Severe Memory Leakage?
For context: I am working on a mod to this source code that aims to provide a new story, HQ music, etc.
I recently noticed (after playing the game for longer than a few minutes) that it would crash soon before the portion of the Brickster Hunt after you've chased him but before you rebuild the helicopter.
For kicks, I compiled under debug, and attached the Visual Studio 2022 debugger, and watched in horror as the Memory usage very quickly skyrocketed (as in, an exponential amount of mb of memory used up every minute), until the program reached 1.7GB of memory usage and crashed when trying to load into the music stream buffer. The error? Bad memory allocation.
After further testing, I have concluded that the SI streamer is at fault. The game idles at just about 104MB of RAM usage from my testing, and skyrockets whenever audio is being streamed. The stock music usually raises this to about 140MB of RAM usage, and some of the higher quality tracks idle around here too for whatever reason, such as The Jail and Police Station themes. However, other higher quality tracks, such as The Lego Island Theme (if that's the track's real name) and the Information center theme bring this amount up way higher, and in the case of the Chasing the Brickster, the memory usage makes it's way to a point where the game can no longer allocate any memory at all (in my testing, this is just under 2GB, which makes sense since that's the memory limit for 32bit applications).
Edit: I have figured out that the Higher Quality tracks that weren't causing memory leaks was because those particular tracks I was instead using the unused 22050Hz versions instead of the masters. Replacing these versions with the 44100Hz masters reveals the same memory leak once again.
This isn't really something to fix for the decomp, since the aim is accuracy, but this is something to keep in mind if you plan on making a mod of Lego Island.
Just to be sure I got this right:
- You saw the memory leak when using modded assets with both the original and recompiled binary?
- You didn't test whether the same memory leak happens on isle-portable as well?
In case you don't already do that, I'd recommend you base your mod on isle-portable since it will have much better compatibility and bugfixes will be included in the code.
Could you test whether you see the same memory leak on isle-portable? In that case I'd move this ticket over there.
Just to be sure I got this right:
- You saw the memory leak when using modded assets with both the original and recompiled binary?
- You didn't test whether the same memory leak happens on isle-portable as well?
In case you don't already do that, I'd recommend you base your mod on
isle-portablesince it will have much better compatibility and bugfixes will be included in the code.Could you test whether you see the same memory leak on
isle-portable? In that case I'd move this ticket over there.
I will test with isle-portable when I have the time, and yes you got that information correct.
I am not able to test with isle-portable, as CMake is unable to fetch the miniaudio v0.11.22 gz compressed tar archive.
It states it's "status code", which I assume to be error code, is 60, and that the "SSL peer certificate or SSH remote key was not OK". It suggests that I can add a CMAKE_TLS_VERIFY env variable to suppress the error, but I added it to the System Environment Variables (eww windows user) and nothing has changed. The following is the log provided by CMake:
--- LOG BEGIN ---
Host github.com:443 was resolved.
IPv6: (none)
IPv4: 140.82.113.4
Trying 140.82.113.4:443...
GnuTLS priority:
NORMAL:-ARCFOUR-128:-CTYPE-ALL:+CTYPE-X509:-VERS-SSL3.0:-VERS-TLS-ALL:+VERS-TLS1.3:+VERS-TLS1.2
ALPN: curl offers http/1.1
SSL connection using TLS1.3 / ECDHE_RSA_AES_128_GCM_SHA256
server verification failed: certificate signer not trusted. (CAfile: none
CRLfile: none)
closing connection #0
--- LOG END ---
You can pull in miniaudio via git submodules or downloading them manually and specifying DOWNLOAD_DEPENDENCIES=OFF for cmake.
64bit is also supported so if you want you can have it run for longer even if it does leak (:
I added it to the System Environment Variables (eww windows user) and nothing has changed.
You have to restart for it to affect sub proesses (eww windows user)
What enviroment do you run this under? The SSL error you are getting indicates that your certificate bundle is out of date. You can try updating it with this one: https://curl.se/ca/cacert.pem
I added it to the System Environment Variables (eww windows user) and nothing has changed.
You have to restart for it to affect sub proesses
This does not appear to be an issue in portable, please re open and provide additional info if you still see it with your mod.
I've noticed this issue as part of #671. The issue seems to be related to high quality audio that is using multiple split chunks in the SI file. Massif visualized:
This could either be a bug in the SI streamer in Lego Island, or a wrong assumption about how split chunks should be used in libweaver. I suspect the former, since functionality-wise everything works fine. It's just continuously allocating memory while audio is streaming. The memory is freed when the action/presenter is cancelled (i.e. when you switch to another area), so the leak is scoped to an instance of a streaming asset.