Fix issues with integer overflow in memory pressure calculations

This commit is contained in:
Dale Glass 2020-10-18 22:13:28 +02:00
parent 0d4987878e
commit 7a186bba34

View file

@ -239,13 +239,16 @@ void GLTextureTransferEngineDefault::updateMemoryPressure() {
float pressure = 0; float pressure = 0;
if (useAvailableGlMemory) { if (useAvailableGlMemory) {
float totalMem = GLBackend::getTotalMemory(); size_t totalMem = GLBackend::getTotalMemory();
float availMem = GLBackend::getAvailableMemory() - AUTO_RESERVE_TEXTURE_MEMORY; size_t availMem = GLBackend::getAvailableMemory();
if (availMem < 0) {
if (availMem >= AUTO_RESERVE_TEXTURE_MEMORY) {
availMem -= AUTO_RESERVE_TEXTURE_MEMORY;
} else {
availMem = 0; availMem = 0;
} }
pressure = (totalMem - availMem) / totalMem; pressure = ((float)totalMem - (float)availMem) / (float)totalMem;
} else { } else {
pressure = (float)totalVariableMemoryAllocation / (float)allowedMemoryAllocation; pressure = (float)totalVariableMemoryAllocation / (float)allowedMemoryAllocation;
} }