Skip to content

Commit

Permalink
Fix Racing Condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakr233 committed Aug 16, 2024
1 parent bfbafcf commit 5d4b1a5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Sources/ColorfulX/AnimatedMulticolorGradientView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,17 @@ open class AnimatedMulticolorGradientView: MulticolorGradientView {

// MARK: - RENDER LIFE CYCLE

private let updateParametersLock = NSLock()

override public func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer)

// skip any vsync check and force an update
updateParametersLock.lock()
renderInputWasModified = true
updateRenderParameters(deltaTime: deltaTimeForRenderParametersUpdate())
renderIfNeeded()
}
updateParametersLock.unlock()

override func renderIfNeeded() {
super.renderIfNeeded()
renderIfNeeded()
}

override func render() {
Expand All @@ -159,7 +159,11 @@ open class AnimatedMulticolorGradientView: MulticolorGradientView {

override func vsync() {
guard shouldRenderNextFrameWithinSynchornization() else { return }

updateParametersLock.lock()
updateRenderParameters(deltaTime: deltaTimeForRenderParametersUpdate())
updateParametersLock.unlock()

// sine the render parameters were updated, we call super.vsync to render
super.vsync()
}
Expand Down

0 comments on commit 5d4b1a5

Please sign in to comment.