internal/atlas: bug fix: inFrame was not correctly updated

Updates #2814
This commit is contained in:
Hajime Hoshi 2023-10-19 02:04:21 +09:00
parent 7d517bfb63
commit 7a921e03da

View File

@ -742,7 +742,7 @@ func (i *Image) DumpScreenshot(graphicsDriver graphicsdriver.Graphics, path stri
defer backendsM.Unlock() defer backendsM.Unlock()
if !inFrame { if !inFrame {
panic("atlas: ReadPixels must be called in between BeginFrame and EndFrame") panic("atlas: DumpScreenshots must be called in between BeginFrame and EndFrame")
} }
return i.backend.restorable.Dump(graphicsDriver, path, blackbg, image.Rect(0, 0, i.width, i.height)) return i.backend.restorable.Dump(graphicsDriver, path, blackbg, image.Rect(0, 0, i.width, i.height))
@ -752,9 +752,13 @@ func EndFrame(graphicsDriver graphicsdriver.Graphics, swapBuffersForGL func()) e
backendsM.Lock() backendsM.Lock()
defer backendsM.Unlock() defer backendsM.Unlock()
defer func() { defer func() {
inFrame = true inFrame = false
}() }()
if !inFrame {
panic("atlas: inFrame must be true in EndFrame")
}
if err := restorable.EndFrame(graphicsDriver, swapBuffersForGL); err != nil { if err := restorable.EndFrame(graphicsDriver, swapBuffersForGL); err != nil {
return err return err
} }
@ -780,6 +784,11 @@ func floorPowerOf2(x int) int {
func BeginFrame(graphicsDriver graphicsdriver.Graphics) error { func BeginFrame(graphicsDriver graphicsdriver.Graphics) error {
backendsM.Lock() backendsM.Lock()
defer backendsM.Unlock() defer backendsM.Unlock()
if inFrame {
panic("atlas: inFrame must be false in BeginFrame")
}
inFrame = true inFrame = true
var err error var err error
@ -821,5 +830,10 @@ func BeginFrame(graphicsDriver graphicsdriver.Graphics) error {
func DumpImages(graphicsDriver graphicsdriver.Graphics, dir string) (string, error) { func DumpImages(graphicsDriver graphicsdriver.Graphics, dir string) (string, error) {
backendsM.Lock() backendsM.Lock()
defer backendsM.Unlock() defer backendsM.Unlock()
if !inFrame {
panic("atlas: DumpImages must be called in between BeginFrame and EndFrame")
}
return restorable.DumpImages(graphicsDriver, dir) return restorable.DumpImages(graphicsDriver, dir)
} }