You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 25, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 25, 2023. It is now read-only.
Crash when dismissing map view rendering tiles #26
I'm seeing a crash when dismissing a view controller displaying a map view that is still in the process of rendering tiles. When I enabled NSZombie, I received the following.
*** -[VKRasterOverlayTileSource invalidateRect:level:]: message sent to deallocated instance 0x1adee910
I had made a few changes to MBXMapView to support initialization with TileJSON, so I backed those out. The problem remained. Since MBXMapView is a subclass, it was trivial to switch to an instance of MKMapKit, which does not exhibit the crash.
I attempted to reproduce this on the demo app by presenting the map view controller modally, adding a tap gesture recognizer and dismissing it on tap. This worked fine until I initialized the map view with our custom map ID.
I've reset the simulator after changing the mapID and the problem remains. I've also checked that self and self.mapView is not the zombie. I've reproduced this without setting the external delegate. My guess is that it has something to do with the invocation forwarding, as commenting out the internal delegate prevents the crash.
To reproduce, dismiss a view controller displaying the map before it finishes rendering all of the tiles for the currently displayed region.
I've just submitted a support issue on the MapBox support site. It contains a modified version of the demo project with the MapIDs in question, which can used to reproduce the issue.
I've added a presenting view controller and a corresponding xib file with a button. Tapping the button calls mapTapped: which presents the map view controller. I've also added a tap gesture recognizer to the map view that dismisses its view controller. The presentation works fine and the gesture recognizer is active. However, if I tap on the map before it finishes rendering tiles for the visible region, it crashes. Enabling NSZombies indicates VKRasterOverlayTileSource invalidateRect:level: is being called on a deallocated object.
@implementation MBXLauncherViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)showMapViewController:(id)sender
{
MBXViewController *viewController = [[MBXViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:viewController animated:YES completion:nil];
}
@end
@implementation MBXViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// iOS project shows use via programmatic view API
//
MBXMapView *mapView = [[MBXMapView alloc] initWithFrame:self.view.bounds mapID:@"newMapID"];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mapTapped:)];
tapRecognizer.numberOfTouchesRequired = 1;
tapRecognizer.numberOfTapsRequired = 1;
[mapView addGestureRecognizer:tapRecognizer];
[self.view addSubview:mapView];
}
- (void)mapTapped:(id)sender
{
[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
}
@end
This fixes the issue in the demo. However, when I set my view controller as a delegate in my actual app the crash returned. Setting the map view's delegate to nil before invalidating the network session in cancelDownloadTasks seemed to resolve the issue.
Confidentiality Note: This e-mail is intended only for the person or entity
to which it is addressed and may contain information that is privileged,
confidential or otherwise protected from disclosure. Dissemination,
distribution or copying of this e-mail or the information herein by anyone
other than the intended recipient, or an employee or agent responsible for
delivering the message to the intended recipient, is prohibited. If you
have received this e-mail in error, please contact the sender and
destroy the original message and all copies.
I'm curious how you're using the delegate stuff. I've been thinking about
trying to roll some of the fixes I've been working on recently into a new
version, and I talked with Justin about that a little bit (no conclusions
yet).
It's not clear to me if the delegate proxying stuff is more trouble than
it's worth. At the moment it's necessary for certain things, but I think
that's mainly because MBXMapView and MBXMapViewTileOverlay are tightly
coupled. The advantage of doing it that was is that you can add a map with
a two-line invocation like:
The dis-advantage is that if you want to do something more complicated,
the delegate proxying makes the overall structure of MBXMapKit more
complicated to understand, modify, and use without errors. I wonder about
the possible merits of de-coupling MBXMapView and MBXMapViewOverlay
somewhat, removing the delegate proxying, and providing some sample apps
showing how to achieve equivalent functionality.
Any thoughts on that?
Reply to this email directly or view it on GitHubhttps://github.com//issues/26#issuecomment-33711098
.
Rather than use a static TileMill file, we dynamical grab tiles over then network from MapBox when a user logs in, which are stored in an instance of RMMapBoxSource. This occurs though a call to RMMapBoxSource beginBackgroundCacheForTileSource:southWest:northEast:minZoom:maxZoom:. As part of our migration from RMMapView to MBXMapView, I've created an adaptor class, which we assign to the titleDelegate of MBXMapView. This adaptor allows MBXMapView to use cached tiles from an RMMapBoxSource while offline.
To make this work offline, I had to create an in-house implementation that allows a MBXMapView to be initialized with TileJSON. I ran into the the same issue you did while trying to implement support for TileMill files.
My perspective would be to keep the simple on line initializers, but have them create an appropriate internal delegate and pass them to a multi parameter initializer that takes an interface or a default/abstract base class, rather than just MBXMapViewTileOverlay.
For example, we could create specific, simple initializer that takes an instance of RMMapBoxSource ( or a MBXMapKit analog that performs the same role and implements beginBackgroundCache...).
In an effort to get to the bottom of this, I've created a stripped down version of MBXMapView that only implements the absolute minimum necessary to display one of our MapBox maps. This includes forgoing initialization from a local or remote TileJSON file and using an instance of MKTileOverlay initialized with a URL template for one of our MapBox maps. This is in contrast to using the provided MBXMapViewTileOverlay. As such, Apple's default implementation of URLForTilePath: and loadTileAtPath:result: is being called and none of the MBXMapKit networking code is in play.
Despite these changes, I'm still seeing the following output when NSZombies is enabled.
*** -[VKRasterOverlayTileSource invalidateRect:level:]: message sent to deallocated instance 0x1bb2d080
So, it would appear that this issue is inherited from MKMapKit, rather than specific to MBXMapKit itself.
wsnook:Are you saying that there's still a problem which my fix doesn't successfully work around?
Yes. I still ran into crashes when quickly dismissing the map. I tried tapping into the did finish rendering delegate methods to postpone dismissal of the displaying view controller, but crashes remain.
While putting together the basic test case for Apple, which uses a stock MKTileOverlay and template, I tried removing the tile overlay before dismissing the presenting view controller. This did seem to prevent a crash when other solutions did not.
So, it would appear that this issue is inherited from MKMapKit, rather than specific to MBXMapKit itself.
Sounds like this sums it up, but that there is also at least one workaround for avoiding it? In that case I'm going to close.
It reminds me of a similar early issue with CLLocationManager where deallocating instances would still send messages to their delegate. It was pretty edge case, and in later versions it was fixed and isn't a problem anymore.
Add a property in your tile overlay class that points to the map view. This way when the view controller is dealloc then the map view will still be alive to receive the result block because the tile overlay class is pointing to it.
I would still consider this a bug but this seems to be a decent work around.
Activity
lightandshadow68 commentedon Jan 27, 2014
I attempted to reproduce this on the demo app by presenting the map view controller modally, adding a tap gesture recognizer and dismissing it on tap. This worked fine until I initialized the map view with our custom map ID.
lightandshadow68 commentedon Jan 27, 2014
I was able to reproduce this by creating a new satellite baselayer map in the MapBox admin section and using the newly created MapID.
lightandshadow68 commentedon Jan 28, 2014
I've reset the simulator after changing the mapID and the problem remains. I've also checked that self and self.mapView is not the zombie. I've reproduced this without setting the external delegate. My guess is that it has something to do with the invocation forwarding, as commenting out the internal delegate prevents the crash.
To reproduce, dismiss a view controller displaying the map before it finishes rendering all of the tiles for the currently displayed region.
I've just submitted a support issue on the MapBox support site. It contains a modified version of the demo project with the MapIDs in question, which can used to reproduce the issue.
lightandshadow68 commentedon Jan 28, 2014
I've added a presenting view controller and a corresponding xib file with a button. Tapping the button calls mapTapped: which presents the map view controller. I've also added a tap gesture recognizer to the map view that dismisses its view controller. The presentation works fine and the gesture recognizer is active. However, if I tap on the map before it finishes rendering tiles for the visible region, it crashes. Enabling NSZombies indicates
VKRasterOverlayTileSource invalidateRect:level:is being called on a deallocated object.lightandshadow68 commentedon Jan 30, 2014
This fixes the issue in the demo. However, when I set my view controller as a delegate in my actual app the crash returned. Setting the map view's delegate to nil before invalidating the network session in
cancelDownloadTasksseemed to resolve the issue.neogithub commentedon Jan 30, 2014
I like option 2 as a more generalized approach.
*Evan Buxton, *Associate Principal
Neoscape
Boston* | New York *
T 617.345.0330 F 617.345.0660 C 617.852.2317
neoscape.com
Confidentiality Note: This e-mail is intended only for the person or entity
to which it is addressed and may contain information that is privileged,
confidential or otherwise protected from disclosure. Dissemination,
distribution or copying of this e-mail or the information herein by anyone
other than the intended recipient, or an employee or agent responsible for
delivering the message to the intended recipient, is prohibited. If you
have received this e-mail in error, please contact the sender and
destroy the original message and all copies.
On Thu, Jan 30, 2014 at 12:29 PM, Will Snook [email protected]:
lightandshadow68 commentedon Jan 30, 2014
Rather than use a static TileMill file, we dynamical grab tiles over then network from MapBox when a user logs in, which are stored in an instance of RMMapBoxSource. This occurs though a call to
RMMapBoxSource beginBackgroundCacheForTileSource:southWest:northEast:minZoom:maxZoom:. As part of our migration from RMMapView to MBXMapView, I've created an adaptor class, which we assign to the titleDelegate of MBXMapView. This adaptor allows MBXMapView to use cached tiles from an RMMapBoxSource while offline.To make this work offline, I had to create an in-house implementation that allows a MBXMapView to be initialized with TileJSON. I ran into the the same issue you did while trying to implement support for TileMill files.
My perspective would be to keep the simple on line initializers, but have them create an appropriate internal delegate and pass them to a multi parameter initializer that takes an interface or a default/abstract base class, rather than just
MBXMapViewTileOverlay.For example, we could create specific, simple initializer that takes an instance of RMMapBoxSource ( or a MBXMapKit analog that performs the same role and implements beginBackgroundCache...).
lightandshadow68 commentedon Feb 10, 2014
In an effort to get to the bottom of this, I've created a stripped down version of MBXMapView that only implements the absolute minimum necessary to display one of our MapBox maps. This includes forgoing initialization from a local or remote TileJSON file and using an instance of MKTileOverlay initialized with a URL template for one of our MapBox maps. This is in contrast to using the provided MBXMapViewTileOverlay. As such, Apple's default implementation of
URLForTilePath:andloadTileAtPath:result:is being called and none of the MBXMapKit networking code is in play.Despite these changes, I'm still seeing the following output when NSZombies is enabled.
*** -[VKRasterOverlayTileSource invalidateRect:level:]: message sent to deallocated instance 0x1bb2d080So, it would appear that this issue is inherited from MKMapKit, rather than specific to MBXMapKit itself.
lightandshadow68 commentedon Feb 20, 2014
wsnook:Are you saying that there's still a problem which my fix doesn't successfully work around?
Yes. I still ran into crashes when quickly dismissing the map. I tried tapping into the did finish rendering delegate methods to postpone dismissal of the displaying view controller, but crashes remain.
While putting together the basic test case for Apple, which uses a stock MKTileOverlay and template, I tried removing the tile overlay before dismissing the presenting view controller. This did seem to prevent a crash when other solutions did not.
incanus commentedon Feb 21, 2014
Sounds like this sums it up, but that there is also at least one workaround for avoiding it? In that case I'm going to close.
It reminds me of a similar early issue with
CLLocationManagerwhere deallocating instances would still send messages to their delegate. It was pretty edge case, and in later versions it was fixed and isn't a problem anymore.dmorneault commentedon Mar 1, 2014
Add a property in your tile overlay class that points to the map view. This way when the view controller is dealloc then the map view will still be alive to receive the result block because the tile overlay class is pointing to it.
I would still consider this a bug but this seems to be a decent work around.