From 3e07a0712fdb54c208970fd8758cd8c5d8b51306 Mon Sep 17 00:00:00 2001 From: Charles Wang Date: Sun, 8 Sep 2019 13:40:38 -0500 Subject: [PATCH] Update SGVideoRenderer.m Fix video replacing crash in background --- SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m b/SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m index 5d887ceb..3e4c3138 100644 --- a/SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m +++ b/SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m @@ -395,7 +395,13 @@ - (void)drawInMTKView:(MTKView *)view } MTLViewport viewports[2] = {}; NSArray *projections = nil; - id drawable = [(CAMetalLayer *)self->_metalView.layer nextDrawable]; + CAMetalLayer *layer = (CAMetalLayer *)self->_metalView.layer; + + if (layer.drawableSize.width == 0 || layer.drawableSize.height == 0) { + return; + } + + id drawable = [layer nextDrawable]; MTLSize textureSize = MTLSizeMake(width, height, 0); MTLSize layerSize = MTLSizeMake(drawable.texture.width, drawable.texture.height, 0); switch (displayMode) {