Skip to content

Commit 0bda329

Browse files
committed
Fix potential race in Metal on exit
1 parent f7ab0b9 commit 0bda329

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

Diff for: hiro/cocoa/widget/label.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ auto pLabel::setForegroundColor(SystemColor color) -> void {
161161
}
162162

163163
auto pLabel::setText(const string& text) -> void {
164-
dispatch_async(dispatch_get_main_queue(), ^{
165-
[cocoaView setNeedsDisplay:YES];
166-
});
164+
[cocoaView setNeedsDisplay:YES];
167165
}
168166

169167
}

Diff for: ruby/video/metal/metal.cpp

+29-25
Original file line numberDiff line numberDiff line change
@@ -599,31 +599,35 @@ struct VideoMetal : VideoDriver, Metal {
599599
}
600600

601601
auto terminate() -> void {
602-
_ready = false;
603-
604-
_commandQueue = nullptr;
605-
_library = nullptr;
606-
607-
_vertexBuffer = nullptr;
608-
for (int i = 0; i < kMaxSourceBuffersInFlight; i++) {
609-
_sourceTextures[i] = nullptr;
610-
}
611-
_mtlVertexDescriptor = nullptr;
612-
613-
_renderToTextureRenderPassDescriptor = nullptr;
614-
_renderTargetTexture = nullptr;
615-
_renderToTextureRenderPipeline = nullptr;
616-
617-
_drawableRenderPipeline = nullptr;
618-
619-
if (_filterChain) {
620-
_libra.mtl_filter_chain_free(&_filterChain);
621-
}
622-
_device = nullptr;
623-
624-
if (view) {
625-
[view removeFromSuperview];
626-
view = nil;
602+
if(_renderQueue) {
603+
dispatch_sync(_renderQueue, ^{
604+
_ready = false;
605+
606+
_commandQueue = nullptr;
607+
_library = nullptr;
608+
609+
_vertexBuffer = nullptr;
610+
for (int i = 0; i < kMaxSourceBuffersInFlight; i++) {
611+
_sourceTextures[i] = nullptr;
612+
}
613+
_mtlVertexDescriptor = nullptr;
614+
615+
_renderToTextureRenderPassDescriptor = nullptr;
616+
_renderTargetTexture = nullptr;
617+
_renderToTextureRenderPipeline = nullptr;
618+
619+
_drawableRenderPipeline = nullptr;
620+
621+
if (_filterChain) {
622+
_libra.mtl_filter_chain_free(&_filterChain);
623+
}
624+
_device = nullptr;
625+
626+
if (view) {
627+
[view removeFromSuperview];
628+
view = nil;
629+
}
630+
});
627631
}
628632
}
629633

0 commit comments

Comments
 (0)