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

Android app crashes with null pointer dereference exception #182

Closed
BartoszStasiurka opened this issue Dec 21, 2022 · 27 comments
Closed

Android app crashes with null pointer dereference exception #182

BartoszStasiurka opened this issue Dec 21, 2022 · 27 comments
Labels
android bug Something isn't working example Affects the example app

Comments

@BartoszStasiurka
Copy link
Contributor

This problem may be related to flutter/flutter#107297

Steps to reproduce:

  • Open example app
  • Tap fast few times back and forth between "Full screen map" and Home Screen.
F/libc    (25275): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x20 in tid 28262 (GLThread 59109), pid 25275 (mapboxglexample)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'xiaomi/lavender_eea/lavender:10/QKQ1.190910.002/V12.5.1.0.QFGEUXM:user/release-keys'
Revision: '0'
ABI: 'arm64'
Timestamp: 2022-12-21 12:14:05+0100
pid: 25275, tid: 28262, name: GLThread 59109  >>> com.mapbox.mapboxglexample <<<
uid: 10261
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x20
Cause: null pointer dereference
    x0  0000007bfbc1cbe0  x1  0000000000000000  x2  0000000000000080  x3  0000000000000008
    x4  0000000000000000  x5  0000000000000001  x6  0000000000000000  x7  0000000000586000
    x8  0000000000000000  x9  2bd832c6fea9c0b1  x10 000000000000000f  x11 0000000000000000
    x12 0000007d84451d00  x13 0000000000000080  x14 fffffffffc000000  x15 00000000fff1ffc0
    x16 0000007d84461700  x17 0000007d842c1b40  x18 0000007bdb56c000  x19 0000007d2c6c2d88
    x20 0000007bfb8ce300  x21 0000007bf9019020  x22 0000007bf9019020  x23 0000000014e21fd8
    x24 000122ccfb839eac  x25 0000000000000001  x26 0000000000000000  x27 0000000000000000
    x28 0000007bfbe12a00  x29 0000007bf9017f00
    sp  0000007bf9017d20  lr  0000007d840f9830  pc  0000007d84267be0
backtrace:
      #00 pc 0000000000296be0  /data/app/com.mapbox.mapboxglexample-3QTnTv5I8VcXhC-NGtBQrA==/lib/arm64/libmapbox-gl.so (BuildId: 9497fa822fb9ba0c8ff97671ad28c0232b4f7d1f)
      #01 pc 000000000012882c  /data/app/com.mapbox.mapboxglexample-3QTnTv5I8VcXhC-NGtBQrA==/lib/arm64/libmapbox-gl.so (BuildId: 9497fa822fb9ba0c8ff97671ad28c0232b4f7d1f)
      #02 pc 00000000000a5894  /data/app/com.mapbox.mapboxglexample-3QTnTv5I8VcXhC-NGtBQrA==/lib/arm64/libmapbox-gl.so (BuildId: 9497fa822fb9ba0c8ff97671ad28c0232b4f7d1f)
      #03 pc 0000000000140350  /apex/com.android.runtime/lib64/libart.so (art_quick_generic_jni_trampoline+144) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #04 pc 000000000205ce34  /memfd:/jit-cache (deleted) (com.mapbox.mapboxsdk.maps.renderer.MapRenderer.onDrawFrame+100)
      #05 pc 000000000207ae4c  /memfd:/jit-cache (deleted) (com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer.onDrawFrame+44)
      #06 pc 000000000204e210  /memfd:/jit-cache (deleted) (com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.MapboxGLSurfaceView$GLThread.guardedRun+2960)
      #07 pc 0000000000137334  /apex/com.android.runtime/lib64/libart.so (art_quick_invoke_stub+548) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #08 pc 0000000000145fec  /apex/com.android.runtime/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+244) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #09 pc 00000000002e3800  /apex/com.android.runtime/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+384) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #10 pc 00000000002dea60  /apex/com.android.runtime/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+892) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #11 pc 00000000005a3ae4  /apex/com.android.runtime/lib64/libart.so (MterpInvokeDirect+424) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #12 pc 0000000000131914  /apex/com.android.runtime/lib64/libart.so (mterp_op_invoke_direct+20) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #13 pc 000000000041ba00  [anon:dalvik-classes2.dex extracted in memory from /data/app/com.mapbox.mapboxglexample-3QTnTv5I8VcXhC-NGtBQrA==/base.apk!classes2.dex] (com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.MapboxGLSurfaceView$GLThread.run+48)
      #14 pc 00000000002b4b14  /apex/com.android.runtime/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEbb.llvm.10247671929900336896+240) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #15 pc 0000000000592d24  /apex/com.android.runtime/lib64/libart.so (artQuickToInterpreterBridge+1032) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #16 pc 0000000000140468  /apex/com.android.runtime/lib64/libart.so (art_quick_to_interpreter_bridge+88) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #17 pc 0000000000137334  /apex/com.android.runtime/lib64/libart.so (art_quick_invoke_stub+548) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #18 pc 0000000000145fec  /apex/com.android.runtime/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+244) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #19 pc 00000000004b171c  /apex/com.android.runtime/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #20 pc 00000000004b2830  /apex/com.android.runtime/lib64/libart.so (art::InvokeVirtualOrInterfaceWithJValues(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, jvalue const*)+416) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #21 pc 00000000004f31f8  /apex/com.android.runtime/lib64/libart.so (art::Thread::CreateCallback(void*)+1176) (BuildId: 64f7ca74f522ef2c933e507c8abf7ef4)
      #22 pc 00000000000e6b50  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36) (BuildId: b9254a9320cb794714fda3ae99886b88)
      #23 pc 0000000000084c6c  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: b9254a9320cb794714fda3ae99886b88)
