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

onStyleLoadedCallback not called on iOS #347

Closed
woelmer opened this issue Jul 1, 2020 · 38 comments
Closed

onStyleLoadedCallback not called on iOS #347

woelmer opened this issue Jul 1, 2020 · 38 comments
Labels

Comments

@woelmer
Copy link

woelmer commented Jul 1, 2020

Flutter (Channel stable, v1.17.5, on Mac OS X 10.15.5 19F101, locale en-US)
On Master branch of plugin.

The onStyleLoadedCallback is not called in the example app. Notice if you go to 'Place Symbol' and click on add (asset image) or add (network image) it does not work. That is because these images are setup in the onStyleLoadedCallback which is not called on iOS. This works fine on Android.

@TimothySealy
Copy link
Collaborator

Hi @woelmer,

I'm trying to reproduce this error but everything seems to work on my device. If I click on add(asset image) or add(network image) the symbols are shown with a mapbox icon or placholder image respectively. Looking at the code the onStyleLoadedCallback should be trigger:
https://github.com/tobrun/flutter-mapbox-gl/blob/4ce26231f3250b598060063d1b8b65950694754e/ios/Classes/MapboxMapController.swift#L525-L527

Can you verify that the onStyleLoadedCallback is not triggered by adding a breakpoint of print statement in this method:
https://github.com/tobrun/flutter-mapbox-gl/blob/4ce26231f3250b598060063d1b8b65950694754e/example/lib/place_symbol.dart#L48-L51

@lj64
Copy link

lj64 commented Jul 1, 2020

I experienced the same issue just yesterday in my project on ios.

onStyleLoadedCallback fired on first entry into the page containing map.
When I closed it and opened again, it did not fire, even though map tiles were displayed.

On Android everything was fine.

@TimothySealy
Copy link
Collaborator

Just tested it a couple of times and it seems that the onStyleLoadedCallback is not always fired. On my device in most cases the style is loaded properly but some times it is not and then the icon images are not loaded. Will have to look deeper into this issue.

@woelmer
Copy link
Author

woelmer commented Jul 2, 2020

@TimothySealy The new recommendation is to add symbols in the onStyleLoadedCallback which is why I noticed it in my own project. I thought I would try out the example and noticed the same thing. I had breakpoints there that were not getting hit. I did have it successfully call the callback once if I recall, so I guess it is intermittent like you noticed.

@philiplindberg
Copy link
Contributor

Seeing the exact same thing as @woelmer - tapping on add (asset image) or add (network image) in the example app does nothing on ios because onStyleLoadedCallback is never called.

The only time I can get onStyleLoadedCallback to be called on ios is after reinstalling the app. When the map is generated for the very first time, onStyleLoadedCallback does get called on both ios and android, but every time after that, onStyleLoadedCallback is only called on android.

@m0nac0
Copy link
Collaborator

m0nac0 commented Aug 9, 2020

@woelmer @philiplindberg If you previously added your annotations before onStyleLoadedCallback was fired and that worked for you, you can continue to do this as a workaround. The new documentation wasn't added because we changed any behavior. Adding annotations in onStyleLoadedCallback was always recommended (just less visibly).

@AAverin
Copy link
Contributor

AAverin commented Sep 5, 2020

I can confirm the issue. Have not been testing on iOS for some time, so not sure when it started happening exactly.
I have updated to 0.8.0 release and also upgraded Flutter to latest available.
Android seems to work fine, on iOS onStyleLoaded is not invoked when map shows.
If I manually (via setState) change map style, callback is invoked, but I do get a crash almost instantly after that. Not sure it's related.

@edufpin
Copy link

edufpin commented Sep 8, 2020

Happening with me too, my workaround is check OS and if iOS do it manually after onMapCreated.

@AAverin
Copy link
Contributor

AAverin commented Oct 25, 2020

Issue is still present on latest master, after the supposed fix was merged. @andrea689 Was the issue fixed in your tests?

@AAverin
Copy link
Contributor

AAverin commented Oct 25, 2020

Ok, this was an issue on my side, didn't update properly. Seems to be more stable now, I'll keep testing

@tobrun tobrun closed this as completed Oct 25, 2020
@AAverin
Copy link
Contributor

AAverin commented Oct 25, 2020

This is still completely unstable for me.
Sometimes callback is called, but most of the times it isn't

@AAverin
Copy link
Contributor

AAverin commented Oct 25, 2020

@tobrun We should reopen it. Style callback is not invoked, but looks like it's not in Flutter, it's not properly called from the native part.
I would assume that this should be long fixed in iOS Mapbox, so we should update to the latest and overall somehow keep dependencies up to date for this project.
#413

@AAverin
Copy link
Contributor

AAverin commented Oct 25, 2020

This callback in controller.dart never gets invoked for me

 MapboxGlPlatform.getInstance(_id).onMapStyleLoadedPlatform.add((_) {
      if (onStyleLoadedCallback != null) {
        onStyleLoadedCallback();
      }
    });

@tobrun tobrun reopened this Oct 26, 2020
@AAverin
Copy link
Contributor

AAverin commented Nov 6, 2020

Debugging in Xcode, this line is being correctly called

channel.invokeMethod("map#onStyleLoaded", arguments: nil)

