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,11 +53,14 @@ void oc_mtl_surface_destroy(oc_surface_data* interface)
void oc_mtl_surface_acquire_command_buffer(oc_mtl_surface* surface)
{
@autoreleasepool
{
if(surface->commandBuffer == nil)
{
surface->commandBuffer = [surface->commandQueue commandBuffer];
[surface->commandBuffer retain];
}
}
}
void oc_mtl_surface_acquire_drawable(oc_mtl_surface* surface)
@ -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 release];
surface->commandBuffer = nil;
}