Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on startup due to directionMarker/directionMarkerSize race condition #638

Conversation

dbdean
Copy link
Contributor

@dbdean dbdean commented Oct 9, 2017

I've been getting this error on startup of StreetComplete a few times:

Device: google bullhead, Android 8.0.0
Thread: Timer-0
App version: 2.1
Stack trace:
java.lang.NullPointerException: Attempt to get length of null array
at android.text.TextUtils.join(TextUtils.java:304)
at de.westnordost.streetcomplete.tangram.MapFragment.onRotationChanged(MapFragment.java:395)
at de.westnordost.streetcomplete.tangram.CompassComponent$CompassAnimator.run(CompassComponent.java:152)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)

It seems it is because directionMarker is not null, but directionMarkerSize is null in onRotationChanged in app/src/main/java/de/westnordost/streetcomplete/tangram/MapFragment.java.

Rearranging the initialisation in initMarkers so that directionMarkerSize is set before directionMarker is should solve the problem, even if onRotationChanged is called during initMarkers, which does seem to happen for me, at least some of the time.

My instinct is telling me to set up all of the markers in local variables first, then assign them to the class so that they are either fully initialised or null when listeners fire, but I haven't gone that far here, just yet.

I've run this a few times, and it hasn't crashed yet, which it would do before semi-often. I'll run this over the next few days to be sure, though.

@westnordost
Copy link
Member

My instinct is telling me to set up all of the markers in local variables first, then assign them to the class so that they are either fully initialised or null when listeners fire, but I haven't gone that far here, just yet.

Hmm, that is a good idea. I will just do that after I merged your PR

@westnordost westnordost merged commit 20dddc7 into streetcomplete:master Oct 9, 2017
@westnordost
Copy link
Member

Thank you, @dbdean

@dbdean dbdean deleted the null_array_length_in_MapFragment_on_startup branch October 18, 2017 12:42
mnalis added a commit to mnalis/StreetComplete that referenced this pull request Sep 4, 2024
copied from app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants