summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Kiley <jmkiley@users.noreply.github.com>2018-11-13 16:07:19 -0800
committerjmkiley <jordan.kiley@mapbox.com>2018-11-13 16:09:27 -0800
commitc47b08beecf639f20fa9b3a62f1bc4736c8c6acf (patch)
treeebd357724ac0a6aebd498803b285f93f0acafab7
parente35921e504a94cbe5f8cbc35b15943f1d2e8903f (diff)
downloadqtlocation-mapboxgl-upstream/jmkiley-cp-13300.tar.gz
[ios] Address bad access exception in `MGLAttributionInfo` (#13300)upstream/jmkiley-cp-13300
* [ios] move creation of attributed string to global queue] * [ios] check if on main queue
-rw-r--r--platform/darwin/src/MGLAttributionInfo.mm18
1 files changed, 14 insertions, 4 deletions
diff --git a/platform/darwin/src/MGLAttributionInfo.mm b/platform/darwin/src/MGLAttributionInfo.mm
index 07d10e852b..b780b2ae0d 100644
--- a/platform/darwin/src/MGLAttributionInfo.mm
+++ b/platform/darwin/src/MGLAttributionInfo.mm
@@ -65,10 +65,20 @@
NSData *htmlData = [styledHTML dataUsingEncoding:NSUTF8StringEncoding];
#if TARGET_OS_IPHONE
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData:htmlData
- options:options
- documentAttributes:nil
- error:NULL];
+ __block NSMutableAttributedString *attributedString;
+ dispatch_block_t initialization = ^{
+ // This initializer should be called from a global or main queue. https://developer.apple.com/documentation/foundation/nsattributedstring/1524613-initwithdata
+ attributedString = [[NSMutableAttributedString alloc] initWithData:htmlData
+ options:options
+ documentAttributes:nil
+ error:NULL];
+ };
+
+ if (![[NSThread currentThread] isMainThread]) {
+ dispatch_sync(dispatch_get_main_queue(), initialization);
+ } else {
+ initialization();
+ }
#else
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithHTML:htmlData
options:options