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

Refactor `addStyleImage` function

Open Brez18 opened this issue 1 year ago • 3 comments

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)```

Brez18 avatar Feb 28 '25 14:02 Brez18

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 NullPointerException at line 626 in the StyleController.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.

Brez18 avatar Mar 01 '25 17:03 Brez18

How did you fix the original issue? I am getting the same error

thwPrecision avatar May 20 '25 01:05 thwPrecision

@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

Brez18 avatar May 20 '25 08:05 Brez18