MetalDevice: Retain references to layer

Apparently the allocate method returns +0 references.
This commit is contained in:
Stenzek 2025-07-19 00:56:52 +10:00
parent 210f492487
commit b545671d67
No known key found for this signature in database
2 changed files with 9 additions and 9 deletions

View File

@ -163,7 +163,7 @@ void MetalSwapChain::Destroy(bool wait_for_gpu)
MetalDevice::GetInstance().WaitForGPUIdle();
RunOnMainThread([this]() {
NSView* view = (__bridge NSView*)m_window_info.window_handle;
NSView* view = (NSView*)m_window_info.window_handle;
[view setLayer:nil];
[view setWantsLayer:FALSE];
[m_layer release];
@ -219,7 +219,7 @@ std::unique_ptr<GPUSwapChain> MetalDevice::CreateSwapChain(const WindowInfo& wi,
@autoreleasepool
{
INFO_LOG("Creating a {}x{} Metal layer.", wi_copy.surface_width, wi_copy.surface_height);
layer = [CAMetalLayer layer]; // TODO: Does this need retain??
layer = [[CAMetalLayer layer] retain];
if (layer == nil)
{
Error::SetStringView(error, "Failed to create metal layer.");
@ -242,7 +242,7 @@ std::unique_ptr<GPUSwapChain> MetalDevice::CreateSwapChain(const WindowInfo& wi,
VERBOSE_LOG("Metal layer pixel format is {}.", GPUTexture::GetFormatName(wi_copy.surface_format));
NSView* view = (__bridge NSView*)wi_copy.window_handle;
NSView* view = (NSView*)wi_copy.window_handle;
[view setWantsLayer:TRUE];
[view setLayer:layer];
}

View File

@ -104,19 +104,19 @@ void* CocoaTools::CreateMetalLayer(const WindowInfo& wi, Error* error)
return ret;
}
CAMetalLayer* layer = [CAMetalLayer layer];
CAMetalLayer* layer = [[CAMetalLayer layer] retain];
if (layer == nil)
{
Error::SetStringView(error, "Failed to create CAMetalLayer");
return nullptr;
}
NSView* view = (__bridge NSView*)wi.window_handle;
NSView* view = (NSView*)wi.window_handle;
[view setWantsLayer:TRUE];
[view setLayer:layer];
[layer setContentsScale:[[[view window] screen] backingScaleFactor]];
return (__bridge void*)layer;
return layer;
}
void CocoaTools::DestroyMetalLayer(const WindowInfo& wi, void* layer)
@ -128,8 +128,8 @@ void CocoaTools::DestroyMetalLayer(const WindowInfo& wi, void* layer)
return;
}
NSView* view = (__bridge NSView*)wi.window_handle;
CAMetalLayer* clayer = (__bridge CAMetalLayer*)layer;
NSView* view = (NSView*)wi.window_handle;
CAMetalLayer* clayer = (CAMetalLayer*)layer;
[view setLayer:nil];
[view setWantsLayer:NO];
[clayer release];
@ -145,7 +145,7 @@ std::optional<float> CocoaTools::GetViewRefreshRate(const WindowInfo& wi, Error*
}
std::optional<float> ret;
NSView* const view = (__bridge NSView*)wi.window_handle;
NSView* const view = (NSView*)wi.window_handle;
const u32 did = [[[[[view window] screen] deviceDescription] valueForKey:@"NSScreenNumber"] unsignedIntValue];
if (CGDisplayModeRef mode = CGDisplayCopyDisplayMode(did))
{