Page 1 of 1

Execute code before exiting Game Mode

PostPosted: Tue Feb 23, 2016 10:42 am
by lcl
Hi!

A feature I'd really love to have would be to be able to execute code before exiting Game Mode.

Currently, GE returns to the editor right when one presses ESC in Game Mode, no matter which option is selected for the "Press ESC to exit game". Now this is a problem when one uses dynamic allocation for something in his game. That allocated memory should be freed, but even if I put the memory freeing code in View -> Key Down -> Esc it won't actually free the memory. It just exits the game. And so it leaks memory. After I go back and forth between Game Mode and editor mode a couple of times, GE's memory consumption has risen drastically.

I could of course free the memory in some other event, but that would require me to always remember to press that key / click that button before finishing testing my game. And actually, if it was just my problem when developing something, I'd be fine with that. But as I'm developing a template GE project for other people to use, this becomes a serious issue.

So, the possible fix I'd suggest would be to either:
A) make the "Press Esc to exit game: no" effective in editor as well
or
B) make GE first execute any code in Key Down Esc, and only after that go back to the editor view

Thanks for reading.

lcl

Re: Execute code before exiting Game Mode

PostPosted: Wed Feb 24, 2016 10:54 am
by skydereign
Good idea. I always went with the alternate quit key approach, but actually fixing the problem is definitely more desirable.

Re: Execute code before exiting Game Mode

PostPosted: Wed Feb 24, 2016 11:43 am
by lcl
skydereign wrote:Good idea. I always went with the alternate quit key approach, but actually fixing the problem is definitely more desirable.

Great, thanks!

Re: Execute code before exiting Game Mode

PostPosted: Thu Mar 10, 2016 3:23 am
by Zivouhr
I agree this would help if possible as I have gotten memory full errors and game editor crashes after only a few escapes from the game mode back into the editor.

Re: Execute code before exiting Game Mode

PostPosted: Sun Feb 19, 2017 10:20 pm
by Zivouhr
lcl wrote:Hi!

A feature I'd really love to have would be to be able to execute code before exiting Game Mode.

Currently, GE returns to the editor right when one presses ESC in Game Mode, no matter which option is selected for the "Press ESC to exit game". Now this is a problem when one uses dynamic allocation for something in his game. That allocated memory should be freed, but even if I put the memory freeing code in View -> Key Down -> Esc it won't actually free the memory. It just exits the game. And so it leaks memory. After I go back and forth between Game Mode and editor mode a couple of times, GE's memory consumption has risen drastically.

I could of course free the memory in some other event, but that would require me to always remember to press that key / click that button before finishing testing my game. And actually, if it was just my problem when developing something, I'd be fine with that. But as I'm developing a template GE project for other people to use, this becomes a serious issue.

So, the possible fix I'd suggest would be to either:
A) make the "Press Esc to exit game: no" effective in editor as well
or
B) make GE first execute any code in Key Down Esc, and only after that go back to the editor view

Thanks for reading.

lcl


Hi Lcl,

For large games, I usually end up with a lot of memory piling up fast, so in editor mode while creating, the editor will crash at about the 5th time pressing exit. I was interested in how easy it is to create a key down event just for programming, that would free up the memory. Is there a simple input, as I couldn't find much about it in the scripting manual for Game Editor, but this would help a ton if I could figure out how to reset the memory to avoid crashing in editor mode and test mode, only to have to reload the game which can take 5 minutes average, and time lost.

Thanks for any tips you have on this.


realloc: Changes the size of the previously allocated memory pointed to by ptr to that specified by size. The value of size can be greater or less than the original. A pointer memory block is returned because it may be necessary for realloc() to move the block in order to change its size. If this occurs, the contents of the old block (up to size bytes) are copied into the new block.
void *realloc(void *ptr, size_t size);

Was all I could find, though not sure how to implement that if that's the key.

Re: Execute code before exiting Game Mode

PostPosted: Sun Feb 19, 2017 10:39 pm
by lcl
Zivouhr wrote:Hi Lcl,

For large games, I usually end up with a lot of memory piling up fast, so in editor mode while creating, the editor will crash at about the 5th time pressing exit. I was interested in how easy it is to create a key down event just for programming, that would free up the memory. Is there a simple input, as I couldn't find much about it in the scripting manual for Game Editor, but this would help a ton if I could figure out how to reset the memory to avoid crashing in editor mode and test mode, only to have to reload the game which can take 5 minutes average, and time lost.

Thanks for any tips you have on this.


realloc: Changes the size of the previously allocated memory pointed to by ptr to that specified by size. The value of size can be greater or less than the original. A pointer memory block is returned because it may be necessary for realloc() to move the block in order to change its size. If this occurs, the contents of the old block (up to size bytes) are copied into the new block.
void *realloc(void *ptr, size_t size);

Was all I could find, though not sure how to implement that if that's the key.

You can only free memory if you have allocated it yourself and have a pointer to the allocated block of memory (which you always should have if you have allocated something). Now, I'm guessing you have not worked with dynamic memory allocation functions such as malloc(), calloc(), realloc()? If you haven't done any programming with those or other dynamic memory allocation functions, you don't have memory that you could free using the free() function as that only frees memory allocated by those functions.

Re: Execute code before exiting Game Mode

PostPosted: Mon Feb 20, 2017 3:31 am
by Zivouhr
lcl wrote:You can only free memory if you have allocated it yourself and have a pointer to the allocated block of memory (which you always should have if you have allocated something). Now, I'm guessing you have not worked with dynamic memory allocation functions such as malloc(), calloc(), realloc()? If you haven't done any programming with those or other dynamic memory allocation functions, you don't have memory that you could free using the free() function as that only frees memory allocated by those functions.


Okay, thanks a lot for helping to explain how that works, Lcl. 8)