internal/atlas: check overflows

This commit is contained in:
Hajime Hoshi 2023-08-06 13:46:41 +09:00
parent 1ae5e022b6
commit a50d9e6291

View File

@ -17,6 +17,7 @@ package atlas
import (
"fmt"
"image"
"math"
"runtime"
"sync"
@ -66,12 +67,16 @@ const baseCountToPutOnSourceBackend = 10
func putImagesOnSourceBackend(graphicsDriver graphicsdriver.Graphics) error {
// The counter usedAsDestinationCount is updated at most once per frame (#2676).
for i := range imagesUsedAsDestination {
i.usedAsDestinationCount++
if i.usedAsDestinationCount < math.MaxInt {
i.usedAsDestinationCount++
}
delete(imagesUsedAsDestination, i)
}
for i := range imagesToPutOnSourceBackend {
i.usedAsSourceCount++
if i.usedAsSourceCount < math.MaxInt {
i.usedAsSourceCount++
}
if i.usedAsSourceCount >= baseCountToPutOnSourceBackend*(1<<uint(min(i.usedAsDestinationCount, 31))) {
if err := i.putOnSourceBackend(graphicsDriver); err != nil {
return err