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 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Random offlineRegionStatusDidChange unrecognized selector crash #4394
@1ec5 This happens on first access of [MGLOfflineStorage sharedOfflineStorage] after app launch so my code has no references to any offline pack instances as that point.
MBGLOfflineRegionObserver::statusChanged() is on the stack, which would indicate that an MGLOfflinePack has been created in response to either calling -[MGLOfflineStorage getPacksWithCompletionHandler:] or -[MGLOfflineStorage addPackForRegion:withContext:completionHandler:]. I’m not sure how the MBGLOfflineRegionObserver would be created otherwise.
@1ec5 I took another look and in fact getPacksWithCompletionHandler was being called in response to app activation. The docs need to be updated to clearly that offline packs passed to the completion handler need to be retained by the calling context.
Ultimately, it would be preferrable to have a different API on MGLOfflineStorage and MGLOfflinePack. Having to fetch all packs to fetch a specific pack is inefficient. The delegate protocol that is supposed to be used by both MGLOfflineStorage and app code is too fragile.
The docs need to be updated to clearly that offline packs passed to the completion handler need to be retained by the calling context.
Updated. Thanks for the reminder.
Having to fetch all packs to fetch a specific pack is inefficient.
Good point. The iOS offline API started out mimicking NSURLSession and related classes to some extent, but it no longer clearly fits into that paradigm. MGLOfflinePack is just a lightweight wrapper around mbgl:OfflineRegion in the cross-platform code. Currently, if you call -getPacksWithCompletionHandler: twice in a row, you’ll get two different sets of MGLOfflinePack objects that wrap the same logical downloads.
The new notification-based design in #4287 (comment) will likely have MGLOfflineStorage maintain a master list of MGLOfflinePacks that allows synchronous access (adding, pausing, and resuming would still be asynchronous). I think we’ll also be able to maintain a one-to-one relationship between MGLOfflinePacks and mbgl::OfflineRegions that way.
Activity
1ec5 commentedon Mar 18, 2016
Looks like OfflineRegionObserver has a dangling pointer to the MGLOfflinePack. The workaround seems to be to hold a strong reference to the offline pack somewhere. For example, if you have a table of offline packs in your UI, the table view controller should manage an array of offline packs, only removing them just before calling -removePackWithCompletionHandler:. See https://github.com/mapbox/mapbox-gl-native/blob/ios-v3.2.0-beta.2/platform/ios/app/MBXOfflinePacksTableViewController.m for the full example code.
1ec5 commentedon Mar 18, 2016
This is exactly the kind of scenario I'm trying to avoid in #4287.
postmechanical commentedon Mar 19, 2016
@1ec5 This happens on first access of
[MGLOfflineStorage sharedOfflineStorage]after app launch so my code has no references to any offline pack instances as that point.1ec5 commentedon Mar 19, 2016
MBGLOfflineRegionObserver::statusChanged()is on the stack, which would indicate that an MGLOfflinePack has been created in response to either calling-[MGLOfflineStorage getPacksWithCompletionHandler:]or-[MGLOfflineStorage addPackForRegion:withContext:completionHandler:]. I’m not sure how theMBGLOfflineRegionObserverwould be created otherwise.postmechanical commentedon Mar 19, 2016
@1ec5 I took another look and in fact getPacksWithCompletionHandler was being called in response to app activation. The docs need to be updated to clearly that offline packs passed to the completion handler need to be retained by the calling context.
Ultimately, it would be preferrable to have a different API on MGLOfflineStorage and MGLOfflinePack. Having to fetch all packs to fetch a specific pack is inefficient. The delegate protocol that is supposed to be used by both MGLOfflineStorage and app code is too fragile.
1ec5 commentedon Mar 19, 2016
Updated. Thanks for the reminder.
Good point. The iOS offline API started out mimicking NSURLSession and related classes to some extent, but it no longer clearly fits into that paradigm. MGLOfflinePack is just a lightweight wrapper around
mbgl:OfflineRegionin the cross-platform code. Currently, if you call-getPacksWithCompletionHandler:twice in a row, you’ll get two different sets of MGLOfflinePack objects that wrap the same logical downloads.The new notification-based design in #4287 (comment) will likely have MGLOfflineStorage maintain a master list of MGLOfflinePacks that allows synchronous access (adding, pausing, and resuming would still be asynchronous). I think we’ll also be able to maintain a one-to-one relationship between MGLOfflinePacks and
mbgl::OfflineRegions that way.postmechanical commentedon Mar 21, 2016
@1ec5 Still crashing even though calling context now retains all offline packs from
getPacksWithCompletionHandler:.1ec5 commentedon Mar 28, 2016
Pretty sure this will be fixed through a combination of #4410 and #4482.
1ec5 commentedon Mar 29, 2016
Fixed in #4410 and #4482, which will be in v3.2.0-beta.3.