From 8a40c62eed5900fa6d9715861e4059778e867afb Mon Sep 17 00:00:00 2001 From: Jordan Kiley Date: Wed, 14 Nov 2018 11:13:13 -0800 Subject: [ios] Address bad access exception in `MGLAttributionInfo` (#13300) (#13365) --- platform/darwin/src/MGLAttributionInfo.mm | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/platform/darwin/src/MGLAttributionInfo.mm b/platform/darwin/src/MGLAttributionInfo.mm index 5fa121f5f8..b780b2ae0d 100644 --- a/platform/darwin/src/MGLAttributionInfo.mm +++ b/platform/darwin/src/MGLAttributionInfo.mm @@ -65,16 +65,20 @@ NSData *htmlData = [styledHTML dataUsingEncoding:NSUTF8StringEncoding]; #if TARGET_OS_IPHONE - __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]; + }; - dispatch_sync(dispatch_get_main_queue() , ^{ - // 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 -- cgit v1.2.1