Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CommandBufferMTL.mm #20575

Open
wants to merge 1 commit into
base: v4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion cocos/renderer/backend/metal/CommandBufferMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ inline int clamp(int value, int min, int max) {

CommandBufferMTL::~CommandBufferMTL()
{
if (_mtlCommandBuffer != nil) {
if ([_mtlCommandBuffer status] == MTLCommandBufferStatus::MTLCommandBufferStatusScheduled) {
// Waiting the background rendering's completion to prevent os-x app crashes on some MacBooks.
[_mtlCommandBuffer waitUntilCompleted];
}

[_mtlCommandBuffer release];
_mtlCommandBuffer = nil;
return;
}
dispatch_semaphore_signal(_frameBoundarySemaphore);
}

Expand All @@ -227,6 +237,10 @@ inline int clamp(int value, int min, int max) {
_autoReleasePool = [[NSAutoreleasePool alloc] init];
dispatch_semaphore_wait(_frameBoundarySemaphore, DISPATCH_TIME_FOREVER);

if (_mtlCommandBuffer != nil) {
[_mtlCommandBuffer release];
}

_mtlCommandBuffer = [_mtlCommandQueue commandBuffer];
[_mtlCommandBuffer enqueue];
[_mtlCommandBuffer retain];
Expand Down Expand Up @@ -369,7 +383,8 @@ inline int clamp(int value, int min, int max) {
}];

[_mtlCommandBuffer commit];
[_mtlCommandBuffer release];
// _mtlCommandBuffer will be released at the beginning of the next frame
// @see CommandBufferMTL::beginFrame
DeviceMTL::resetCurrentDrawable();
[_autoReleasePool drain];
}
Expand Down