From 10688a8b2975a34f555ae7d06dbf640a3d7a1373 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 18 Nov 2017 18:41:49 -0500 Subject: [PATCH] Fixed SDL Texture deadlock Need to make sure to unlock always after locking --- Sources/SDL/Texture.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/SDL/Texture.swift b/Sources/SDL/Texture.swift index 7e39596..5434c46 100644 --- a/Sources/SDL/Texture.swift +++ b/Sources/SDL/Texture.swift @@ -140,13 +140,15 @@ public final class Texture { var pixels: UnsafeMutableRawPointer? = nil - guard SDL_LockTexture(internalPointer, rectPointer, &pixels, &pitch) >= 0, - let pointer = pixels + guard SDL_LockTexture(internalPointer, rectPointer, &pixels, &pitch) >= 0 else { return nil } - let result = try body(pointer, Int(pitch)) + defer { SDL_UnlockTexture(internalPointer) } + + guard let pointer = pixels + else { return nil } - SDL_UnlockTexture(internalPointer) + let result = try body(pointer, Int(pitch)) return result }