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

Misc Android Crash Fixes #963

Merged
merged 2 commits into from
Aug 21, 2020

Conversation

ClayC-WeatherBug
Copy link
Contributor

  • Add null checks when queueing features and making region payload to avoid crashes.
  • Modified disposeNativeMapView threading to fix a crash.

Copy link
Member

@ferdicus ferdicus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I can neither approve nor reject - just asking dumb questions :D

Log.e(getClass().getSimpleName() , " disposeNativeMapView() exception destroying map view", ex);
}
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a closing } for the if statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops - good catch and thanks. I'll update the PR shortly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I think, now there is a missing ) on line 334 :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's causing a build error in our CI tools

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah shoot - sorry that was sloppy on my part. I just pushed an update. Thanks for pointing that out!

Comment on lines 322 to 335
if (mapView != null)
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
try
{
mapView.dispose();
}
catch (Exception ex)
{
Log.e(getClass().getSimpleName() , " disposeNativeMapView() exception destroying map view", ex);
}
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not that well versed in Java, can you explain to me the benefit of your solution versus the one already implemented?

Is it the fact, that Runnable is being created inline and thus only if mapView != null versus the old implementation that is creating it nevertheless?

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The future task which we were using earlier will not be executed immediately. It will be executed after some amount of time, but until then it will block the main thread. That causes ANR issues, and we found this while changing the orientation in Android tablets. It causes the app to freeze.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wait for dispose was introduced in:
nitaliano/react-native-mapbox-gl#1075

I'm a bit confused, as i don't get all the details behind 1075 either.

So you're saying that on android waiting for mapView.dispose() caused App Not Responding. But how is it related to changing orientation on Android tablet?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Orientation Change our Android Activity will be destroyed and recreated. In this case, we are seeing a black screen and the app freezes forever. After doing some analysis, we found that Future Task is blocking UI/Main thread.

@@ -1171,27 +1171,35 @@ public void onHostDestroy() {

private WritableMap makeRegionPayload(Boolean isAnimated) {
CameraPosition position = mMap.getCameraPosition();
if(position == null || position.target == null){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, what causes position or position.target to be null?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not sure, but we were occasionally seeing a crash at this line and this seemed to fix it.

properties.putArray("visibleBounds", GeoJSONUtils.fromLatLngBounds(visibleRegion.latLngBounds));
} catch(Exception ex)
{
ex.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what cases would it fail?! And what is the exception?!

We should consider using com.mapbox.mapboxsdk.log.Logger as that can be processed on the JS side, see Logger.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call on using Logger. I'll send an update to the PR shortly. Same comment here as above - we were occasionally seeing crashes, and the stack traces pointed to this part of the code. We added the null check and try/catch, and it seems to have fixed the crashes.

@ClayC-WeatherBug
Copy link
Contributor Author

I apologize for the delay in responding to questions on this PR. I was out all last week and didn't get a chance to respond to any of this. These changes came from some changes my team made internally to fix crashes. I've reached out to the developers and either I or one of them will respond with more details to the questions asap.

… avoid crashes.

- Modified disposeNativeMapView threading to fix a crash.
@ClayC-WeatherBug
Copy link
Contributor Author

I've updated this PR with changes based on the comments. @mfazekas and @ferdicus please let me know if you have any questions or concerns.

@ClayC-WeatherBug
Copy link
Contributor Author

@mfazekas @ferdicus any other questions or concerns with this PR?

@ferdicus
Copy link
Member

@mfazekas @ferdicus any other questions or concerns with this PR?

I'll have a look at this on Friday and let you know, thanks in advance for all the work already 👍

@ferdicus
Copy link
Member

Sorry for the delay

@ClayC-WeatherBug, I've checked again, there is a missing ) now here https://github.com/ClayC-WeatherBug/maps/blob/8165c45424e3b036bb989a9328c47a61ad7cc1c0/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/mapview/RCTMGLMapViewManager.java#L334

  • If that is fixed
  • CI runs through
  • @mfazekas, doesn't find anything else :)

I think we're good to go

@ferdicus
Copy link
Member

@mfazekas , can we merge this, or is there anything else you wanted to address?

@mfazekas
Copy link
Contributor

@ferdicus it's good to go

@ferdicus ferdicus merged commit 9ab5259 into rnmapbox:master Aug 21, 2020
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.

3 participants