mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 19:22:49 +01:00
internal/atlas: check overflows
This commit is contained in:
parent
1ae5e022b6
commit
a50d9e6291
@ -17,6 +17,7 @@ package atlas
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
|
"math"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -66,12 +67,16 @@ const baseCountToPutOnSourceBackend = 10
|
|||||||
func putImagesOnSourceBackend(graphicsDriver graphicsdriver.Graphics) error {
|
func putImagesOnSourceBackend(graphicsDriver graphicsdriver.Graphics) error {
|
||||||
// The counter usedAsDestinationCount is updated at most once per frame (#2676).
|
// The counter usedAsDestinationCount is updated at most once per frame (#2676).
|
||||||
for i := range imagesUsedAsDestination {
|
for i := range imagesUsedAsDestination {
|
||||||
|
if i.usedAsDestinationCount < math.MaxInt {
|
||||||
i.usedAsDestinationCount++
|
i.usedAsDestinationCount++
|
||||||
|
}
|
||||||
delete(imagesUsedAsDestination, i)
|
delete(imagesUsedAsDestination, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range imagesToPutOnSourceBackend {
|
for i := range imagesToPutOnSourceBackend {
|
||||||
|
if i.usedAsSourceCount < math.MaxInt {
|
||||||
i.usedAsSourceCount++
|
i.usedAsSourceCount++
|
||||||
|
}
|
||||||
if i.usedAsSourceCount >= baseCountToPutOnSourceBackend*(1<<uint(min(i.usedAsDestinationCount, 31))) {
|
if i.usedAsSourceCount >= baseCountToPutOnSourceBackend*(1<<uint(min(i.usedAsDestinationCount, 31))) {
|
||||||
if err := i.putOnSourceBackend(graphicsDriver); err != nil {
|
if err := i.putOnSourceBackend(graphicsDriver); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user