mapbox-maps-android icon indicating copy to clipboard operation
mapbox-maps-android copied to clipboard

back navigation to Fragment with Mapbox Map not working - Thread MapboxRenderThread was not started, ignoring event

Open felixkrautschuk opened this issue 3 years ago • 10 comments

Environment

  • Android OS version: 12 (also tested 11, 10, 9)
  • Devices affected: tested on Emulators and Google Pixel 3a (physical device)
  • Maps SDK Version: 10.6.0 (also tested 10.1.0, same behaviour)

Observed behavior and steps to reproduce

Navigating forwards to a Fragment with Mapbox map works as expected (also multiple times back and forth), but when navigating back to a Fragment with a Mapbox map from a different Fragment, the app does not respond anymore.

https://user-images.githubusercontent.com/6443021/175537861-1586d6f4-cf74-4215-9378-d07b65307c66.mov

When navigating away (forwards) from the Mapbox map Fragment, I see the following log in Logcat:

2022-06-24 14:30:27.718 17325-17367/de.maxity.mapbox.demo D/EGL_emulation: app_time_stats: avg=4432.95ms min=3.08ms max=44264.67ms count=10 2022-06-24 14:30:27.821 17325-17325/de.maxity.mapbox.demo D/CompatibilityChangeReporter: Compat change id reported: 171228096; UID 10381; state: ENABLED 2022-06-24 14:30:27.852 17325-17325/de.maxity.mapbox.demo I/Mapbox: [maps-android\Mbgl-RenderThread]: RenderThread : surface destroyed 2022-06-24 14:30:27.854 17325-17444/de.maxity.mapbox.demo E/Surface: freeAllBuffers: 1 buffers were freed while being dequeued! 2022-06-24 14:30:27.857 17325-17325/de.maxity.mapbox.demo E/Surface: freeAllBuffers: 1 buffers were freed while being dequeued! 2022-06-24 14:30:27.989 17325-17444/de.maxity.mapbox.demo E/Surface: getSlotFromBufferLocked: unknown buffer: 0x0 2022-06-24 14:30:28.120 17325-17325/de.maxity.mapbox.demo I/Mapbox: [maps-android\Mbgl-RenderThread]: RenderThread : surface destroyed 2022-06-24 14:30:28.120 17325-17444/de.maxity.mapbox.demo E/Surface: freeAllBuffers: 1 buffers were freed while being dequeued! 2022-06-24 14:30:28.121 17325-17325/de.maxity.mapbox.demo E/Surface: freeAllBuffers: 1 buffers were freed while being dequeued! 2022-06-24 14:30:28.124 17325-17325/de.maxity.mapbox.demo I/Mapbox: [maps-android\Mbgl-Renderer]: onDestroy 2022-06-24 14:30:28.124 17325-17444/de.maxity.mapbox.demo I/Mapbox: [maps-android\Mbgl-Renderer]: Destroy renderer 2022-06-24 14:30:28.163 17325-17444/de.maxity.mapbox.demo E/Surface: getSlotFromBufferLocked: unknown buffer: 0x1 2022-06-24 14:30:29.473 17325-17367/de.maxity.mapbox.demo D/EGL_emulation: app_time_stats: avg=76.00ms min=2.59ms max=1282.97ms count=22

When attempting to navigate back to that Mapbox Map Fragment:

2022-06-24 14:31:31.781 17325-17325/de.maxity.mapbox.demo W/Mapbox: [maps-android\Mbgl-MapboxRenderThread]: Thread MapboxRenderThread was not started, ignoring event 2022-06-24 14:35:58.771 17325-17333/de.maxity.mapbox.demo I/ity.mapbox.dem: Thread[6,tid=17333,WaitingInMainSignalCatcherLoop,Thread*=0x725ab05759a0,peer=0x13440b18,"Signal Catcher"]: reacting to signal 3 2022-06-24 14:35:58.771 17325-17333/de.maxity.mapbox.demo I/ity.mapbox.dem: 2022-06-24 14:35:58.965 17325-17333/de.maxity.mapbox.demo I/ity.mapbox.dem: Wrote stack traces to tombstoned

Please note, that this was working as expected when using Mapbox Android SDK 9.7.2.

Expected behavior

When navigating back to a Fragment with Mapbox map, the app should not hang up and ideally the map should not loose its state (as it was working until Mapbox SDK 9.7.2)

Notes / preliminary analysis

Additional links and references

felixkrautschuk avatar Jun 24 '22 13:06 felixkrautschuk

@felixkrautschuk can you please provide us with the code for this app? From the information you provided above, it looks like the instance may not have bee properly destroyed/garbage collected when leaving the fragment, but having the code would help us definitively conclude that that is the issue.

ZiZasaurus avatar Jun 24 '22 17:06 ZiZasaurus

@ZiZasaurus thanks for your feedback. I need to mention that it is not a native Android app. We use the NativeScript framework to build our apps for Android and iOS. I know you do not have any official support for that framework, so it is hard to provide specific code that you can work with.

