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

[BUG] JNI exceptions in console when having a lot of rebuilds or controller calls at once #136

Closed
josxha opened this issue Nov 11, 2024 · 6 comments · Fixed by #210
Closed
Labels
android Android specific issue bug Something isn't working
Milestone

Comments

@josxha
Copy link
Owner

josxha commented Nov 11, 2024

Platforms

Android

Version of flutter-maplibre

0.1.2

Bug Description

When rebuilding the MapLibreMap widget a lot in a short amount of times the console shows JNI related exceptions.

E/flutter (26853): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: Use after release error
E/flutter (26853): #0      JReference.pointer (package:jni/src/jreference.dart:56:21)
E/flutter (26853): #1      MapLibreMap.moveCamera (package:maplibre/src/native/jni/org/maplibre/android/maps/MapLibreMap.dart:5280:27)
E/flutter (26853): #2      MapLibreMapStateJni.moveCamera.<anonymous closure> (package:maplibre/src/native/widget_state_jni.dart:221:14)
E/flutter (26853): #3      _platformIsolateMain.<anonymous closure> (dart:ui/platform_isolate.dart:142:51)
E/flutter (26853): #4      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter (26853): 

When hot restarting the app, another exception gets logged in the console:

E/flutter (26880): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformIsolate shutdown unexpectedly

Steps to Reproduce

Using the MapLibreLayer in flutter_map_maplibre, see bug report here: josxha/flutter_map_plugins#54

Expected Results

Don't throw any exceptions

Actual Results

Exceptions in the console and future calls are partly unresponsive.

Code Sample

// Paste your code here
@josxha josxha added the bug Something isn't working label Nov 11, 2024
@josxha josxha added the android Android specific issue label Nov 11, 2024
@josxha
Copy link
Owner Author

josxha commented Nov 20, 2024

This bug might solve itself when the platform and ui thread are merged. This is done on the master branch but not in the beta channel last time I checked. flutter/flutter#150525

In the meantime, it could be sufficient to use a global Lock that prevents multiple calls to access the thread at once.

@bing127

This comment was marked as off-topic.

@josxha

This comment was marked as off-topic.

@bing127

This comment was marked as off-topic.

@josxha

This comment was marked as off-topic.

@josxha
Copy link
Owner Author

josxha commented Dec 2, 2024

jnigen added documentation a few days ago: https://github.com/dart-lang/native/blob/main/pkgs/jnigen/doc/threading.md

@josxha josxha added this to the v0.2.0 milestone Dec 7, 2024
@josxha josxha linked a pull request Dec 15, 2024 that will close this issue
@josxha josxha removed this from the v0.2.0 milestone Dec 31, 2024
@josxha josxha added this to the v0.3.0 milestone Jan 30, 2025
@josxha josxha closed this as completed in b5e68f2 Jan 30, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in maplibre dev Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Android specific issue bug Something isn't working
Projects
Status: Done
2 participants