ayoola-solomon / mytracks

Automatically exported from code.google.com/p/mytracks
0 stars 0 forks source link

NullPointerException in Canvas.drawPath() #678

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The stack trace of this error:
java.lang.NullPointerException
at android.graphics.Canvas.drawPath(Canvas.java:950)
at com.google.android.apps.mytracks.maps.SingleColorTrackPathPainter.void 
drawTrack(android.graphics.Canvas)(MT:48)
at com.google.android.apps.mytracks.MapOverlay.void 
draw(android.graphics.Canvas,com.google.android.maps.MapView,boolean)(MT:258)
at com.google.android.maps.Overlay.draw(Overlay.java:179)
at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:45)
at com.google.android.maps.MapView.onDraw(MapView.java:530)
at android.view.View.draw(View.java:6946)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.View.draw(View.java:6949)
at android.widget.FrameLayout.draw(FrameLayout.java:357)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.View.draw(View.java:6949)
at android.widget.FrameLayout.draw(FrameLayout.java:357)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.View.draw(View.java:6949)
at android.widget.FrameLayout.draw(FrameLayout.java:357)
at 
com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:194
7)
at android.view.ViewRoot.draw(ViewRoot.java:1584)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1320)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1925)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3728)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)

What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

Original issue reported on code.google.com by youtaol@google.com on 15 Dec 2011 at 6:08

GoogleCodeExporter commented 8 years ago
This crash is similar with crash: "NullPointerException in c.a()" , and below 
is the unobfuscated stack trace of this crash.

java.lang.NullPointerException
at com.google.android.apps.mytracks.maps.DynamicSpeedTrackPathPainter.void 
drawTrack(android.graphics.Canvas)(MT:63)
at com.google.android.apps.mytracks.MapOverlay.void 
draw(android.graphics.Canvas,com.google.android.maps.MapView,boolean)(MT:258)
at com.google.android.maps.Overlay.draw(Overlay.java:179)
at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:45)
at com.google.android.maps.MapView.onDraw(MapView.java:530)
at android.view.View.draw(View.java:7082)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.View.draw(View.java:7085)
at android.widget.FrameLayout.draw(FrameLayout.java:357)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.View.draw(View.java:7085)
at android.widget.FrameLayout.draw(FrameLayout.java:357)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.View.draw(View.java:7085)
at android.widget.FrameLayout.draw(FrameLayout.java:357)
at 
com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:207
6)
at android.view.ViewRoot.draw(ViewRoot.java:1646)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1379)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1984)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
at dalvik.system.NativeStart.main(Native Method)

So same crash happened when run Canvas.drawPath in DynamicSpeedTrackPathPainter 
or SingleColorTrackPathPainter,  both are invoked by 
MapOverlay.drawTrack(Canvas canvas, Projection projection, Rect viewRect)

Original comment by youtaol@google.com on 15 Dec 2011 at 7:57

GoogleCodeExporter commented 8 years ago

Original comment by youtaol@google.com on 29 Mar 2012 at 10:41

GoogleCodeExporter commented 8 years ago
For this one, because the path variable is not set till updatePath is called, 
we should just add a check against null here.

Original comment by jshih@google.com on 6 Apr 2012 at 1:04

GoogleCodeExporter commented 8 years ago
Can you help to check following:
At the line 355 of MapOverlay:
line 353:if (newPoints == 0 && lastPathExists && !newProjection) {
line 354:        // No need to recreate path (same points and viewing area).
line 355:        draw = true;
line 356:      }

Do you think the line 355 should be  draw = false; ? And if so, do you think it 
made this issue happen?

Original comment by youtaol@google.com on 9 Apr 2012 at 4:04

GoogleCodeExporter commented 8 years ago
For MapOverlay, line 355, I agree it should be draw = false.

For
java.lang.NullPointerException
at android.graphics.Canvas.drawPath(Canvas.java:950)
at com.google.android.apps.mytracks.maps.SingleColorTrackPathPainter.void 
drawTrack(android.graphics.Canvas)(MT:48)

The bug in MayOverlay is not the root cause. The path variable can be null. It 
is not set in the constructor. Thus before using it, we need to check if it is 
null or not.

For 
java.lang.NullPointerException
at com.google.android.apps.mytracks.maps.DynamicSpeedTrackPathPainter.void 
drawTrack(android.graphics.Canvas)(MT:63)
at com.google.android.apps.mytracks.MapOverlay.void 
draw(android.graphics.Canvas,com.google.android.maps.MapView,boolean)(MT:258)

Do you know which variable causing the null pointer exception?

Original comment by jshih@google.com on 9 Apr 2012 at 5:48

GoogleCodeExporter commented 8 years ago
The null variable is the path for SingleColorTrackPathPainter and 
coloredPaths.get(i) for DynamicSpeedTrackPathPainter.

I think maybe the bug in MayOverlay is the root cause. When the 
draw(MapOverlay, line 355) is true but it does not run updatePath method of 
trackPathPainter(Such as line 364 or line 368 in MapOverlay), then the path in 
SingleColorTrackPathPainter and coloredPaths in DynamicSpeedTrackPathPainter 
will not be initialized when run trackPathPainter.drawTrack(canvas)(line 375).

355         draw = true;    
356       } else {  
...
358         if (numPoints < 2) {    
359           // Not enough points to draw a path.  
360           draw = false; 
361         } else if (!trackPathPainter.needsRedraw() && lastPathExists && 
!newProjection) {   
362           // Incremental update of the path, without repositioning the 
view.   
363           draw = true;  
364           trackPathPainter.updatePath(projection, viewRect, numPoints - 
newPoints, alwaysVisible, points);  
365         } else {    
366           // The view has changed so we have to start from scratch. 
367           draw = true;
368           trackPathPainter.updatePath(projection, viewRect, 0, 
alwaysVisible, points); 
369         }   
370       } 
...
374     if (draw) { 
375       trackPathPainter.drawTrack(canvas);
376     }   
377   }

Original comment by youtaol@google.com on 10 Apr 2012 at 9:09

GoogleCodeExporter commented 8 years ago
Good analysis. Agree it is the root cause. :)

Original comment by jshih@google.com on 10 Apr 2012 at 5:39

GoogleCodeExporter commented 8 years ago
Issue 709 has been merged into this issue.

Original comment by youtaol@google.com on 11 Apr 2012 at 8:56

GoogleCodeExporter commented 8 years ago
Did this issue ever get fixed? Is it still happening with 1.1.16?

Original comment by jshih@google.com on 21 Jun 2012 at 11:43

GoogleCodeExporter commented 8 years ago
Yes, it should have not been fixed. It still happen in 1.1.16. May we need to 
add a trackPathPainter.updatePath statement in the "if" branch?

Original comment by youtaol@google.com on 25 Jun 2012 at 6:32

GoogleCodeExporter commented 8 years ago

Original comment by jshih@google.com on 25 Jun 2012 at 5:14

GoogleCodeExporter commented 8 years ago

Original comment by jshih@google.com on 2 Aug 2012 at 9:54

GoogleCodeExporter commented 8 years ago
Does the change also fix the crash of DynamicSpeedTrackPathPainter.void 
drawTrack(android.graphics.Canvas)?
And new crash in feedback is:
https://feedback.corp.google.com/#/Product/82349/Category/90248/Cluster/3478088?
context=ci

Original comment by youtaol@google.com on 22 Aug 2012 at 8:24

GoogleCodeExporter commented 8 years ago
Yes, I fixed it for all the TrackPathPainter.

Original comment by jshih@google.com on 22 Aug 2012 at 4:50