Fixed overflowing memory counter
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
2034
|
||||
2036
|
||||
@@ -95,16 +95,12 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
|
||||
public function getSpecificAsset(id:String, type:String, source:AssetSource = BOTH):Dynamic {
|
||||
try {
|
||||
#if cpp
|
||||
cpp.vm.Gc.enable(false);
|
||||
#end
|
||||
MemoryUtil.disable();
|
||||
|
||||
if (!id.startsWith("assets/")) {
|
||||
var ass = getSpecificAsset('assets/$id', type, source);
|
||||
if (ass != null) {
|
||||
#if cpp
|
||||
cpp.vm.Gc.enable(true);
|
||||
#end
|
||||
MemoryUtil.enable();
|
||||
return ass;
|
||||
}
|
||||
}
|
||||
@@ -113,22 +109,15 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
|
||||
var asset = e.getAsset(id, type);
|
||||
if (asset != null) {
|
||||
#if cpp
|
||||
cpp.vm.Gc.enable(true);
|
||||
#end
|
||||
MemoryUtil.enable();
|
||||
return asset;
|
||||
}
|
||||
}
|
||||
|
||||
#if cpp
|
||||
cpp.vm.Gc.enable(true);
|
||||
#end
|
||||
|
||||
MemoryUtil.enable();
|
||||
return null;
|
||||
} catch(e) {
|
||||
#if cpp
|
||||
cpp.vm.Gc.enable(true);
|
||||
#end
|
||||
MemoryUtil.enable();
|
||||
throw e;
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -21,7 +21,7 @@ class FramerateField extends TextField {
|
||||
*/
|
||||
public var debugMode:Bool = false;
|
||||
|
||||
public var peak:UInt = 0;
|
||||
public var peak:Float = 0;
|
||||
public var lastFPS:Float = 0;
|
||||
|
||||
public function new(x:Float = 10, y:Float = 10, color:Int = 0x000000)
|
||||
@@ -59,12 +59,13 @@ class FramerateField extends TextField {
|
||||
text.push('FPS: ${Std.int(lastFPS)}');
|
||||
}
|
||||
#if !web
|
||||
var totalMemory = MemoryUtil.currentMemUsage();
|
||||
if (showMemory || debugMode) {
|
||||
text.push('RAM: ${CoolUtil.getSizeString(cast(System.totalMemory, UInt))}');
|
||||
text.push('RAM: ${CoolUtil.getSizeString(totalMemory)}');
|
||||
}
|
||||
if (showMemoryPeak || debugMode) {
|
||||
if (peak < System.totalMemory)
|
||||
peak = System.totalMemory;
|
||||
if (peak < totalMemory)
|
||||
peak = totalMemory;
|
||||
text.push('RAM PEAK: (${CoolUtil.getSizeString(peak)})');
|
||||
}
|
||||
#end
|
||||
|
||||
@@ -244,8 +244,6 @@ class Main extends Sprite
|
||||
|
||||
Paths.assetsTree.clearCache();
|
||||
|
||||
#if cpp
|
||||
cpp.vm.Gc.run(true);
|
||||
#end
|
||||
MemoryUtil.clearMajor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package funkin.utils;
|
||||
|
||||
#if cpp
|
||||
import cpp.vm.Gc;
|
||||
#elseif hl
|
||||
import hl.Gc;
|
||||
#elseif java
|
||||
import java.vm.Gc;
|
||||
#elseif neko
|
||||
import neko.vm.Gc;
|
||||
#end
|
||||
import openfl.system.System;
|
||||
|
||||
class MemoryUtil {
|
||||
public static function clearMinor() {
|
||||
#if (cpp || java || neko)
|
||||
Gc.run(false);
|
||||
#end
|
||||
}
|
||||
|
||||
public static function clearMajor() {
|
||||
#if cpp
|
||||
Gc.run(true);
|
||||
Gc.compact();
|
||||
#elseif hl
|
||||
Gc.major();
|
||||
#elseif (java || neko)
|
||||
Gc.run(true);
|
||||
#end
|
||||
}
|
||||
|
||||
public static function enable() {
|
||||
#if (cpp || hl)
|
||||
Gc.enable(true);
|
||||
#end
|
||||
}
|
||||
|
||||
public static function disable() {
|
||||
#if (cpp || hl)
|
||||
Gc.enable(false);
|
||||
#end
|
||||
}
|
||||
|
||||
public static inline function currentMemUsage() {
|
||||
#if cpp
|
||||
return Gc.memInfo64(Gc.MEM_INFO_USAGE);
|
||||
#elseif sys
|
||||
return cast(cast(System.totalMemory, UInt), Float);
|
||||
#else
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user