mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 10:42:42 +01:00
shareable: Bug fix: mutex should not be used at finalizers
Updates #913
This commit is contained in:
parent
28dd2f6e19
commit
cbf36734f8
@ -56,10 +56,8 @@ var theImages = &images{
|
||||
//
|
||||
// ResolveStaleImages is intended to be called at the end of a frame.
|
||||
func ResolveStaleImages() {
|
||||
defer func() {
|
||||
// Until the begin o the frame (by RestoreIfNeeded, any operations are deferred.
|
||||
theImages.m.Lock()
|
||||
}()
|
||||
// Until the begin o the frame (by RestoreIfNeeded, any operations are locked.
|
||||
defer theImages.m.Lock()
|
||||
|
||||
graphicscommand.FlushCommands()
|
||||
if !needsRestoring() {
|
||||
|
@ -73,9 +73,6 @@ func init() {
|
||||
}
|
||||
|
||||
func resolveDeferred() {
|
||||
deferredM.Lock()
|
||||
defer deferredM.Unlock()
|
||||
|
||||
for _, f := range deferred {
|
||||
f()
|
||||
}
|
||||
@ -151,8 +148,7 @@ var (
|
||||
|
||||
imagesToMakeShared = map[*Image]struct{}{}
|
||||
|
||||
deferred []func()
|
||||
deferredM sync.Mutex
|
||||
deferred []func()
|
||||
)
|
||||
|
||||
// isShareable reports whether the new allocation can use the shareable backends.
|
||||
@ -388,9 +384,7 @@ func (i *Image) at(x, y int) (byte, byte, byte, byte) {
|
||||
// A function from finalizer must not be blocked, but disposing operation can be blocked.
|
||||
// Defer this operation until it becomes safe. (#913)
|
||||
func (i *Image) disposeFromFinalizer() {
|
||||
deferredM.Lock()
|
||||
defer deferredM.Unlock()
|
||||
|
||||
// deferred doesn't have to be, and should not be protected by a mutex.
|
||||
deferred = append(deferred, func() {
|
||||
i.dispose(true)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user