Jump to content


Photo

Memory Leak? Constant crashing.


  • Please log in to reply
12 replies to this topic

#1 the artist

the artist

    GMC Member

  • New Member
  • 128 posts

Posted 27 December 2010 - 04:58 PM

This game I have been working on randomly crashes when I play it. Sometimes it happens faily soon, sometimes it doesn't happen at all. I'm pretty sure its not because of a large amount of objects being active at once because I have been through debug mode and havn't seen anything weird before it crashes.

This isn't even one of my more ambitious projects and I've never had this sort of problem at all before. When it crashes it just freezes and there is no error message. I think it might be a memory leak but thats because I can't think of anything else it might be because I've never had any problems with any other games. Does anyone know how I would go about finding the cause of the problem and then fixing it?
  • 0

#2 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 2749 posts
  • Version:GM:Studio

Posted 27 December 2010 - 07:02 PM

There really isn't anything that we can do when you're telling us just the symptoms. You need to show us the source.

If you suspect a memory leak, that's a good place to start. Start up Task Manager just before running your game in debug, then watch the game's memory usage column and see when it jumps.

GameGeisha
  • 0

#3 goldage5

goldage5

    GMC Member

  • GMC Member
  • 152 posts

Posted 27 December 2010 - 07:17 PM

just wondering....

what is a memory leak?
  • 0

#4 Water Chicken

Water Chicken

    Got it memorized?

  • GMC Member
  • 1191 posts
  • Version:GM:Studio

Posted 27 December 2010 - 07:20 PM

From what I know, it's when a great amount of memory is being used and none of it being released. If it goes on for too long, it can crash the game, or even the computer due to not having enough memory to store stuff.

Edited by Emanrice, 27 December 2010 - 07:23 PM.

  • 0

#5 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 2749 posts
  • Version:GM:Studio

Posted 27 December 2010 - 07:24 PM

what is a memory leak?

Here is a Wikipedia article about memory leaks. It says:

A memory leak, in computer science (or leakage, in this context), occurs when a computer program consumes memory but is unable to release it back to the operating system.

Please make an effort to find things out yourself before asking other people. Your brain is in your own head for a reason.

GameGeisha
  • 0

#6 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16839 posts
  • Version:GM:Studio

Posted 27 December 2010 - 07:27 PM

@OP - Freezing (and at different moments) suggests some type of infinte loop rather than a memory leak... A memory leak usually starts by lagging the game ad then blocking, or even crashing, it. So, do you have any while() loops running in objects?

@goldage5 - A memory leak is when you are asigning memory to something (like a data-structure, or external resources) and then not deleting them from memory when not in use, or over-writing the "pointer" variable and so creating a "leak"... Here is an example...

//CREATE EVENT
snd=sound_add("sound.wav",0,0); //This loads a sound into the variable "snd"...
alarm[0]=room_speed;

//ALARM[0] EVENT
snd=sound_add("sound.wav",0,0); //This loads a sound into the variable "snd" AGAIN but without deleting the old sound...

So, now we have the same sound stored TWICE in memory, but as we have used the same variable, the first copy of the loaded sound cannot now be accessed and so is using up memory for nothing. If this happens MANY times, then we have a memory leak and it will eat up memory until the game crashes... The code SHOULD be...

//ALARM[0] EVENT
sound_delete(snd); //Delete the sound from memory FIRST
snd=sound_add("sound.wav",0,0); //Now we can re-use the same variable without any leaks...

I hope that helps you!
  • 0

#7 goldage5

goldage5

    GMC Member

  • GMC Member
  • 152 posts

Posted 27 December 2010 - 08:33 PM

oh. ok thanks.
  • 0

#8 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 2865 posts
  • Version:GM:Studio

Posted 27 December 2010 - 08:36 PM

That kind of crashes while running GM games happens when you run large loops, or when you suddenly store large images/sounds from an external source... check all of your loops and external files to see if its one of them.
  • 0

#9 the artist

the artist

    GMC Member

  • New Member
  • 128 posts

Posted 27 December 2010 - 09:42 PM

I am going to start looking through all my code for anything such that has been mentioned.

thanks

Edited by the artist, 27 December 2010 - 09:56 PM.

  • 0

#10 the artist

the artist

    GMC Member

  • New Member
  • 128 posts

Posted 27 December 2010 - 09:55 PM

I think this is the piece of code that is causing the crash. When I remove it the game doesn't crash at all!

I just need to understand why this makes it crash; I'm a little confused :S

if (place_meeting(x,y+vsp,ob_parentbuilding) and vsp>0)
{
    //Move so we hit the ground
    var cc;
    cc=vsp+1; //A counter, so we don't get an infinite loop

     //Move down until we hit the floor
    while (!place_meeting(x,y+1,ob_parentbuilding) and cc>=0) y+=1;

     //Now ground the player
    grounded=true;

    vsp=0;vspeed=0;gravity=0
}

  • 0

#11 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16839 posts
  • Version:GM:Studio

Posted 27 December 2010 - 11:16 PM

You should subtract 1 froom cc at the same time as you add 1 to y... So...

while (!place_meeting(x,y+1,ob_parentbuilding) and cc>=0)
{
y+=1;
cc-=1;
}

You create the counter, but donīt actually use it for anything, and so it will ALWAYS be greater than 0 (if vsp>0 then cc must be at least 1) so the "while" is an infinite loop as it is always checking the cc variable. So count it down as I show above...
  • 0

#12 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 2865 posts
  • Version:GM:Studio

Posted 27 December 2010 - 11:17 PM

if place_meeting(x,y+vsp,ob_parentbuilding) && vsp > 0
{
    while (!place_meeting(x,y,ob_parentbuilding)
      y+=1;

     //Now ground the player
    grounded=true;
    vsp=0;vspeed=0;gravity=0
}
That's how i would do it.. the variable cc is quite useless, because you are already checking in the 'if' if vsp is bigger than zero.


@Mark: So, we meet again... -_-

Edited by manuel777, 27 December 2010 - 11:19 PM.

  • 0

#13 the artist

the artist

    GMC Member

  • New Member
  • 128 posts

Posted 28 December 2010 - 02:35 PM

You should subtract 1 froom cc at the same time as you add 1 to y... So...

while (!place_meeting(x,y+1,ob_parentbuilding) and cc>=0)
{
y+=1;
cc-=1;
}

You create the counter, but donīt actually use it for anything, and so it will ALWAYS be greater than 0 (if vsp>0 then cc must be at least 1) so the "while" is an infinite loop as it is always checking the cc variable. So count it down as I show above...


Ah, I see it now. It's working now and not crashing, thank you very much for the help.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users