@@ -43,8 +43,7 @@ + (void)setView:(RCTBridge*)bridge jsRunLoop:(NSRunLoop*)jsRunLoop mktView:(MTKV
4343
4444 [jsRunLoop performBlock: ^{
4545 if (bridge != currentBridge) {
46- currentBridge = bridge;
47- [BabylonNativeInterop setCurrentNativeInstance: mtkView width: width height: height];
46+ [BabylonNativeInterop setCurrentNativeInstance: bridge mtkView: mtkView width: width height: height];
4847 } else if (currentNativeInstance) {
4948 if (mtkView != currentView) {
5049 [BabylonNativeInterop setCurrentView: mtkView];
@@ -104,6 +103,7 @@ + (void)reportTouchEvent:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
104103}
105104
106105+ (void )whenInitialized : (RCTBridge*)bridge resolve : (RCTPromiseResolveBlock)resolve {
106+ const std::lock_guard<std::mutex> lock (mapMutex);
107107 if (bridge == currentBridge) {
108108 resolve ([NSNumber numberWithUnsignedLong: reinterpret_cast <uintptr_t >(currentNativeInstance.get ())]);
109109 } else {
@@ -116,16 +116,20 @@ + (void)setCurrentView:(MTKView*)mtkView {
116116 activeTouches = [NSMutableArray new ];
117117}
118118
119- + (void )setCurrentNativeInstance : (MTKView *)mtkView width : (int )width height : (int )height {
119+ + (void )setCurrentNativeInstance : (RCTBridge*) bridge mtkView : ( MTKView *)mtkView width : (int )width height : (int )height {
120120 [BabylonNativeInterop setCurrentView: mtkView];
121121
122- const std::lock_guard<std::mutex> lock (mapMutex);
122+ {
123+ const std::lock_guard<std::mutex> lock (mapMutex);
123124
124- currentNativeInstance. reset () ;
125+ currentBridge = bridge ;
125126
126- jsi::Runtime* jsiRuntime = GetJSIRuntime (currentBridge);
127- if (jsiRuntime) {
128- currentNativeInstance = std::make_unique<Babylon::Native>(GetJSIRuntime (currentBridge), (__bridge void *)mtkView, width, height);
127+ currentNativeInstance.reset ();
128+
129+ jsi::Runtime* jsiRuntime = GetJSIRuntime (currentBridge);
130+ if (jsiRuntime) {
131+ currentNativeInstance = std::make_unique<Babylon::Native>(GetJSIRuntime (currentBridge), (__bridge void *)mtkView, width, height);
132+ }
129133 }
130134
131135 auto initializationPromisesIterator = initializationPromises.find ((__bridge void *)currentBridge);
0 commit comments