buffered: Bug fix: Race condition at checkDealeydCommandsNil

This change also renames checkDealeydCommandsNil to
checkDealeydCommandsFlushed, which makes more sense.

Updates #1195
This commit is contained in:
Hajime Hoshi 2020-06-17 03:19:31 +09:00
parent 2869885816
commit 0beddf5519
2 changed files with 4 additions and 4 deletions

View File

@ -89,8 +89,8 @@ func tryAddDelayedCommandSlow(f func(obj interface{}) error, ondelayed func() in
}
}
func checkDelayedCommandsNil(fname string) {
if delayedCommands != nil {
func checkDelayedCommandsFlushed(fname string) {
if atomic.LoadUint32(&delayedCommandsFlushed) == 0 {
panic("buffered: the command queue is not available yet at " + fname)
}
}

View File

@ -125,7 +125,7 @@ func (i *Image) MarkDisposed() {
}
func (img *Image) Pixels(x, y, width, height int) (pix []byte, err error) {
checkDelayedCommandsNil("Pixels")
checkDelayedCommandsFlushed("Pixels")
if !image.Rect(x, y, x+width, y+height).In(image.Rect(0, 0, img.width, img.height)) {
return nil, fmt.Errorf("buffered: out of range")
@ -160,7 +160,7 @@ func (img *Image) Pixels(x, y, width, height int) (pix []byte, err error) {
}
func (i *Image) Dump(name string, blackbg bool) error {
checkDelayedCommandsNil("Dump")
checkDelayedCommandsFlushed("Dump")
return i.img.Dump(name, blackbg)
}