mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/graphicscommand: bug fix: IsInvalidated was not concurrent-safe
This function was not called actually, so this is not a real problem. However, this could be a potential problem for a future GLES driver (#292). Updates #292 Closes #2321
This commit is contained in:
parent
6ea455f4e1
commit
4824cbc755
@ -625,6 +625,20 @@ func (c *newShaderCommand) Exec(graphicsDriver graphicsdriver.Graphics, indexOff
|
||||
return nil
|
||||
}
|
||||
|
||||
type isInvalidatedCommand struct {
|
||||
result bool
|
||||
image *Image
|
||||
}
|
||||
|
||||
func (c *isInvalidatedCommand) String() string {
|
||||
return fmt.Sprintf("is-invalidated: image: %d", c.image.id)
|
||||
}
|
||||
|
||||
func (c *isInvalidatedCommand) Exec(graphicsDriver graphicsdriver.Graphics, indexOffset int) error {
|
||||
c.result = c.image.image.IsInvalidated()
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitializeGraphicsDriverState initialize the current graphics driver state.
|
||||
func InitializeGraphicsDriverState(graphicsDriver graphicsdriver.Graphics) (err error) {
|
||||
runOnRenderingThread(func() {
|
||||
|
@ -181,18 +181,26 @@ func (i *Image) WritePixels(pixels []byte, x, y, width, height int) {
|
||||
})
|
||||
}
|
||||
|
||||
func (i *Image) IsInvalidated() bool {
|
||||
func (i *Image) IsInvalidated(graphicsDriver graphicsdriver.Graphics) (bool, error) {
|
||||
if i.screen {
|
||||
// The screen image might not have a texture, and in this case it is impossible to detect whether
|
||||
// the image is invalidated or not.
|
||||
panic("graphicscommand: IsInvalidated cannot be called on the screen image")
|
||||
return false, fmt.Errorf("graphicscommand: IsInvalidated cannot be called on the screen image")
|
||||
}
|
||||
|
||||
// i.image can be nil before initializing.
|
||||
if i.image == nil {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
return i.image.IsInvalidated()
|
||||
|
||||
c := &isInvalidatedCommand{
|
||||
image: i,
|
||||
}
|
||||
theCommandQueue.Enqueue(c)
|
||||
if err := theCommandQueue.Flush(graphicsDriver); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return c.result, nil
|
||||
}
|
||||
|
||||
func (i *Image) dumpName(path string) string {
|
||||
|
@ -661,11 +661,8 @@ func (i *Image) Dispose() {
|
||||
//
|
||||
// If an image is invalidated, GL context is lost and all the images should be restored asap.
|
||||
func (i *Image) isInvalidated(graphicsDriver graphicsdriver.Graphics) (bool, error) {
|
||||
// FlushCommands is required because c.offscreen.impl might not have an actual texture.
|
||||
if err := graphicscommand.FlushCommands(graphicsDriver); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return i.image.IsInvalidated(), nil
|
||||
// IsInvalidated flushes the commands internally.
|
||||
return i.image.IsInvalidated(graphicsDriver)
|
||||
}
|
||||
|
||||
func (i *Image) Dump(graphicsDriver graphicsdriver.Graphics, path string, blackbg bool, rect image.Rectangle) (string, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user