Execute code before exiting Game Mode

Ideas for Game Editor evolution.

Execute code before exiting Game Mode

Postby lcl » Tue Feb 23, 2016 10:42 am

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
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Execute code before exiting Game Mode

Postby skydereign » Wed Feb 24, 2016 10:54 am

Good idea. I always went with the alternate quit key approach, but actually fixing the problem is definitely more desirable.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Execute code before exiting Game Mode

Postby lcl » Wed Feb 24, 2016 11:43 am

skydereign wrote:Good idea. I always went with the alternate quit key approach, but actually fixing the problem is definitely more desirable.

Great, thanks!
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Execute code before exiting Game Mode

Postby Zivouhr » Thu Mar 10, 2016 3:23 am

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.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Execute code before exiting Game Mode

Postby Zivouhr » Sun Feb 19, 2017 10:20 pm

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.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Execute code before exiting Game Mode

Postby lcl » Sun Feb 19, 2017 10:39 pm

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.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Execute code before exiting Game Mode

Postby Zivouhr » Mon Feb 20, 2017 3:31 am

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)
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score


Return to Feature Requests

Who is online

Users browsing this forum: No registered users and 1 guest

cron