From 71947c581e78891233dd2c97cbe60d5cdc23d8b5 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 11 Jul 2024 19:35:41 -0400 Subject: [PATCH] [PUBLIC PR] Fix a bug where the memory counter would overflow into the negatives (#662) * get Float instead of Int in cpp (Float is 64-bit in so it works easier than Int64) * use Math.fround instead of Math.round --------- Co-authored-by: Karim Akra <144803230+KarimAkra@users.noreply.github.com> --- source/funkin/ui/debug/MemoryCounter.hx | 2 +- source/funkin/util/MemoryUtil.hx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/funkin/ui/debug/MemoryCounter.hx b/source/funkin/ui/debug/MemoryCounter.hx index b25b55645..50421f398 100644 --- a/source/funkin/ui/debug/MemoryCounter.hx +++ b/source/funkin/ui/debug/MemoryCounter.hx @@ -36,7 +36,7 @@ class MemoryCounter extends TextField @:noCompletion #if !flash override #end function __enterFrame(deltaTime:Float):Void { - var mem:Float = Math.round(MemoryUtil.getMemoryUsed() / BYTES_PER_MEG / ROUND_TO) * ROUND_TO; + var mem:Float = Math.fround(MemoryUtil.getMemoryUsed() / BYTES_PER_MEG / ROUND_TO) * ROUND_TO; if (mem > memPeak) memPeak = mem; diff --git a/source/funkin/util/MemoryUtil.hx b/source/funkin/util/MemoryUtil.hx index f5935ed67..18fd41472 100644 --- a/source/funkin/util/MemoryUtil.hx +++ b/source/funkin/util/MemoryUtil.hx @@ -48,11 +48,11 @@ class MemoryUtil * Calculate the total memory usage of the program, in bytes. * @return Int */ - public static function getMemoryUsed():Int + public static function getMemoryUsed():#if cpp Float #else Int #end { #if cpp // There is also Gc.MEM_INFO_RESERVED, MEM_INFO_CURRENT, and MEM_INFO_LARGE. - return cpp.vm.Gc.memInfo(cpp.vm.Gc.MEM_INFO_USAGE); + return cpp.vm.Gc.memInfo64(cpp.vm.Gc.MEM_INFO_USAGE); #else return openfl.system.System.totalMemory; #end