• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Destroying animation curves.

K

KekkoKamen

Guest
Ok,
Every frame, I'm creating an animation curve and I destroy it after it's been used in the draw event. The reason for that, is that I feed the curve updated values every frames, and draw that curve in the draw event.
In summary, every frame, I create an animation curve and destroy it after it has been used.

While I run the game, it works perfectly, the curve is drawn like I need it to. But when I restart the room using room_restart(), I get a code error in the step event saying that it could not create curve.

I figured that maybe when restarting the room in the step event the curve was not getting destroyed since it only happens in the draw event, so I added animcurve_destroy(my_curve) just before the room is restarted. After doing that, it got weirder, because now I can restart the room but only once, if I restart it twice I get that same code error as before.

When restarting a room, shouldn't everything in the room starts anew ? I don't uses globals, it's the only room in the program. I don't understand why it wouldn't work.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
When restarting a room, shouldn't everything in the room starts anew ?
Yes, but that doesn't mean you've cleaned everything up from before... You should use the CLEAN UP event to check for the anim curve and destroy it if it still exists when the room ends. That said, not doing that will give you a memory leak, but shouldn't give you the behaviour you explain. Can you show the code you have for creating, using and destroying the curve?
 
K

KekkoKamen

Guest
Ok, thanks for your answer.

It appears that it works now. There was a totally different curve (with a different name, stored in a different struct) in my creation event that I was not destroying before room_restart().
For some reasons, that curve was not the one that GM would not create when I restart the room, so I did not suspect that troubles was coming from this one.

So, if I understand, if I had a Clean up event in the object, the event will run it's code before the room is restarted or the object destroy, and I should put my code for destroying the curves in it ?
 
Top