Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
[ios, macos] Initialize offline storage on main thread before snapsho…
Browse files Browse the repository at this point in the history
…tting
  • Loading branch information
1ec5 committed Apr 7, 2020
1 parent 928f37f commit 9449b65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 7 additions & 2 deletions platform/darwin/src/MGLMapSnapshotter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,14 @@ - (void)startWithQueue:(dispatch_queue_t)queue overlayHandler:(MGLMapSnapshotOve
if (!completion) {
return;
}
if (!mbgl::Scheduler::GetCurrent()) {

// Ensure that offline storage has been initialized on the main thread, as MGLMapView and MGLOfflineStorage do when used directly.
// https://github.com/mapbox/mapbox-gl-native-ios/issues/227
if ([NSThread.currentThread isMainThread]) {
(void)[MGLOfflineStorage sharedOfflineStorage];
} else {
[NSException raise:NSInvalidArgumentException
format:@"startWithQueue:completionHandler: must be called from a thread with an active run loop."];
format:@"-[MGLMapSnapshotter startWithQueue:completionHandler:] must be called from the main thread, not %@.", NSThread.currentThread];
}

if (self.loading) {
Expand Down
4 changes: 0 additions & 4 deletions platform/darwin/test/MGLMapSnapshotterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ - (void)setUp {
[super setUp];

[MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"];

// Initialize file system and run loop before snapshotting.
// https://github.com/mapbox/mapbox-gl-native-ios/issues/227
(void)[MGLOfflineStorage sharedOfflineStorage];
}

- (void)tearDown {
Expand Down

0 comments on commit 9449b65

Please sign in to comment.