From 66e635d755ade763a5987a843d7e32cfc8292e15 Mon Sep 17 00:00:00 2001 From: Ronie Salgado Date: Mon, 9 Dec 2019 16:53:23 -0300 Subject: [PATCH] This fixed an edge condition with the metal renderer where the update rect ends out of the bounds of the display texture. --- platforms/iOS/vm/OSX/sqSqueakOSXMetalView.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/platforms/iOS/vm/OSX/sqSqueakOSXMetalView.m b/platforms/iOS/vm/OSX/sqSqueakOSXMetalView.m index ecfe91068b..2bf3661944 100644 --- a/platforms/iOS/vm/OSX/sqSqueakOSXMetalView.m +++ b/platforms/iOS/vm/OSX/sqSqueakOSXMetalView.m @@ -379,9 +379,19 @@ - (void)loadTexturesFrom: (void*) displayStorage subRectangle: (NSRect) subRect [self updateDisplayTextureStorage]; } + // Clip the subrect against the texture bounds, to avoid an edge condition + // that ends crashing the VM. + subRect = NSIntersectionRect(subRect, NSMakeRect(0, 0, displayTextureWidth, displayTextureHeight)); + if(NSIsEmptyRect(subRect)) + { + // Discard the update of empty texture regions. + return; + } + MTLRegion region = MTLRegionMake2D(subRect.origin.x, displayTextureHeight - subRect.origin.y - subRect.size.height, subRect.size.width, subRect.size.height); unsigned int sourcePitch = displayTextureWidth*4; + //char *source = ((char*)displayStorage) + (unsigned int)(subRect.origin.x + subRect.origin.y*displayTextureWidth)*4; char *source = ((char*)displayStorage) + (unsigned int)(subRect.origin.x + (displayTextureHeight-subRect.origin.y-subRect.size.height)*displayTextureWidth)*4; [displayTexture replaceRegion: region mipmapLevel: 0 withBytes: source bytesPerRow: sourcePitch];