mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 10:42:42 +01:00
internal/atlas: bug fix: (*Image).Deallocate (*Shader).Deallocate were not concurrent-safe
Updates #2162
This commit is contained in:
parent
bdd8916bb1
commit
8a44ef4f6c
@ -547,6 +547,14 @@ func (i *Image) MarkDisposed() {
|
|||||||
backendsM.Lock()
|
backendsM.Lock()
|
||||||
defer backendsM.Unlock()
|
defer backendsM.Unlock()
|
||||||
|
|
||||||
|
if !inFrame {
|
||||||
|
appendDeferred(func() {
|
||||||
|
i.deallocate()
|
||||||
|
runtime.SetFinalizer(i, nil)
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
i.deallocate()
|
i.deallocate()
|
||||||
runtime.SetFinalizer(i, nil)
|
runtime.SetFinalizer(i, nil)
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,16 @@ func (s *Shader) ensureShader() *restorable.Shader {
|
|||||||
|
|
||||||
// Deallocate deallocates the internal state.
|
// Deallocate deallocates the internal state.
|
||||||
func (s *Shader) Deallocate() {
|
func (s *Shader) Deallocate() {
|
||||||
|
backendsM.Lock()
|
||||||
|
defer backendsM.Unlock()
|
||||||
|
|
||||||
|
if !inFrame {
|
||||||
|
appendDeferred(func() {
|
||||||
|
s.deallocate()
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
s.deallocate()
|
s.deallocate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
internal/processtest/testdata/issue1753.go
vendored
4
internal/processtest/testdata/issue1753.go
vendored
@ -56,10 +56,10 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
|||||||
return fmt.Errorf("phase: %d, got: %v, want: %v", g.phase, got, want)
|
return fmt.Errorf("phase: %d, got: %v, want: %v", g.phase, got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispose the shader. When a new shader is created in the next phase, the underlying shader ID might be reused.
|
// Deallocate the shader. When a new shader is created in the next phase, the underlying shader ID might be reused.
|
||||||
// This test checks that the new shader works in this situation.
|
// This test checks that the new shader works in this situation.
|
||||||
// The actual disposal will happen after this frame and before the next frame in the current implementation.
|
// The actual disposal will happen after this frame and before the next frame in the current implementation.
|
||||||
s.Dispose()
|
s.Deallocate()
|
||||||
|
|
||||||
g.phase++
|
g.phase++
|
||||||
|
|
||||||
|
2
internal/processtest/testdata/issue2129.go
vendored
2
internal/processtest/testdata/issue2129.go
vendored
@ -41,7 +41,7 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
s.Dispose()
|
s.Deallocate()
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
2
internal/processtest/testdata/issue2162.go
vendored
2
internal/processtest/testdata/issue2162.go
vendored
@ -28,7 +28,7 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
s.Dispose()
|
s.Deallocate()
|
||||||
}
|
}
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user