Skip to content

Commit

Permalink
Releases old sample when setting a new one
Browse files Browse the repository at this point in the history
  • Loading branch information
ricobeck authored and finnvoor committed Apr 5, 2024
1 parent 7cd87c4 commit a66986b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/PlaydateKit/Core/Sound.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public enum Sound {
}

deinit {
if samplePointer != nil {
if let samplePointer {
sample.freeSample(samplePointer)
}
sampleplayer.freePlayer.unsafelyUnwrapped(playerPointer)
Expand All @@ -168,6 +168,9 @@ public enum Sound {

/// Assigns sample to player.
@discardableResult public func setSample(path: StaticString) -> Bool {
if let samplePointer {
sample.freeSample(samplePointer)
}
samplePointer = sample.load(path.utf8Start)
guard samplePointer != nil else { return false }

Expand All @@ -177,6 +180,10 @@ public enum Sound {

/// Assigns sample to player.
@discardableResult public func setSample(path: UnsafePointer<CChar>) -> Bool {
if let samplePointer {
sample.freeSample(samplePointer)
}

samplePointer = sample.load(path)
guard samplePointer != nil else { return false }

Expand Down

0 comments on commit a66986b

Please sign in to comment.