Skip to content

Commit

Permalink
Fixed SDL Texture deadlock
Browse files Browse the repository at this point in the history
Need to make sure to unlock always after locking
  • Loading branch information
colemancda committed Nov 18, 2017
1 parent 086e738 commit 10688a8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Sources/SDL/Texture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 10688a8

Please sign in to comment.