Skip to content

Commit

Permalink
Fixed multi-threading causing view read failure (#16253)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuguohua authored Sep 15, 2023
1 parent 290746a commit 608660a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
6 changes: 3 additions & 3 deletions native/cocos/platform/mac/modules/Screen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ of this software and associated engine source code (the "Software"), a limited,
#include "base/Macros.h"
#include "cocos/bindings/jswrapper/SeApi.h"
#include "platform/interfaces/modules/ISystemWindowManager.h"
#include "platform/interfaces/modules/ISystemWindow.h"
#include "platform/mac/modules/SystemWindow.h"
#include "application/ApplicationManager.h"
namespace cc {

Expand All @@ -52,8 +52,8 @@ of this software and associated engine source code (the "Software"), a limited,
global->getProperty("devicePixelRatio", &devicePixelRatioVal);
return devicePixelRatioVal.isNumber() ? devicePixelRatioVal.toFloat() : 1.F;
#else
auto* window = CC_GET_MAIN_SYSTEM_WINDOW();
NSWindow* nsWindow = reinterpret_cast<NSWindow*>(window->getWindowHandle()) ;
auto* systemWindow = static_cast<SystemWindow*>(CC_GET_MAIN_SYSTEM_WINDOW());
auto* nsWindow = systemWindow->getNSWindow();
return [nsWindow backingScaleFactor];
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion native/cocos/platform/mac/modules/SystemWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ of this software and associated documentation files (the "Software"), to deal
[view addSubview:newView];
[nsWindow.contentView setWantsBestResolutionOpenGLSurface:YES];
[nsWindow makeKeyAndOrderFront:nil];
_windowHandle = reinterpret_cast<uintptr_t>(nsWindow.contentView) ;
_windowHandle = reinterpret_cast<uintptr_t>(newView);

auto dpr = [nsWindow backingScaleFactor];
_width = w * dpr;
Expand Down
7 changes: 0 additions & 7 deletions native/cocos/renderer/gfx-metal/MTLSwapchain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ of this software and associated engine source code (the "Software"), a limited,
if (!layer.device) {
layer.device = MTLCreateSystemDefaultDevice();
}
#elif CC_PLATFORM == CC_PLATFORM_MACOS
CAMetalLayer *layer = nullptr;
auto *view = (CCView *)info.windowHandle;
if(view && view.subviews.count > 0) {
NSView* subView = view.subviews[0];
layer = static_cast<CAMetalLayer *>(subView.layer);
}
#else
auto *view = (CCView *)info.windowHandle;
CAMetalLayer *layer = static_cast<CAMetalLayer *>(view.layer);
Expand Down

0 comments on commit 608660a

Please sign in to comment.