Skip to content

Commit b31f4dc

Browse files
authored
Remove Surface caching in the Apple graphics context (#5267)
Benchmarks crash due to the attempt to use a cached scene that was closed in the previous benchmark. Create a Surface for each of the benchmarks instead. ## Testing Testing was done manually. ## Release Notes N/A
1 parent 022644a commit b31f4dc

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

benchmarks/multiplatform/benchmarks/src/appleMain/kotlin/GraphicsContext.apple.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,8 @@ fun graphicsContext() = object : GraphicsContext {
2323
private val device = MTLCreateSystemDefaultDevice() ?: throw IllegalStateException("Can't create MTLDevice")
2424
private val commandQueue = device.newCommandQueue() ?: throw IllegalStateException("Can't create MTLCommandQueue")
2525
private val directContext = DirectContext.makeMetal(device.objcPtr(), commandQueue.objcPtr())
26-
private var cachedSurface: Surface? = null
2726

2827
override fun surface(width: Int, height: Int): Surface {
29-
val oldSurface = cachedSurface
30-
31-
if (oldSurface != null && oldSurface.width == width && oldSurface.height == height) {
32-
return oldSurface
33-
}
34-
3528
val descriptor = MTLTextureDescriptor()
3629
descriptor.width = width.toULong()
3730
descriptor.height = height.toULong()
@@ -51,9 +44,7 @@ fun graphicsContext() = object : GraphicsContext {
5144
SurfaceColorFormat.BGRA_8888,
5245
ColorSpace.sRGB,
5346
SurfaceProps(pixelGeometry = PixelGeometry.UNKNOWN)
54-
).also {
55-
cachedSurface = it
56-
} ?: throw IllegalStateException("Can't create Surface")
47+
) ?: throw IllegalStateException("Can't create Surface")
5748
}
5849

5950
override suspend fun awaitGPUCompletion() {

0 commit comments

Comments
 (0)