Lost connection to device.
@mariusvn
Copy link
Contributor

I confirm that i have sigsegv on my testing too

@Soknath-MIL
Copy link

I confirm facing the same problem. But it happens with randomness when we switch back and forth.

@mariusvn
Copy link
Contributor

mariusvn commented Jan 5, 2023

Yup, it seems like it's related to the maplibre native library and i suspect the problem to be related to the C++ part of the JNI. Take a look here: maplibre/maplibre-native#177

@cfspeier
Copy link

I experience the same. There is a workaround mentioned on flutter-mapbox-gl.

flutter-mapbox-gl/maps#1119 (comment)

Would something similar work for maplibre-gl? Thank you

@WeySoft
Copy link

WeySoft commented Feb 2, 2023

I face the same problem, also with randomness.

@GaelleJoubert
Copy link
Contributor

Yes I am facing the same problem. It happens when I switch pages "fast" (map is only displayed in one of my page).
Looks like the issue is happening when the map does not have the time to properly initiate or dispose something.

@GaelleJoubert
Copy link
Contributor

I took the file from the fix from mapBox (this one), and add it at this path : flutter-maplibre-gl-c723434d635068157311eb47c26df3e0554ff894\maplibre_gl_platform_interface\lib\src

It seems to fix the issue ! At least I have not mannage to make it happen again. I'll do a PR :)

GaelleJoubert added a commit to GaelleJoubert/flutter-maplibre-gl that referenced this issue Feb 23, 2023
Fix issue maplibre#182
I took the file from the fix from mapBox (this one), and add it at the same place in maplibre.

It seems to fix the issue ! At least I have not mannage to make it happen again.
@GaelleJoubert
Copy link
Contributor

I have open a pull request with the fix I copied from mapbox. It seems to work for me, let me know if it does for you !

@JanikoNaber
Copy link

JanikoNaber commented Mar 8, 2023

I tried the PR from @GaelleJoubert on Flutter 3.7, with and without the KeepAlive trick. Unfortunately without success. It reduces the occurrence of the bug, but it still crashes. I'm used a bottom navigation with the Maplibre widget in one tab, by quickly switching between these tabs the app crashes after 2-3 jumps.

