mapbox-maps-flutter
mapbox-maps-flutter copied to clipboard
Refactor `addStyleImage` function
I get this Platform Exception whenever i try to add an styleImage using the style.addStyleImage() function: This is the log dump
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): Failed to handle message
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Bitmap$Config android.graphics.Bitmap.getConfig()' on a null object reference
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at com.mapbox.maps.mapbox_maps.StyleController.addStyleImage(StyleController.kt:611)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at com.mapbox.maps.mapbox_maps.pigeons.StyleManager$Companion.setUp$lambda$93$lambda$92(MapInterfaces.kt:6573)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at com.mapbox.maps.mapbox_maps.pigeons.StyleManager$Companion.$r8$lambda$lRvnrb64UZK1xwpPleLL6Q0pCMo(Unknown Source:0)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at com.mapbox.maps.mapbox_maps.pigeons.StyleManager$Companion$$ExternalSyntheticLambda34.onMessage(Unknown Source:2)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage(BasicMessageChannel.java:261)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at android.os.Handler.handleCallback(Handler.java:959)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at android.os.Handler.dispatchMessage(Handler.java:100)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at android.os.Looper.loopOnce(Looper.java:282)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at android.os.Looper.loop(Looper.java:387)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at android.app.ActivityThread.main(ActivityThread.java:9505)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at java.lang.reflect.Method.invoke(Native Method)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:600)
E/BasicMessageChannel#dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0(24833): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1005)
E/flutter (24833): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.addStyleImage.0"., null, null)
E/flutter (24833): #0 StyleManager.addStyleImage (package:mapbox_maps_flutter/src/pigeons/map_interfaces.dart:7142:7)```
So i was able to rectify the problems i was having but in the process i found some issues with the addStyleImage function
- So firstly one of the problems came from a param which is a List<ImageStretches?>, according to this [null] can be passed as an arg but when this is done it produces a
NullPointerExceptionat line 626 in theStyleController.kt. - The other problem is the param scale, when i tried to increase the scale value the symbol would reduce in size and when scale value was decreased the size would increase which i believe is the complete opposite.
How did you fix the original issue? I am getting the same error
@thwPrecision the problem i was facing was with the way i was i providing the MbxImage arg particularly the getting the imageBytes for it. If u want i can provide u with a function that adds StyleImage to map