Fixed some wrapper lifetime and leak issues found in PlayDate bindings target.
This commit is contained in:
@@ -55,7 +55,12 @@ public final class Sprite {
|
||||
init(pointer: OpaquePointer, isOwned: Bool) {
|
||||
self.pointer = pointer
|
||||
self.isOwned = isOwned
|
||||
spriteAPI.pointee.setUserdata.unsafelyUnwrapped(pointer, Unmanaged.passUnretained(self).toOpaque())
|
||||
// Transient wrappers for sprites created outside the binding must not
|
||||
// store a back-reference: it would dangle once the wrapper is
|
||||
// deallocated, and only owned wrappers clear it in `deinit`.
|
||||
if isOwned {
|
||||
spriteAPI.pointee.setUserdata.unsafelyUnwrapped(pointer, Unmanaged.passUnretained(self).toOpaque())
|
||||
}
|
||||
}
|
||||
|
||||
/// Allocates a new sprite.
|
||||
|
||||
Reference in New Issue
Block a user