But when debugging in flutter, this invocation somehow doesn't come to MethodChannelMapboxGl._handleMethodCall. All other methods, like onMapIdle, are correctly invoked.

Could it be related somehow to await _channel.invokeMethod('map#waitForMap'); call?

@AAverin
Copy link
Contributor

AAverin commented Nov 8, 2020

I have found what's going on.

If I modify method_channel_mapbox_gl.dart like this:

 @override
  Future<void> initPlatform(int id) async {
    assert(id != null);
    _channel = MethodChannel('plugins.flutter.io/mapbox_maps_$id');
    _channel.setMethodCallHandler((MethodCall call) async {
       print("${call.method} invoked before map was ready");
    });
    await _channel.invokeMethod('map#waitForMap');
    _channel.setMethodCallHandler(_handleMethodCall);
  }

onStyleLoaded callback on iOS will be invoked before map was ready.

@tobrun @m0nac0 Could you please help us out with this critical issue on iOS? I am not sure how to properly modify iOS MapBox code to run properly.

@AAverin
Copy link
Contributor

AAverin commented Nov 8, 2020

@andrea689 web support refactoring might have been the cause of this issue, this PR #223

@AAverin
Copy link
Contributor

AAverin commented Nov 16, 2020

@tobrun @m0nac0 this issue is a critical blocker for my project and I can't release until it is resolved.
Can I help you more in any way pushing this forward? I have already found the cause of the problem and would need some guidance from iOS to make a more robust native MapBox implementation.

@andrea689
Copy link
Collaborator

Hi @AAverin can you share a minimun app example with this problem? I have a production app and no have problems. If you want, try my app: https://apps.apple.com/it/app/3bee-i-tuoi-alveari/id1533079866

@AAverin
Copy link
Contributor

AAverin commented Nov 17, 2020

@andrea689 Looks like it's not as straightforward as I thought. I had this bug all the time during development, but release build looks to be working fine at the moment. I will try to compare and provide more details, but overall it seems that it is possible that onStyleLoaded will be invoked before waitForMap have finished. Even if it only happens on dev builds, I think it needs some kind of fix.

@andrea689
Copy link
Collaborator

@AAverin with #418 I fixed this. If onStyleLoadedCallback is called before the controller.isCompleted (waitForMap), I wait for controller future and after call onStyleLoadedCallback

https://github.com/tobrun/flutter-mapbox-gl/blob/7861b62ee1d396439d44ebb1f84563244aa6bf82/lib/src/mapbox_map.dart#L217-L243

@AAverin
Copy link
Contributor

AAverin commented Nov 17, 2020

@andrea689 I will take a look again, but now I am using latest master and I am pretty sure I still had issue on dev builds

@gabeschine
Copy link
Contributor

I also experience this. It seems racy: sometimes it is called, most times it is not. It is easy enough to reproduce by using "hot restart" in flutter.

@keehoo
Copy link

keehoo commented Feb 13, 2021

Still an issue in 0.10.0 ;(

@manhlhvm
Copy link

Still an issue in 0.10.0 ;(

me too :(

@AAverin
Copy link
Contributor

AAverin commented Feb 19, 2021

So far for me the issue only seems to reproduce on debug builds. Release builds seem to be fine, at least no users have complained yet.

@keehoo
Copy link

keehoo commented Feb 19, 2021

So far for me the issue only seems to reproduce on debug builds. Release builds seem to be fine, at least no users have complained yet.

@AAverin I was able to reproduce this on both release & debug (iOS)... I'm also not sure whether I saw this happening on Android, will check more and get back here if find anything.

@AAverin
Copy link
Contributor

AAverin commented Feb 19, 2021

Debugging this issue, it seemed as native methods inside Mapbox SDK were not called.
Because flutter-mapbox uses some old versions of Mapbox SDK I have created #413

@jgrandchavin
Copy link

I have exactly the same problem on iOS, still any solution found ?

@Sar777
Copy link

Sar777 commented Jun 30, 2021

any news?

@pdcolandrea
Copy link

still an issue on 0.12.0, only happening on ios I believe

@AAverin
Copy link
Contributor

AAverin commented Sep 5, 2021

I can also confirm this happening in production builds on real devices.
OnStyleLoaded callback is completely inconsistent on iOS

@AAverin
Copy link
Contributor

AAverin commented Sep 11, 2021

Some debugging results.
map#onStyleLoaded gets called before map#waitForMap, which means that _handleMethodCall in dart is not yet attached correctly and onStyleLoaded invocation will not reach dart codebase.
This results in the bug we have here.

@AAverin
Copy link
Contributor

AAverin commented Sep 11, 2021

Opened a PR with a fix

@samderlust
Copy link
Contributor

I still have this issue with Mapbox 0.14.0?

@AAverin
Copy link
Contributor

AAverin commented Jan 6, 2022

@samderlust In that case we would need your help debugging the issue.
Last fixes for for onStyleLoaded callback reliability were applied in this PR: #808
If you can reliably reproduce the problem can you try debugging your app to see what is the cause exactly?

@samderlust
Copy link
Contributor

@AAverin thanks, it fixed with mater branch

@stale
Copy link

stale bot commented Mar 14, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 14, 2022
@AAverin AAverin closed this as completed Mar 14, 2022
@kaspesi
Copy link

kaspesi commented Nov 21, 2024

Im seeing this in mapbox maps 11.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests