diff --git a/iosx/src/flowmgr/AVSVideoView_Metal.mm b/iosx/src/flowmgr/AVSVideoView_Metal.mm index 2da4e21e8..86d95183f 100644 --- a/iosx/src/flowmgr/AVSVideoView_Metal.mm +++ b/iosx/src/flowmgr/AVSVideoView_Metal.mm @@ -317,15 +317,22 @@ - (void)render:(CADisplayLink*)displayLink } [_lock unlock]; - id commandBuffer = [_commandQueue commandBuffer]; - commandBuffer.label = @"AVSCommandBuffer"; - + __block dispatch_semaphore_t blockSem = _gpuSemaphore; + + if (!_renderPassDescriptor || _viewFrame.size.width == 0 || _viewFrame.size.height == 0) { + dispatch_semaphore_signal(blockSem); + return; + } + id currentDrawable = [_metalLayer nextDrawable]; if (!currentDrawable) { + dispatch_semaphore_signal(blockSem); return; } - __block dispatch_semaphore_t blockSem = _gpuSemaphore; + id commandBuffer = [_commandQueue commandBuffer]; + + commandBuffer.label = @"AVSCommandBuffer"; [commandBuffer addCompletedHandler:^(id _Nonnull) { // GPU work has completed. [_lock lock]; @@ -335,33 +342,30 @@ - (void)render:(CADisplayLink*)displayLink dispatch_semaphore_signal(blockSem); }]; - if (_renderPassDescriptor) { - _renderPassDescriptor.colorAttachments[0].texture = currentDrawable.texture; + _renderPassDescriptor.colorAttachments[0].texture = currentDrawable.texture; - id renderEncoder = - [commandBuffer renderCommandEncoderWithDescriptor:_renderPassDescriptor]; - renderEncoder.label = @"AVSEncoder"; - - // Set context state. - //[renderEncoder pushDebugGroup:renderEncoderDebugGroup]; - [renderEncoder setRenderPipelineState:_pipelineState]; - [renderEncoder setVertexBuffer:_vertexBuffer offset:0 atIndex:0]; - - [renderEncoder setFragmentTexture:_yTexture atIndex:0]; - [renderEncoder setFragmentTexture:_uTexture atIndex:1]; - [renderEncoder setFragmentTexture:_vTexture atIndex:2]; - - [renderEncoder drawPrimitives:MTLPrimitiveTypeTriangleStrip - vertexStart:0 - vertexCount:4 - instanceCount:1]; + id renderEncoder = + [commandBuffer renderCommandEncoderWithDescriptor:_renderPassDescriptor]; + renderEncoder.label = @"AVSEncoder"; + + // Set context state. + //[renderEncoder pushDebugGroup:renderEncoderDebugGroup]; + [renderEncoder setRenderPipelineState:_pipelineState]; + [renderEncoder setVertexBuffer:_vertexBuffer offset:0 atIndex:0]; + + [renderEncoder setFragmentTexture:_yTexture atIndex:0]; + [renderEncoder setFragmentTexture:_uTexture atIndex:1]; + [renderEncoder setFragmentTexture:_vTexture atIndex:2]; + + [renderEncoder drawPrimitives:MTLPrimitiveTypeTriangleStrip + vertexStart:0 + vertexCount:4 + instanceCount:1]; - //[renderEncoder popDebugGroup]; - [renderEncoder endEncoding]; - - [commandBuffer presentDrawable:currentDrawable]; - } + //[renderEncoder popDebugGroup]; + [renderEncoder endEncoding]; + [commandBuffer presentDrawable:currentDrawable]; [commandBuffer commit]; } @@ -402,7 +406,7 @@ - (void)startRunning - (void)stopRunning { _running = NO; - [_displayLink removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; + [_displayLink invalidate]; _displayLink = nil; }