Skip to content

Commit afccdea

Browse files
committed
fix(ios): use synchronized for pointer array op to avoid possible crash
1 parent 0b1bb64 commit afccdea

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

packages/react-native-external-display/ios/RNExternalDisplay.mm

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ - (UIView *)view
1717
{
1818
RNExternalDisplayView *view = [RNExternalDisplayView new];
1919
view.delegate = self;
20-
if (!_views) {
21-
_views = [NSPointerArray weakObjectsPointerArray];
20+
@synchronized(self) {
21+
if (!_views) {
22+
_views = [NSPointerArray weakObjectsPointerArray];
23+
}
24+
[_views addPointer:(__bridge void *)view];
2225
}
23-
[_views addPointer:(__bridge void *)view];
2426
return view;
2527
}
2628

@@ -48,12 +50,14 @@ - (void)checkScreen
4850

4951
- (void)removeView:(RNExternalDisplayView*)target
5052
{
51-
NSUInteger index = 0;
52-
for (RNExternalDisplayView *view in _views) {
53-
if (view == target) {
54-
[_views removePointerAtIndex:index];
53+
@synchronized(self) {
54+
NSUInteger index = 0;
55+
for (RNExternalDisplayView *view in _views) {
56+
if (view == target) {
57+
[_views removePointerAtIndex:index];
58+
}
59+
index++;
5560
}
56-
index++;
5761
}
5862
}
5963

0 commit comments

Comments
 (0)