mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-02 14:04:28 +01:00
internal/restoring: bug fix: stop keeping pixel data on 32bit architecture
Updates #4259
This commit is contained in:
parent
a0a80bbc1f
commit
965fd4cac8
@ -446,6 +446,13 @@ func (i *Image) readPixelsFromGPUIfNeeded(graphicsDriver graphicsdriver.Graphics
|
||||
}
|
||||
|
||||
func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte, x, y, width, height int) error {
|
||||
if alwaysReadPixelsFromGPU() {
|
||||
if err := i.image.ReadPixels(graphicsDriver, pixels, x, y, width, height); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := i.readPixelsFromGPUIfNeeded(graphicsDriver); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ package restorable
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
||||
@ -32,6 +33,12 @@ func needsRestoring() bool {
|
||||
return forceRestoring || needsRestoringByGraphicsDriver
|
||||
}
|
||||
|
||||
// alwaysReadPixelsFromGPU reports whether ReadPixels alwasy reads pixels from GPU or not.
|
||||
// This is true for low-end machines like 32bit architecture without much memory.
|
||||
func alwaysReadPixelsFromGPU() bool {
|
||||
return !needsRestoring() && unsafe.Sizeof(uintptr(0)) < 8
|
||||
}
|
||||
|
||||
// EnableRestoringForTesting forces to enable restoring for testing.
|
||||
func EnableRestoringForTesting() {
|
||||
forceRestoring = true
|
||||
|
Loading…
Reference in New Issue
Block a user