Memory Leak? Constant crashing.
#1
Posted 27 December 2010 - 04:58 PM
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?
#2
Posted 27 December 2010 - 07:02 PM
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
#3
Posted 27 December 2010 - 07:17 PM
what is a memory leak?
#4
Posted 27 December 2010 - 07:20 PM
Edited by Emanrice, 27 December 2010 - 07:23 PM.
#5
Posted 27 December 2010 - 07:24 PM
Here is a Wikipedia article about memory leaks. It says:what is a memory leak?
Please make an effort to find things out yourself before asking other people. Your brain is in your own head for a reason.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.
GameGeisha
#6
Posted 27 December 2010 - 07:27 PM
@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!
#7
Posted 27 December 2010 - 08:33 PM
#8
Posted 27 December 2010 - 08:36 PM
#9
Posted 27 December 2010 - 09:42 PM
thanks
Edited by the artist, 27 December 2010 - 09:56 PM.
#10
Posted 27 December 2010 - 09:55 PM
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
}
#11
Posted 27 December 2010 - 11:16 PM
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...
#12
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.
#13
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 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