Has anyone already tried the PR from flutter mapbox gl flutter-mapbox-gl/maps#1273 ?

This is actually a show stopper for us, so we downgraded to Flutter 2.10.5 (but would be good to use Flutter 3).

@GaelleJoubert
Copy link
Contributor

I have the same architecture than you : bottom navigation with the Maplibre widget in one tab. And I have noticed the same behavior : It reduces the occurrence of the bug, but it still crashes.
The keep alive fixed it for me though.
I have not try the PR #1273, but I will probably be able to try it next week, if no one have time to do it before.

@GaelleJoubert
Copy link
Contributor

@JanikoNaber I try to apply the fix from flutter-mapbox-gl/maps#1273, but it does not pass all the check now ..
But I can't really figure out why, if somebody have some time to fix it ?
It does build on my side and seems to fix the crash. (no crash until now).

@mariusvn
Copy link
Contributor

mariusvn commented Mar 8, 2023

i'll check tomorrow and i'll test too to be sure that fixes the crash. This is clearly a breaking bug that needs to be fixed. Thanks @GaelleJoubert for all the work

@cfspeier
Copy link

Hi,

thank you for your efforts @GaelleJoubert and @mariusvn 👐

Any conclusion yet?

@mariusvn
Copy link
Contributor

I did not have time to work on it this week, i'll try to do it next week

m0nac0 added a commit that referenced this issue Apr 4, 2023
Fix issue #182

---------

Co-authored-by: m0nac0 <58807793+m0nac0@users.noreply.github.com>
@m0nac0
Copy link
Collaborator

m0nac0 commented Apr 4, 2023

Is this fixed for you guys with the changes from #203?

@GaelleJoubert
Copy link
Contributor

Yes I think so

@cfspeier
Copy link

cfspeier commented Apr 4, 2023

Hey thanks a lot for updating. Unfortunately, I still get the null pointer dereference exception. But maybe I am doing something else wrong:

F/libc (10367): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 10733 (Thread-9)

@GaelleJoubert
Copy link
Contributor

It's weird, that error was completely gone the last weeks.
And today it's back. I had it 3 times already, and I did not had it for the last couple of weeks.

@GaelleJoubert
Copy link
Contributor

I have a doubt that fluuter actually use an "old" reference of "main", when I add the dependency like that :

 maplibre_gl:
    git:
      url: https://github.com/maplibre/flutter-maplibre-gl #https://github.com/m0nac0/flutter-maplibre-gl.git
      ref: main

And that's why I have the crash back (I've just switch back to main tooday).
I've try to actually explicitly give the last commit as dependency, like that :


 maplibre_gl:
    git:
      url: https://github.com/maplibre/flutter-maplibre-gl #https://github.com/m0nac0/flutter-maplibre-gl.git
      ref: ee82380e456e0cba4130f3ad8e9c8787742a0f79

And I don't have the crash any more.

Can you try that, and tell me if you still have the crash ?

@mariusvn
Copy link
Contributor

mariusvn commented Apr 6, 2023

That's weird, maybe a flutter cache clean would resolve the problem ?

@GaelleJoubert
Copy link
Contributor

Yeah maybe, I am super buisy right know, so I'll just stay with the method that works for me.
I'll try that later.
It was just a hint for those who still see the error.

@cfspeier
Copy link

cfspeier commented Apr 13, 2023

Hi all,

I still see the same exception. I can reproduce it by switching between the map and other tabs quickly. Thanks for your efforts though. (really appreciated)

However, I fix this, by switching to to an IndexedStack, which will make the map view persistent. With the IndexedStack I do not see this error anymore.

Best
Christoph

JulianBissekkou added a commit that referenced this issue Jul 4, 2023
This PR should fix the crash as described in #182  and #257 
The status is still in draft because I would like to get feedback from
android devs of maplibre-gl-native.

### Problem
The crash started to occure with flutter 3.x and after some
investigations we were able to detect the exact change that broke it.
See flutter/flutter#107297 or
flutter/flutter#107297 (comment)
for details.

