Fix leak in canvas code and samples #60

Merged
MartinFouilleul merged 3 commits from fix_canvas_leak into main 2023-08-23 14:33:22 +00:00
1 changed files with 8 additions and 4 deletions
Showing only changes of commit 98f131cb30 - Show all commits

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) void oc_mtl_surface_acquire_command_buffer(oc_mtl_surface* surface)
{ {
if(surface->commandBuffer == nil) @autoreleasepool
{ {
surface->commandBuffer = [surface->commandQueue commandBuffer]; if(surface->commandBuffer == nil)
[surface->commandBuffer retain]; {
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->commandBuffer presentDrawable:surface->drawable];
[surface->drawable release]; [surface->drawable release];
surface->drawable = nil; surface->drawable = nil;
[surface->commandBuffer commit];
} }
[surface->commandBuffer commit];
[surface->commandBuffer release]; [surface->commandBuffer release];
surface->commandBuffer = nil; surface->commandBuffer = nil;
} }