Author Topic: Out of Memory Error  (Read 4884 times)

Tamatou

  • Wannabe
  • Posts: 43
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Chrome 44.0.2403.155 Chrome 44.0.2403.155
    • View Profile
  • Playstyle: Gamepad
Out of Memory Error
« on: August 16, 2015, 11:56:43 PM »
Hello guys.

So I've been working on my fangame for a while now, currently I am working on the first Boss. But suddenly Game Maker startet getting "Out of Memory" Error Messagen about 40% of the Time when starting the game and about 10% of the time when saving it.

This is very annoying. Has anyone had this same problem? I've heard it's relativly common. But is there a way to fix it?
From Austria with Love <3

klazen108

  • Administrator
  • The Kid
  • Posts: 286
  • your a kid now your a squid now
  • OS:
  • Windows NT 10.0 Windows NT 10.0
  • Browser:
  • Chrome 44.0.2403.155 Chrome 44.0.2403.155
    • View Profile
    • Delicious-Fruit
  • Playstyle: Keyboard
Re: Out of Memory Error
« Reply #1 on: August 17, 2015, 12:42:20 AM »
You mention that this only happens like 40% of the time, so it leads me to believe that your game has a memory leak. This is usually caused by acquiring handles for data structures, particle systems, maybe externally loaded sprites/backgrounds/music, etc. and then not freeing them when you're done. Does your game use any ds functions? (like ds_list_*, ds_map_*, etc). What about particle functions? (like part_system_create()) Or how about external loading? (background_add, sprite_add)? When you open a file for reading/writing, for instance during saving, do you close the handle afterwards? (file_bin_close or file_text_close)

If you can think of any of these things that might be in your game, it'll help pinpoint what might be wrong!

Tamatou

  • Wannabe
  • Posts: 43
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Chrome 44.0.2403.155 Chrome 44.0.2403.155
    • View Profile
  • Playstyle: Gamepad
Re: Out of Memory Error
« Reply #2 on: August 17, 2015, 09:29:09 AM »
The only thing I have is one particle system used to create smoke (ALOT of smoke)
I've heard externally loading music can reduce the loading time, but I haven't really looked into that so far.
My loading time is getting longer and longer the more I work on the game (I suppose that is to be expected) But my game isn't really that big. It just has alot of (unecessary) effects like Screen Shake, Light and Darkness Effects, Zoom Effect etc...

Oh, and I never really heard of DS_Functions until now.
From Austria with Love <3

klazen108

  • Administrator
  • The Kid
  • Posts: 286
  • your a kid now your a squid now
  • OS:
  • Windows NT 10.0 Windows NT 10.0
  • Browser:
  • Chrome 44.0.2403.155 Chrome 44.0.2403.155
    • View Profile
    • Delicious-Fruit
  • Playstyle: Keyboard
Re: Out of Memory Error
« Reply #3 on: August 17, 2015, 06:39:46 PM »
You mention you're using a particle system. When do you create and destroy your particle system? And which fangame engine are you using? If you're using an engine like yuuutu, and creating your particle system on game start, but not destroying it on game end, then you're actually creating a new particle system every time you press R! Try just opening your game, saving, and just pressing R over and over and see if you can get it to crash really fast - if so you've got a memory leak on your hands.

Also, how big is your project file (the gmk or gm81 file)? Just so I can imagine how much stuff is actually in your game, to see if that's becoming an issue. The effects wouldn't matter much, but large, animated sprites and backgrounds can really eat at your memory consumption without you noticing. Images are stored compressed in PNG format but are uncompressed when loaded into memory, dramatically increasing the amount of space they take up. As a quick example, a plain 800x600 black rectangle is just 4kb big as a PNG, but it's 1MB as a sprite! Music is another big one, especially if you store your music as WAV files (don't do that!).

Tamatou

  • Wannabe
  • Posts: 43
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Chrome 44.0.2403.155 Chrome 44.0.2403.155
    • View Profile
  • Playstyle: Gamepad
Re: Out of Memory Error
« Reply #4 on: August 17, 2015, 10:49:18 PM »
I am using the YoSniper I Wanna Be The Engine (not the newest version though)
Oh no, I've always been using WAV for Music. There are only like 6 songs in the Game so far.

I tried pressing R alot but that doesen't seem to affect the game. Also there visualy doesn't appear to be more smoke particles.
Note that the game never crashed when running. It only crashes when game maker is loading it up and rarely (and annonyingly) when saving the file.

The Game Maker File is 208 MB
So I am indeed worried that the game might get too big eventually. Game is only about 5% done.

