From 7a186bba34df9b89ced27eae33d739ebc80b60f4 Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Sun, 18 Oct 2020 22:13:28 +0200 Subject: [PATCH] Fix issues with integer overflow in memory pressure calculations --- .../gpu-gl-common/src/gpu/gl/GLTextureTransfer.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLTextureTransfer.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLTextureTransfer.cpp index 6a88fd2c50..2b9b209c67 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLTextureTransfer.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLTextureTransfer.cpp @@ -239,13 +239,16 @@ void GLTextureTransferEngineDefault::updateMemoryPressure() { float pressure = 0; if (useAvailableGlMemory) { - float totalMem = GLBackend::getTotalMemory(); - float availMem = GLBackend::getAvailableMemory() - AUTO_RESERVE_TEXTURE_MEMORY; - if (availMem < 0) { + size_t totalMem = GLBackend::getTotalMemory(); + size_t availMem = GLBackend::getAvailableMemory(); + + if (availMem >= AUTO_RESERVE_TEXTURE_MEMORY) { + availMem -= AUTO_RESERVE_TEXTURE_MEMORY; + } else { availMem = 0; } - pressure = (totalMem - availMem) / totalMem; + pressure = ((float)totalMem - (float)availMem) / (float)totalMem; } else { pressure = (float)totalVariableMemoryAllocation / (float)allowedMemoryAllocation; }