From 1921ecb9f4d32ec8e6069fd4e31ea4634cdbceab Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Fri, 9 Feb 2024 11:27:03 +1300 Subject: [PATCH] Guarantee ViewGraph only passes numbers to charts This error occurs on some devices in the Play store (android 12). I can't reproduce it unless I forcefully pass NaN to my charts, so this might just fix the error. Related to #206. Exception java.lang.Error: at com.horcrux.svg.PathParser.parse_number (PathParser.java:627) at com.horcrux.svg.PathParser.parse_list_number (PathParser.java:594) at com.horcrux.svg.PathParser.parse (PathParser.java:118) at com.horcrux.svg.PathView.setD (PathView.java:28) at com.horcrux.svg.RenderableViewManager$PathViewManager.setD (RenderableViewManager.java:751) at com.horcrux.svg.RenderableViewManager$PathViewManager.setD (RenderableViewManager.java:740) at com.facebook.react.viewmanagers.RNSVGPathManagerDelegate.setProperty (RNSVGPathManagerDelegate.java:112) at com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps (ViewManagerPropertyUpdater.java:46) at com.facebook.react.uimanager.ViewManager.updateProperties (ViewManager.java:84) at com.facebook.react.uimanager.ViewManager.createViewInstance (ViewManager.java:188) at com.facebook.react.uimanager.ViewManager.createView (ViewManager.java:115) at com.facebook.react.uimanager.NativeViewHierarchyManager.createView (NativeViewHierarchyManager.java:281) at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute (UIViewOperationQueue.java:194) at com.facebook.react.uimanager.UIViewOperationQueue$1.run (UIViewOperationQueue.java:909) at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches (UIViewOperationQueue.java:1026) at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded (UIViewOperationQueue.java:1086) at com.facebook.react.uimanager.GuardedFrameCallback.doFrame (GuardedFrameCallback.java:29) at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame (ReactChoreographer.java:175) at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame (ChoreographerCompat.java:85) at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1106) at android.view.Choreographer.doCallbacks (Choreographer.java:866) at android.view.Choreographer.doFrame (Choreographer.java:792) at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1092) at android.os.Handler.handleCallback (Handler.java:938) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loopOnce (Looper.java:226) at android.os.Looper.loop (Looper.java:313) at android.app.ActivityThread.main (ActivityThread.java:8751) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135) --- ViewGraph.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ViewGraph.tsx b/ViewGraph.tsx index e5516a1..ef83df2 100644 --- a/ViewGraph.tsx +++ b/ViewGraph.tsx @@ -26,9 +26,11 @@ export default function ViewGraph() { const [unit, setUnit] = useState('kg'); const convertWeight = (weight: number, unitFrom: string, unitTo: string) => { - if (unitFrom === unitTo) return weight; - if (unitFrom === 'lb' && unitTo === 'kg') return weight * 0.453592; - if (unitFrom === 'kg' && unitTo === 'lb') return weight * 2.20462; + let result = weight; + if (unitFrom === unitTo) result = weight; + if (unitFrom === 'lb' && unitTo === 'kg') result = weight * 0.453592; + if (unitFrom === 'kg' && unitTo === 'lb') result = weight * 2.20462; + return isNaN(result) ? 0 : result; }; useEffect(() => {