Slightly Off Topic:
Now that is wierd. I originally wanted the boss to choose one of two attacks to start out on. But sometimes a glitch would occour where the boss spawned twice the amount of bullets making avoiding nearly impossible. I've worked around this by giving the boss a third attack that he would do whenever this glitch occured. But now suddely the glitch doesn't occur anymore so now he never uses his third attack. Don't worry I can easily fix this. But it just really astonished me.
From Austria with Love <3

Derf

  • Guest
Re: Out of Memory Error
« Reply #5 on: August 17, 2015, 11:05:22 PM »
That is far far far too big for a game maker file. No game, even 100% complete should be that big. That is most likely the source of your crashes.

First of all, there's no need to use music files as big as I presume you are using, most people won't be able to tell the difference in bitrate between some of those and compressed mp3s/oggs, let alone in game while concentrating on gameplay. You should compress those files down, no one's going to download a fangame that's 4GB big just because of music.

Secondly, you need to load them externally so the game make file doesn't hold all of the music files. This thread explains how in quite some depth.

Following these steps will most likely fix your issues.

klazen108

  • Administrator
  • The Kid
  • Posts: 286
  • your a kid now your a squid now
  • OS:
  • Windows NT 10.0 Windows NT 10.0
  • Browser:
  • Chrome 44.0.2403.155 Chrome 44.0.2403.155
    • View Profile
    • Delicious-Fruit
  • Playstyle: Keyboard
Re: Out of Memory Error
« Reply #6 on: August 18, 2015, 01:36:47 PM »
208MB? Oh yeah, that's absolutely your issue then. Since you're using the yosniper engine, the quick fix is to just convert those WAV files to mp3, and then put them back in your game. It'll work exactly the same, provided your game doesn't try to play two mp3s at once (gm8/8.1 can't do that). You only need to do this for the music, the sfx can and should stay as wav files.

After you've done that, if you still need to save memory, external loading of music is where you go to next. It would be easier if you were using, say, the Seph engine, since it comes with the FMOD sound engine and external music loading built right in, but setting up the yosniper engine to externally load music might be a little tricky (not to mention the potential source of some more memory leaks!) I wouldn't recommend it unless you feel comfortable modifying the engine like that.

Katz

  • Cherry Eater
  • Posts: 71
  • OS:
  • Windows 8.1/Server 2013 Windows 8.1/Server 2013
  • Browser:
  • Chrome 44.0.2403.155 Chrome 44.0.2403.155
    • View Profile
  • Playstyle: Keyboard
Re: Out of Memory Error
« Reply #7 on: August 18, 2015, 02:18:46 PM »
208MB? Oh yeah, that's absolutely your issue then. Since you're using the yosniper engine, the quick fix is to just convert those WAV files to mp3, and then put them back in your game. It'll work exactly the same, provided your game doesn't try to play two mp3s at once (gm8/8.1 can't do that). You only need to do this for the music, the sfx can and should stay as wav files.

After you've done that, if you still need to save memory, external loading of music is where you go to next. It would be easier if you were using, say, the Seph engine, since it comes with the FMOD sound engine and external music loading built right in, but setting up the yosniper engine to externally load music might be a little tricky (not to mention the potential source of some more memory leaks!) I wouldn't recommend it unless you feel comfortable modifying the engine like that.

nvm
« Last Edit: August 18, 2015, 03:03:38 PM by Katz »

Derf

  • Guest
Re: Out of Memory Error
« Reply #8 on: August 18, 2015, 02:23:35 PM »
No that would cause memory leaks.

What you need to do is run a script at start up that does something like:

Code: [Select]
global.song1 = sound_add(working_directory+"\BGM\song1.mp3",3,1);
global.song2 = sound_add(working_directory+"\BGM\song2.mp3",3,1);
global.song3 = sound_add(working_directory+"\BGM\song3.mp3",3,1);
global.song4 = sound_add(working_directory+"\BGM\song4.mp3",3,1);
etc
etc

Listing all your songs, and then just call the global variables every time you wanted to change music later on. Instead of adding duplicate sound files to the memory unnecessarily.

If you want to attempt it Tamatou it really isn't too difficult and it's all laid out here + in the link.

Tamatou

  • Wannabe
  • Posts: 43
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Chrome 44.0.2403.155 Chrome 44.0.2403.155
    • View Profile
  • Playstyle: Gamepad
Re: Out of Memory Error
« Reply #9 on: August 18, 2015, 10:58:21 PM »
Thank you so much guys  :atkHappy:
I haven't gotten a chance to try that yet since I'm on a vacation. But as soon as I return I'll try following your instructions and let you know if it worked
From Austria with Love <3