@@ -421,9 +421,11 @@ struct VideoMetal : VideoDriver, Metal {
421
421
422
422
id<CAMetalDrawable> drawable = view.currentDrawable ;
423
423
424
+ __block VideoMetal &strongSelf = self;
425
+
424
426
if (@available (macOS 10.15.4 , *)) {
425
427
[drawable addPresentedHandler:^(id<MTLDrawable> drawable) {
426
- self .drawableWasPresented (drawable);
428
+ strongSelf .drawableWasPresented (drawable);
427
429
depth--;
428
430
}];
429
431
}
@@ -599,31 +601,35 @@ struct VideoMetal : VideoDriver, Metal {
599
601
}
600
602
601
603
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;
604
+ if (_renderQueue) {
605
+ dispatch_sync (_renderQueue, ^{
606
+ _ready = false ;
607
+
608
+ _commandQueue = nullptr ;
609
+ _library = nullptr ;
610
+
611
+ _vertexBuffer = nullptr ;
612
+ for (int i = 0 ; i < kMaxSourceBuffersInFlight ; i++) {
613
+ _sourceTextures[i] = nullptr ;
614
+ }
615
+ _mtlVertexDescriptor = nullptr ;
616
+
617
+ _renderToTextureRenderPassDescriptor = nullptr ;
618
+ _renderTargetTexture = nullptr ;
619
+ _renderToTextureRenderPipeline = nullptr ;
620
+
621
+ _drawableRenderPipeline = nullptr ;
622
+
623
+ if (_filterChain) {
624
+ _libra.mtl_filter_chain_free (&_filterChain);
625
+ }
626
+ _device = nullptr ;
627
+
628
+ if (view) {
629
+ [view removeFromSuperview];
630
+ view = nil;
631
+ }
632
+ });
627
633
}
628
634
}
629
635
0 commit comments