From 7a921e03da84e30492a0ffc6c09fdc576fd66482 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 19 Oct 2023 02:04:21 +0900 Subject: [PATCH] internal/atlas: bug fix: inFrame was not correctly updated Updates #2814 --- internal/atlas/image.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/atlas/image.go b/internal/atlas/image.go index 8dae46c81..8872cffab 100644 --- a/internal/atlas/image.go +++ b/internal/atlas/image.go @@ -742,7 +742,7 @@ func (i *Image) DumpScreenshot(graphicsDriver graphicsdriver.Graphics, path stri defer backendsM.Unlock() 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)) @@ -752,9 +752,13 @@ func EndFrame(graphicsDriver graphicsdriver.Graphics, swapBuffersForGL func()) e backendsM.Lock() defer backendsM.Unlock() defer func() { - inFrame = true + inFrame = false }() + if !inFrame { + panic("atlas: inFrame must be true in EndFrame") + } + if err := restorable.EndFrame(graphicsDriver, swapBuffersForGL); err != nil { return err } @@ -780,6 +784,11 @@ func floorPowerOf2(x int) int { func BeginFrame(graphicsDriver graphicsdriver.Graphics) error { backendsM.Lock() defer backendsM.Unlock() + + if inFrame { + panic("atlas: inFrame must be false in BeginFrame") + } + inFrame = true var err error @@ -821,5 +830,10 @@ func BeginFrame(graphicsDriver graphicsdriver.Graphics) error { func DumpImages(graphicsDriver graphicsdriver.Graphics, dir string) (string, error) { backendsM.Lock() defer backendsM.Unlock() + + if !inFrame { + panic("atlas: DumpImages must be called in between BeginFrame and EndFrame") + } + return restorable.DumpImages(graphicsDriver, dir) }