From 48ba111cccdf93fedbb341cb5a8602e88a4812af Mon Sep 17 00:00:00 2001 From: Ben Doherty Date: Mon, 10 Feb 2020 10:34:44 -0800 Subject: [PATCH] Fix crash in Metal backend with screen-space refractions (#2104) --- filament/backend/src/metal/MetalDriver.mm | 3 +++ filament/backend/src/metal/MetalHandles.mm | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/filament/backend/src/metal/MetalDriver.mm b/filament/backend/src/metal/MetalDriver.mm index dc7ab1b757..9705d7d433 100644 --- a/filament/backend/src/metal/MetalDriver.mm +++ b/filament/backend/src/metal/MetalDriver.mm @@ -850,6 +850,9 @@ void MetalDriver::blit(TargetBufferFlags buffers, id srcTexture = srcTarget->getBlitColorSource(); id dstTexture = dstTarget->getColor(); + ASSERT_PRECONDITION(srcTexture != nil && dstTexture != nil, + "Source texture and destination texture must not be nil"); + // Metal's texture coordinates have (0, 0) at the top-left of the texture, but Filament's // coordinates have (0, 0) at bottom-left. MTLRegion srcRegion = MTLRegionMake2D( diff --git a/filament/backend/src/metal/MetalHandles.mm b/filament/backend/src/metal/MetalHandles.mm index e64bd0ad87..31b452dffa 100644 --- a/filament/backend/src/metal/MetalHandles.mm +++ b/filament/backend/src/metal/MetalHandles.mm @@ -441,6 +441,9 @@ id MetalRenderTarget::getDepthResolve() { } id MetalRenderTarget::getBlitColorSource() { + if (defaultRenderTarget) { + return acquireDrawable(context); + } if (color) { return color; } @@ -448,6 +451,9 @@ id MetalRenderTarget::getBlitColorSource() { } id MetalRenderTarget::getBlitDepthSource() { + if (defaultRenderTarget) { + return acquireDepthTexture(context); + } if (depth) { return depth; }