Basically we follow this guide: https://docs.mapbox.com/android/maps/examples/simple-map-view/ But as we are not able to add the Android Mapbox Map directly in the XML UI Layout, we need to programmatically create the Mapbox map and add it to a Framelayout.

public createNativeView(): Object {
    return new android.widget.FrameLayout(Utils.android.getApplicationContext());
}

public initNativeView() {
    //lifecycle event handlers

    Application.android.on(AndroidApplication.activityStartedEvent, (args: AndroidActivityEventData) => {
         this.nativeMapView.onStart();
    });
    
    Application.android.on(AndroidApplication.activityStoppedEvent, (args: AndroidActivityEventData) => {
         this.nativeMapView.onStop();
    });
    
    Application.android.on(AndroidApplication.activityDestroyedEvent, (args: AndroidActivityEventData) => {
         this.nativeMapView.onDestroy();
    });

    super.initNativeView();
}

public onLoaded() {
    super.onLoaded();

    if(!this.isInitialized) {
       com.mapbox.maps.ResourceOptionsManager.Companion.getDefault(
           Application.android.foregroundActivity, 
           this.accessToken
       );

        this.nativeMapView = new com.mapbox.maps.MapView(Application.android.foregroundActivity);
        this.nativeView.addView(this.nativeMapView);        

        this.isInitialized = true;
    }
}

I am not able to provide any code about navigating between the Fragments, as NativeScript is caring about all that. But when just switching back to Mapbox 9.7.2 (without changing any NativeScript dependency etc), everything works as expected.

I temporary removed all the logic logic about adding sources, layers etc... this issue already occurs with a basic map.

felixkrautschuk avatar Jun 27 '22 09:06 felixkrautschuk

Would you be able to test our v10.0.0-beta.1, we recently made some patches around lifecycle management.

tobrun avatar Jun 29 '22 13:06 tobrun

@tobrun thanks for your feedback, but unfortunately this did not help, still the same behaviour with 10.6.0-beta.1

felixkrautschuk avatar Jun 29 '22 14:06 felixkrautschuk

@tobrun thanks for your feedback, but unfortunately this did not help, still the same behaviour with 10.6.0-beta.1

Later on today we will release v10.7.0-beta.1 - could you please check with it? Not v10.6.0-beta.1 😄

kiryldz avatar Jun 29 '22 15:06 kiryldz

@kiryldz @tobrun still the same behaviour with v10.7.0-beta.1

felixkrautschuk avatar Jun 30 '22 08:06 felixkrautschuk

@kiryldz @tobrun still the same behaviour with v10.7.0-beta.1

Thanks for confirming, that was worth trying. Will need to look deeper in detail then.

kiryldz avatar Jun 30 '22 09:06 kiryldz

As a temporary fix, you can exclude the 'maps-lifecycle' plugin from the com.mapbox.maps dependency (Documentation states that this plugin was added into the com.mapbox.maps dependency from v10.0.0-rc.5). While this does remove the automatic lifecycle handling from the application - it allows for navigation back to a map fragment.

Tested and working with com.mapbox.maps:android:10.8.0-rc.1

caustin13 avatar Sep 07 '22 06:09 caustin13

@caustin13 thank you, this is working! Indeed I don't want all of this automatic lifecycle handling. When the user goes back to the map fragment, I want to keep the whole state of the map (position, zoom-level, visible layers, etc ...).

felixkrautschuk avatar Sep 07 '22 07:09 felixkrautschuk

I experience the same problem. I have a tab navigation and if I go to a different tab (while the mapbox is already loaded/shown) and then come back the app will crash on android. I use v10.0.0-beta.33

ricardodolnl avatar Sep 11 '22 09:09 ricardodolnl

As a temporary fix, you can exclude the 'maps-lifecycle' plugin from the com.mapbox.maps dependency (Documentation states that this plugin was added into the com.mapbox.maps dependency from v10.0.0-rc.5). While this does remove the automatic lifecycle handling from the application - it allows for navigation back to a map fragment.

Tested and working with com.mapbox.maps:android:10.8.0-rc.1

i used the lastest version com.mapbox.maps:android:10.10.0,and test, they didnot repair. I just exclude as you said ,and worked!

byedo avatar Dec 20 '22 10:12 byedo

I just got the same problem on a specific device (not a mobile phone), with a very old Android version. It worked on all other devices but on this one, after turning off the screen (I used a broadcast receiver to detect screen on/off and tried to invalidate the map), after some other activity was loaded and unloaded over the map activity, the map turns all black.

Even after excluding maps-lifecycle as @caustin13 said, I still get a RenderThread : surface destroyed followed by a Failed looking up window and Requested window android.os.BinderProxy@156ae7b6 does not exist. This can be related? I'm just using the com.mapbox.navigation:android:2.10.0 dependency.

taq avatar Jan 25 '23 20:01 taq