Skip to content

Commit

Permalink
Merge pull request #453 from ronsaldo/bug/metal-window-resize-crash
Browse files Browse the repository at this point in the history
Fix Metal window crash on resize.
  • Loading branch information
eliotmiranda committed Dec 9, 2019
2 parents a71f633 + 66e635d commit 321f398
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions platforms/iOS/vm/OSX/sqSqueakOSXMetalView.m
Expand Up @@ -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];
Expand Down

0 comments on commit 321f398

Please sign in to comment.