mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
restorable: Bug fix: Make limit to the number of draw-image command history (#349)
This commit is contained in:
parent
e8b155fefe
commit
d94e9c9d86
2
image.go
2
image.go
@ -72,7 +72,7 @@ func (i *images) resolveStalePixels(context *opengl.Context) error {
|
||||
defer i.m.Unlock()
|
||||
i.lastChecked = nil
|
||||
for img := range i.images {
|
||||
if err := img.ReadPixelsFromVRAMIfStale(context); err != nil {
|
||||
if err := img.ResolveStalePixels(context); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||
)
|
||||
|
||||
const drawImageHistoryMax = 100
|
||||
|
||||
type drawImageHistoryItem struct {
|
||||
image *Image
|
||||
vertices []float32
|
||||
@ -129,6 +131,10 @@ func (p *Image) appendDrawImageHistory(image *Image, vertices []float32, colorm
|
||||
if p.stale {
|
||||
return
|
||||
}
|
||||
if len(p.drawImageHistory)+1 > drawImageHistoryMax {
|
||||
p.makeStale()
|
||||
return
|
||||
}
|
||||
// All images must be resolved and not stale each after frame.
|
||||
// So we don't have to care if image is stale or not here.
|
||||
item := &drawImageHistoryItem{
|
||||
@ -164,7 +170,6 @@ func (p *Image) MakeStaleIfDependingOn(target *Image) {
|
||||
if p.stale {
|
||||
return
|
||||
}
|
||||
// TODO: Performance is bad when drawImageHistory is too many.
|
||||
for _, c := range p.drawImageHistory {
|
||||
if c.image == target {
|
||||
p.makeStale()
|
||||
@ -185,7 +190,7 @@ func (p *Image) readPixelsFromVRAM(image *graphics.Image, context *opengl.Contex
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Image) ReadPixelsFromVRAMIfStale(context *opengl.Context) error {
|
||||
func (p *Image) ResolveStalePixels(context *opengl.Context) error {
|
||||
if p.volatile {
|
||||
return nil
|
||||
}
|
||||
@ -199,7 +204,7 @@ func (p *Image) HasDependency() bool {
|
||||
if p.stale {
|
||||
return false
|
||||
}
|
||||
return p.drawImageHistory != nil
|
||||
return len(p.drawImageHistory) > 0
|
||||
}
|
||||
|
||||
// Restore restores *graphics.Image from the pixels using its state.
|
||||
|
Loading…
Reference in New Issue
Block a user