[A14] Sounds and Music Memory Loading Issues

Started by tangerinemusiclabs, August 09, 2016, 04:36:17 AM

Previous topic - Next topic

tangerinemusiclabs

I've been making a mod that puts additional background music into the game, but I've run into some issues where the mod loading behavior has been causing some CTD issues for some people.  I think it's because the Unity engine pre-loads all the sound files (music or otherwise) into its memory and if it's too big, then it just quits altogether.  The code of the mod itself is straightforward so I think that it has to be the file size or file type that causing it.

The soundtracks that I made for the mod is fairly long, so it may be part of the reason why it crashes on some people's machines, especially on older builds.  (20+ minutes for one) But I'm not exactly sure what the recommended format, bit-rate, VBR/CBR etc. are for music files, and if there are hard limits that should be avoided in order to make the mod work.  The bizzare thing is that it works fine on my machine -- sometimes -- other times the song just doesn't want to seem to load at all.  Sometimes I hit the "play song" button in the debug menu and nothing plays.  If I restart the computer and try again, sometimes it works.  (No CTD yet, but I do have a lot of physical memory on my computer that others might not have.)

I think it's definitely related to the memory because it plays my 3 minute song just fine, but has trouble with the 20 minute ones.

If anyone here happens to know how to pinpoint in the problem, it'd be greatly appreciated too.  Seems like there ought to be an easy solution to it if it were possible.

Mod is here, for reference:
http://steamcommunity.com/sharedfiles/filedetails/?id=731638290

milon

If the mod works as designed for all shorter songs, and if it breaks on longer songs, and if you can play the longer songs outside of RimWorld, then I would conclude the problem is either lack of RAM, or a Unity bug, or a RimWorld bug.

I suggest you collect some data from your users - amount of RAM, OS, if the mod works or not, etc.  See if you can find a correlation.

If it turns out to be a Unity bug, there's nothing we can do.  If it's a RAM issue, it's on the user to fix.  If it's a RimWorld bug, then it should be posted in the Bugs forum.

Let us know how it goes!

tangerinemusiclabs

#2
Thanks for the reply.  I think it's safe to say that it's not a RAM issue since I have 32 GB and users with 16GB reporting the same problems.  My setup doesn't get a CTD, but it just stops the sound from playing.  So it's either an issue with Unity or Rimworld, for sure, but at this point I'm not sure which is the culprit.  (It's probably a combination of the sound engine and how the sounds are loaded into the game itself, is my guess.)

Either way, though, if it's experiencing issues with even 20MB of sound files that's going to be fairly limiting, even for non-music related mods.  High quality sounds/music is pretty much out of the question if the buffer for sounds are that small.

Part of the problem, I think, is that the game currently doesn't make a distinction between sound files and music files.  I understand the need to preload sound effects into the memory for immediacy, but ambient musics shouldn't really need that kind of priortization, for the most part.  Dunno if that helps or not.

The thread on the Steam Workshop, if you want to see the discussion:
https://steamcommunity.com/sharedfiles/filedetails/?id=731638290

Hope something can be done about it!  Would be great to keep on adding more stuff to the game.

milon

I agree with your assessment - either RimWorld or Unity must be at fault.

Moving to Bugs for the devs to review.

tangerinemusiclabs

#4
Bumping this thread but I've been learning about the Unity Engine lately and discovered a possible solution to this issue.

Changing the audio load type for music files to either "decompress on load" or "streaming" would likely solve the audio-related CTD issues if it's indeed loading everything using the "compressed in memory" methodology. 

Hope this helps!  I'd try to fix it myself if I had more time.

https://docs.unity3d.com/Manual/class-AudioClip.html