Fix leak in metal surface: command buffer must not be committed if there is no surface to present it to, or it will result in a huge leak in metal resources. Also wrap oc_mtl_surface_acquire_command_buffer() in an @autoreleasepool to fix a smaller leak

This commit is contained in:
Martin Fouilleul 2023-08-23 15:09:06 +02:00
parent 86b1121fbe
commit 98f131cb30
1 changed files with 8 additions and 4 deletions

View File

@ -53,10 +53,13 @@ void oc_mtl_surface_destroy(oc_surface_data* interface)
void oc_mtl_surface_acquire_command_buffer(oc_mtl_surface* surface)
{
if(surface->commandBuffer == nil)
@autoreleasepool
{
surface->commandBuffer = [surface->commandQueue commandBuffer];
[surface->commandBuffer retain];
if(surface->commandBuffer == nil)
{
surface->commandBuffer = [surface->commandQueue commandBuffer];
[surface->commandBuffer retain];
}
}
}
@ -102,8 +105,9 @@ void oc_mtl_surface_present(oc_surface_data* interface)
[surface->commandBuffer presentDrawable:surface->drawable];
[surface->drawable release];
surface->drawable = nil;
[surface->commandBuffer commit];
}
[surface->commandBuffer commit];
[surface->commandBuffer release];
surface->commandBuffer = nil;
}