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] Error is thrown when adding marker then centering map #1171

Closed
mbasa opened this issue Feb 23, 2022 · 18 comments
Closed

[BUG] Error is thrown when adding marker then centering map #1171

mbasa opened this issue Feb 23, 2022 · 18 comments
Labels
bug This issue reports broken functionality or another error

Comments

@mbasa
Copy link

mbasa commented Feb 23, 2022

I get the error below whenever I add a marker on a given position then center the map to the marker position. This error appears with versions 0.13.0 and 0.14.0, but not in 0.12.0.

The problem seems to be here: (package:flutter_map/src/layer/marker_layer.dart:217:21)

The source code of my project can be found here: https://github.com/mbasa/pgrServerDemo.

Thanks and regards,

Mario.

======== Exception caught by widgets library =======================================================
The following RangeError was thrown building StreamBuilder<int?>(dirty, state: _StreamBuilderBaseState<int?, AsyncSnapshot<int?>>#2220d):
RangeError (index): Invalid value: Only valid value is 0: 1

The relevant error-causing widget was: 
  FlutterMap FlutterMap:file:///Users/mbasa/Development/AndroidStudioProjects/pgrServerDemo/lib/main.dart:432:17
When the exception was thrown, this was the stack: 
#0      List._setIndexed (dart:core-patch/growable_array.dart:269:49)
#1      List.[]= (dart:core-patch/growable_array.dart:264:5)
#2      _MarkerLayerState.build.<anonymous closure> (package:flutter_map/src/layer/marker_layer.dart:217:21)
#3      StreamBuilder.build (package:flutter/src/widgets/async.dart:442:81)
#4      _StreamBuilderBaseState.build (package:flutter/src/widgets/async.dart:124:48)
#5      StatefulElement.build (package:flutter/src/widgets/framework.dart:4705:27)
#6      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4588:15)
#7      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4763:11)
#8      Element.rebuild (package:flutter/src/widgets/framework.dart:4311:5)
#9      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2578:33)
#10     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
#11     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:363:5)
#12     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1145:15)
#13     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1082:9)
#14     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
#18     _invoke (dart:ui/hooks.dart:150:10)
#19     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
#20     _drawFrame (dart:ui/hooks.dart:114:31)
(elided 3 frames from dart:async)

@mbasa mbasa added bug This issue reports broken functionality or another error needs triage This new bug report needs reproducing and prioritizing labels Feb 23, 2022
@ibrierley
Copy link
Contributor

There's a pull request at #1147 I did for a similar issue that may be related. Would you be able to test this at all, to see if it fixes your problem ? If so, I'll try and get it merged quicker.

@mbasa
Copy link
Author

mbasa commented Feb 23, 2022

Unfortunately, the error still persists. I did this:

flutter_map:
    git:
      url: https://github.com/ibrierley/flutter_map
      branch: markerlayer_crash_fix

but still get this:

Screen Shot 2022-02-23 at 16 57 35

@ibrierley
Copy link
Contributor

Yes, sorry I didn't spot your earlier comment, I don't think my fix is related to this issue.

I've tried running the app, how does one recreate the problem (does it need to be connected to the server?), as it all runs fine, but I'm probably doing something you're not adding the marker or whatever.

Can you try and create smaller test case for people to run.

@ibrierley
Copy link
Contributor

oh I get the pgServer is unavailable...so can't really test properly here. See if you can create a test that can run standalone without any connections etc for people to test.

@JaffaKetchup JaffaKetchup changed the title Error is thrown when adding marker then centering map [BUG] Error is thrown when adding marker then centering map Feb 23, 2022
@ibrierley
Copy link
Contributor

Actually, it could still be related....if you can, in flutter_maps marker_layer, around line 218, print out widget.markerLayerOptions.markers.length and _pxCache.length...are they different ?

@mbasa
Copy link
Author

mbasa commented Feb 23, 2022

Will test if the values are different.

But if you are running my app, once the map appears just click anywhere since that will add a marker on the clicked position and then center the map to that position. The error should appear. Thanks.

@ibrierley
Copy link
Contributor

Hi, I did, the centering doesn't work as it pops up an error about the pgrServer not being reachable, so I don't think any tests I've done are valid.

@mbasa
Copy link
Author

mbasa commented Feb 23, 2022

Can you please click on the icon on the AppBar and change the url to:

http://cld06.georepublic.net/pgrServer

then press the Zoom Bnd floating button in the map to recenter. Then just click anywhere to add a Marker.

Thanks thanks.

@ibrierley
Copy link
Contributor

ok, that gets rid of that error, but doesn't crash on my device.

@ibrierley
Copy link
Contributor

Actually, your pubspec is using 0.11.0 which may be why it doesn't for me....

@ibrierley
Copy link
Contributor

Ok, I think I managed to reproduce it, changing flutter_map to 0.14 in pubspec, dio: any, latlong2: ^0.8.1

Then it crashes when adding/recentering, but it doesnt crash if I use my PR

flutter_map:
    git:
      url: git://github.com/ibrierley/flutter_map
      ref: markerlayer_crash_fix

Make sure you do a new pub get etc after changing that...see if it helps.

@ibrierley
Copy link
Contributor

Possibly make sure you use ref: and not branch: in the pubspec as above, I'm not sure if there's any difference or what.

@JaffaKetchup JaffaKetchup added non-fatal and removed needs triage This new bug report needs reproducing and prioritizing labels Feb 23, 2022
@tantzygames
Copy link

tantzygames commented Feb 24, 2022

I am also encountering this after upgrading from 0.12.0 to 0.14.0

I'll do a pull request when I get a chance. Until then in the file lib/src/layers/marker_layer.dart add this at line 210:

if (_pxCache.length != widget.markerLayerOptions.markers.length) {
  _pxCache = generatePxCache();
}

@JaffaKetchup
Copy link
Member

@tantzygames, I think your suggestion already appears in @ibrierley's #1147?

@tantzygames
Copy link

I see, so it does. Thanks for that

@mbasa
Copy link
Author

mbasa commented Feb 28, 2022

@ibrierley apologies for not replying much sooner, but your branch referenced as:

flutter_map:
      git:
        url: https://github.com/ibrierley/flutter_map
        ref: markerlayer_crash_fix

does fix the problem. I have been testing for over an hour now and have yet to experience a crash like before.

Thanks.

@ibrierley
Copy link
Contributor

No problem, this fix has been merged now.

@ibrierley
Copy link
Contributor

I'm going to close this, as I'm assuming the PR sorts this on the whole (at least prevents crashing and one can turn off caching). Feel free to reopen if still a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue reports broken functionality or another error
Projects
None yet
Development

No branches or pull requests

4 participants