Skip to content

Commit f89bba4

Browse files
authored
Merge pull request #83 from HippoAR/fix-empty-ar-view
Always call init method on main thread
2 parents eeee6e4 + 1673f34 commit f89bba4

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

ios/RCTARKit.m

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,27 @@ @interface RCTARKit () <ARSCNViewDelegate, ARSessionDelegate, UIGestureRecognize
2222
@end
2323

2424

25+
void dispatch_once_on_main_thread(dispatch_once_t *predicate,
26+
dispatch_block_t block) {
27+
if ([NSThread isMainThread]) {
28+
dispatch_once(predicate, block);
29+
} else {
30+
if (DISPATCH_EXPECT(*predicate == 0L, NO)) {
31+
dispatch_sync(dispatch_get_main_queue(), ^{
32+
dispatch_once(predicate, block);
33+
});
34+
}
35+
}
36+
}
37+
38+
2539
@implementation RCTARKit
2640

2741
+ (instancetype)sharedInstance {
2842
static RCTARKit *instance = nil;
2943
static dispatch_once_t onceToken;
3044

31-
dispatch_once(&onceToken, ^{
45+
dispatch_once_on_main_thread(&onceToken, ^{
3246
if (instance == nil) {
3347
ARSCNView *arView = [[ARSCNView alloc] init];
3448
instance = [[self alloc] initWithARView:arView];
@@ -67,7 +81,6 @@ - (instancetype)initWithARView:(ARSCNView *)arView {
6781
// start ARKit
6882
[self addSubview:arView];
6983
[self resume];
70-
7184
}
7285
return self;
7386
}

0 commit comments

Comments
 (0)