-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Conversation
@@ -104,7 +104,9 @@ void NativeMapView::notifyMapChange(mbgl::MapChange change) { | |||
|
|||
android::UniqueEnv _env = android::AttachEnv(); | |||
static auto onMapChanged = javaClass.GetMethod<void (int)>(*_env, "onMapChanged"); | |||
javaPeer->Call(*_env, onMapChanged, (int) change); | |||
if (javaPeer != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make this just if (javaPeer)
or if (javaPeer != nulllptr)
if you want to make it more explicit
@@ -408,7 +410,9 @@ void NativeMapView::scheduleSnapshot(jni::JNIEnv&) { | |||
|
|||
// invoke Mapview#OnSnapshotReady | |||
static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<Bitmap>)>(*_env, "onSnapshotReady"); | |||
javaPeer->Call(*_env, onSnapshotReady, bitmap); | |||
if (javaPeer != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
@tobrun I'm wondering why the callback is actually fired when the javaPeer is gone. If the java peer is gone, that would be because Do you have a way to reproduce this with any reliability? |
Yes, with the code shown in OP I was able to reproduce this on demand. |
When writing a test for this issue, I'm occasionally running into the exception mentioned by the user:
This is a more logical exception as the one I tried addressing in OP. Been reading up on this issue though don't have an immediate fix for it. |
Michael from Wahoo Fitness here, this issue is causing a lot of crashes for us. Just wondering if this fix was scheduled soon? |
1454c26
to
0b5c123
Compare
@ivovandongen I revisit this PR with a different approach, it introduces a paused state to the map renderer and it resolves the crashes (including #11358 (comment)). @michaelfomin getting this fixed is a priority, the fix will be backported to a 5.5.x release. |
0b5c123
to
f555cde
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since onPause
and onResume
are called on the UI thread and render
on the GL thread, I think we should use std::atomic<bool>
here for the paused flag.
f555cde
to
0a83f4e
Compare
@ivovandongen thank you for flagging, fixed up the code to |
This PR adds null checking to the java peer before calling into a NativeMapView callback.
With the
Mapbox#snapshot
api I was able to reproduce:When requesting a snapshot as part of Activity#onPause:
This could potentially explain crashes as #11268.