The engine change in
flutter/engine@8dc7cd1
is not calling `removeView` in all cases which might be the reason why
this issue is happening.
I digged into the framework and saw that `removeView` will trigger
`onDetachedFromWindow` in the subviews. This is important since once of
the subviews is `TextureView` which destorys the surface texture:


Here is `TextureView.onDeatachedFromWindowInternal`
```java
    @OverRide
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    protected void onDetachedFromWindowInternal() {
        destroyHardwareLayer();
        releaseSurfaceTexture();
        super.onDetachedFromWindowInternal();
    }
```

My guess: If this is not called we might still draw onto a surface which
triggers the crash.

### The fix
If my assumptions are correct then this should be fixed in the engine
and not in the libraries that need a platform view. You can find the
workaround in this PR. We simply create a view container that calls
`removeView` to trigger the `onDetachedFromWindow`.
We tested this in an example app with success and also in some of our
internal projects.

Please give some feedback if my assumptions are correct. Thanks!

---------

Co-authored-by: Julian Bissekkou <julian.bissekkou@tapped.dev>
Co-authored-by: Stefan Schaller <stefan.schaller@tapped.dev>
JanikoNaber pushed a commit to JanikoNaber/flutter-maplibre-gl that referenced this issue Aug 23, 2023
Fix issue maplibre#182

---------

Co-authored-by: m0nac0 <58807793+m0nac0@users.noreply.github.com>
JanikoNaber pushed a commit to JanikoNaber/flutter-maplibre-gl that referenced this issue Aug 23, 2023
This PR should fix the crash as described in maplibre#182  and maplibre#257 
The status is still in draft because I would like to get feedback from
android devs of maplibre-gl-native.

### Problem
The crash started to occure with flutter 3.x and after some
investigations we were able to detect the exact change that broke it.
See flutter/flutter#107297 or
flutter/flutter#107297 (comment)
for details.

The engine change in
flutter/engine@8dc7cd1
is not calling `removeView` in all cases which might be the reason why
this issue is happening.
I digged into the framework and saw that `removeView` will trigger
`onDetachedFromWindow` in the subviews. This is important since once of
the subviews is `TextureView` which destorys the surface texture:


Here is `TextureView.onDeatachedFromWindowInternal`
```java
    @OverRide
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    protected void onDetachedFromWindowInternal() {
        destroyHardwareLayer();
        releaseSurfaceTexture();
        super.onDetachedFromWindowInternal();
    }
```

My guess: If this is not called we might still draw onto a surface which
triggers the crash.

### The fix
If my assumptions are correct then this should be fixed in the engine
and not in the libraries that need a platform view. You can find the
workaround in this PR. We simply create a view container that calls
`removeView` to trigger the `onDetachedFromWindow`.
We tested this in an example app with success and also in some of our
internal projects.

Please give some feedback if my assumptions are correct. Thanks!

---------

Co-authored-by: Julian Bissekkou <julian.bissekkou@tapped.dev>
Co-authored-by: Stefan Schaller <stefan.schaller@tapped.dev>
@dawid-niedzwiecki
Copy link

This makes the package unusable. Hope this gets fixed soon.

@m0nac0
Copy link
Collaborator

m0nac0 commented Jan 14, 2024

This issue should in fact already be resolved. Are you seeing the exact same issue? If so, please share with which flutter version, plugin version, Android version you are experiencing this.

@dawid-niedzwiecki
Copy link

pls

@m0nac0
Copy link
Collaborator

m0nac0 commented Mar 3, 2024

@dawid-niedzwiecki Are you seeing the exact same issue? If so, please share with which flutter version, plugin version, Android version you are experiencing this.

@josxha josxha added the example Affects the example app label Jun 6, 2024
@kuhnroyal
Copy link
Collaborator

I think this is fixed, if not, please open a new issue with a detailed reproduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android bug Something isn't working example Affects the example app
Projects
None yet
Development

No branches or pull requests