JBR-4710 macOS: SIGSEGV at sun.java2d.metal.MTLLayer.blitTexture

Added check for disposed texture in the MTLLayer

(cherry picked from commit c27d8a7c5e)
This commit is contained in:
Alexey Ushakov
2022-10-13 16:28:30 +02:00
committed by jbrbot
parent d874d21970
commit aab6ff25b1
2 changed files with 13 additions and 10 deletions

View File

@@ -39,7 +39,7 @@
MTLContext* ctx;
float bufferWidth;
float bufferHeight;
id<MTLTexture> buffer;
id<MTLTexture>* buffer;
int nextDrawableCount;
int topInset;
int leftInset;
@@ -50,7 +50,7 @@
@property (readwrite, assign) MTLContext* ctx;
@property (readwrite, assign) float bufferWidth;
@property (readwrite, assign) float bufferHeight;
@property (readwrite, assign) id<MTLTexture> buffer;
@property (readwrite, assign) id<MTLTexture>* buffer;
@property (readwrite, assign) int nextDrawableCount;
@property (readwrite, assign) int topInset;
@property (readwrite, assign) int leftInset;

View File

@@ -113,7 +113,9 @@
}
- (void) blitTexture {
if (self.ctx == NULL || self.javaLayer == NULL || self.buffer == nil || self.ctx.device == nil) {
if (self.ctx == NULL || self.javaLayer == NULL || self.buffer == NULL || *self.buffer == nil ||
self.ctx.device == nil)
{
J2dTraceLn4(J2D_TRACE_VERBOSE,
"MTLLayer.blitTexture: uninitialized (mtlc=%p, javaLayer=%p, buffer=%p, device=%p)", self.ctx,
self.javaLayer, self.buffer, ctx.device);
@@ -125,7 +127,7 @@
return;
}
@autoreleasepool {
if ((self.buffer.width == 0) || (self.buffer.height == 0)) {
if (((*self.buffer).width == 0) || ((*self.buffer).height == 0)) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: cannot create drawable of size 0");
[self stopDisplayLink];
return;
@@ -133,8 +135,8 @@
NSUInteger src_x = self.leftInset * self.contentsScale;
NSUInteger src_y = self.topInset * self.contentsScale;
NSUInteger src_w = self.buffer.width - src_x;
NSUInteger src_h = self.buffer.height - src_y;
NSUInteger src_w = (*self.buffer).width - src_x;
NSUInteger src_h = (*self.buffer).height - src_y;
if (src_h <= 0 || src_w <= 0) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: Invalid src width or height.");
@@ -159,7 +161,7 @@
id <MTLBlitCommandEncoder> blitEncoder = [commandBuf blitCommandEncoder];
[blitEncoder
copyFromTexture:self.buffer sourceSlice:0 sourceLevel:0
copyFromTexture:(*self.buffer) sourceSlice:0 sourceLevel:0
sourceOrigin:MTLOriginMake(src_x, src_y, 0)
sourceSize:MTLSizeMake(src_w, src_h, 1)
toTexture:mtlDrawable.texture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(0, 0, 0)];
@@ -189,6 +191,7 @@
[self stopDisplayLink];
CVDisplayLinkRelease(self.displayLink);
self.displayLink = nil;
self.buffer = NULL;
[super dealloc];
}
@@ -283,13 +286,13 @@ Java_sun_java2d_metal_MTLLayer_validate
BMTLSDOps *bmtlsdo = (BMTLSDOps*) SurfaceData_GetOps(env, surfaceData);
layer.bufferWidth = bmtlsdo->width;
layer.bufferHeight = bmtlsdo->width;
layer.buffer = bmtlsdo->pTexture;
layer.buffer = &bmtlsdo->pTexture;
layer.ctx = ((MTLSDOps *)bmtlsdo->privOps)->configInfo->context;
layer.device = layer.ctx.device;
layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
layer.drawableSize =
CGSizeMake(layer.buffer.width,
layer.buffer.height);
CGSizeMake((*layer.buffer).width,
(*layer.buffer).height);
[layer startDisplayLink];
} else {
layer.ctx = NULL;