mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +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.
|
// ResolveStaleImages is intended to be called at the end of a frame.
|
||||||
func ResolveStaleImages() {
|
func ResolveStaleImages() {
|
||||||
defer func() {
|
// Until the begin o the frame (by RestoreIfNeeded, any operations are locked.
|
||||||
// Until the begin o the frame (by RestoreIfNeeded, any operations are deferred.
|
defer theImages.m.Lock()
|
||||||
theImages.m.Lock()
|
|
||||||
}()
|
|
||||||
|
|
||||||
graphicscommand.FlushCommands()
|
graphicscommand.FlushCommands()
|
||||||
if !needsRestoring() {
|
if !needsRestoring() {
|
||||||
|
@ -73,9 +73,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resolveDeferred() {
|
func resolveDeferred() {
|
||||||
deferredM.Lock()
|
|
||||||
defer deferredM.Unlock()
|
|
||||||
|
|
||||||
for _, f := range deferred {
|
for _, f := range deferred {
|
||||||
f()
|
f()
|
||||||
}
|
}
|
||||||
@ -151,8 +148,7 @@ var (
|
|||||||
|
|
||||||
imagesToMakeShared = map[*Image]struct{}{}
|
imagesToMakeShared = map[*Image]struct{}{}
|
||||||
|
|
||||||
deferred []func()
|
deferred []func()
|
||||||
deferredM sync.Mutex
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// isShareable reports whether the new allocation can use the shareable backends.
|
// 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.
|
// A function from finalizer must not be blocked, but disposing operation can be blocked.
|
||||||
// Defer this operation until it becomes safe. (#913)
|
// Defer this operation until it becomes safe. (#913)
|
||||||
func (i *Image) disposeFromFinalizer() {
|
func (i *Image) disposeFromFinalizer() {
|
||||||
deferredM.Lock()
|
// deferred doesn't have to be, and should not be protected by a mutex.
|
||||||
defer deferredM.Unlock()
|
|
||||||
|
|
||||||
deferred = append(deferred, func() {
|
deferred = append(deferred, func() {
|
||||||
i.dispose(true)
|
i.dispose(true)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user