Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Does AppGameKit Tier 1 Automatically Clean-Up When Our Programs Terminate?

Author
Message
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 6th Dec 2018 17:29 Edited at: 6th Dec 2018 21:00
I encountered a weird issue a week or two ago in my defense game.

Originally I was loading images, creating sprites, etc at the beginning of each state of the program and stopping animations, clearing animation frames, stopping sprite tweens, deleting sprites, images etc at the end of each state. By state I mean Title Screen, Gameplay, GameOver, etc.

For some weird reason I started getting a "program stopped working" when moving from Gameplay back to the Title Screen. Well not so much started but more that I started doing thorough testing of navigating around from state to state where previously I was focused on developing & playing through the game focused on general testing & gameplay balancing.

Anyway through tracing I tracked it down to failing on DeleteAllImages() api call. No error message or anything only Windows itself telling me the program stopped working. I then manually unloaded every image and tracked it down to deleting specific subimages or if that worked (sometimes it did) then the error occurred while deleting the atlas image itself.

I then decided to just restructure everything and load all images at the start of the program and keep them in memory to the end. When the player exits the game I then do all of the clean-up and again the same error occurs same thing always while either using DeleteAllImages() or DeleteImage().

It's been incredibly frustrating. Finally I tried to just not even use DeleteImage() or DeleteAllImages() and in this case the program exits cleanly with no."programmed stopped working" error encountered.

So my question is does AppGameKit clean-up when the program ends? If so then I will just not even try to free the images myself since using DeleteImage or DeleteAllImages does not work for a few images for some completely unknown to me reason.

I even tried explicitly looping through all tweens from 1 to 999999 and if exists if playing stop it and then delete it and then looping through all sprites from 1 to 999999 checking if sprite exists if so set shader to 0, check if sprite is playing if so stop it checking if sprite animation frame count > 0 if so clear all frames and finally delete the sprite. Then sync a couple times to be sure chsnges are applied and then finally looping 1 to 999999 check if image i exists if so delete it.... and still on the deleteimage line "DefenseGame.exe has stopped working".

Yet if I do not try to clean-up with DeleteImages the program exits fine no errors. I don't get it at all. But as long as it is really freeing the images from memory then I will just leave it alone.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 6th Dec 2018 21:48
I would say it's a case of Windows cleaning up not AGK.
One thing that does persist and is very frustration to work with is the files in the /Users/your_name/AppData/Local/AgkApps/App_name folder
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 6th Dec 2018 22:07 Edited at: 6th Dec 2018 22:14
It's just odd to me. Although I don't bother with it for super simple projects and example game code etc... for games to be released out in the wild I'd like to be sure to release any resources my program has grabbed.

I just don't know how to do that when the actual DeleteImage or DeleteAllImages api calls themselves are what causes the error. So the only solution seems to be not to even use them. Maybe AppGameKit expects us not to free the images and it will do it but if we had a big project with loads of large images for different levels etc I think surely we should be deleting the images not needed.

I don't know what I'd do if this game was a larger project that truly needed to release all images from the title screen before loading the gameplay images and then releasing those before loading images for the game over state etc for example and I got this error. Only solution would be to stop using AppGameKit and use something else to redo allof the work I guess. That'd be a real waste of time.

I will try saving that image atlas with a new file name and switch to the new save and see if that makes any difference. I wouldn't think it would matter because other sub images on that sheet delete fine. It is almost like something has some kind of lock on the sub images AppGameKit is trying to delete. But that is why I wrote code to loop through about 1 million ids for tweens and sprites being sure they were all released before attempting to delete the images. Makes no difference.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 6th Dec 2018 22:09
Are you sure your not referencing the images after you delete them? Maybe still have a sprite or mesh still alive
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 6th Dec 2018 22:20 Edited at: 6th Dec 2018 22:28
Yes I am about 99% sure. Like I said I explicitly loop through almost 1 million IDs for tweens and clean them up if exist. Then do the same for about 1 million sprite IDs cleaning them up. Only after that do I try delete the images. I can try bumping thar loop up to 1 billion IDs. But I also have tried DeleteAllSprites problem is I have no idea if that automatically stops the sprite animations and clears the animation frames and at any rate it didn't remove the error so is why I decided to write the code to explicitly handle all of that for sprites too.

Originally I simply set sprite shader to 0, stopped sprite animations, cleared sprite animation frames and deleted sprites based on the IDs stored in arrays that were actually being used in the game. Before that all tweens are handled since they have a sprite reference so I took care of them before handling the sprites. Since that didnt work i decided to loop through a massive number of them. That is how I ended up with the loop i from 1 to 999999.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 6th Dec 2018 22:33 Edited at: 6th Dec 2018 22:39
This is the first project I have encountered this issue on but it is also the first one I have used the SpriteTweens and PlaySprite animation systems too. So I think maybe one of those has something to do with it. I might try recoding everything to handle that stuff myself as I normally do and see if getting rid of that stuff fixes the issue.

It's weird issues like this that is the reason I never use those kind of built-in systems in anything Unity, etc. There seems to always be some weird thing that happens. Not saying those are the cause but they definitely make it all much more complicated architecturally as far as tracking down the root cause because I don't know what those things are doing behind the scenes and maybe one of them is locking something. I think I might try recoding it all to remove that stuff and see.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 6th Dec 2018 22:45 Edited at: 6th Dec 2018 22:50
It happens with DeleteAllImages() or DeleteImage() except for DeleteImage it is only a specific atlas image or certain sub images of that atlas image. All tweens are cleaned up then all sprites are cleaned up including removing shader, stopping animations if playing clearing their animation frames if there are any then I try to clean up the images.

I'll try recoding it all to not use the built-in sprite animation and tween systems. If the error goes away then we will know just don't use those. I am using them both heavily in my game.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 6th Dec 2018 23:48
I get no problem with deleteallimages()
because i delete all sprites and delete all objects first
It says you must do this in the help file first otherwise
the engine still attempts to call a sprite with an image
that dont exist. Because its at the end of your code
doesnt mean it still wont error. I hope that clarifies

fubar
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 7th Dec 2018 00:18 Edited at: 7th Dec 2018 00:19
I always like to be in control of resources, but would really like a function that returns a list of <assigned> objects, images and the like, as DeleteAll<whatever> isn't always handy for stuff you want to keep resident - especially dynamically generated stuff.
Oh yea, and there's the resetting of the dynamic index which is only reset by Deleteall<stuff> if I recall.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 7th Dec 2018 01:12 Edited at: 7th Dec 2018 01:15
fubarpk that's what I figured. I delete all tweens first because they are using sprites. Then I delete sprites. Finally I delete the images. I've started rewriting everything that uses tweens and the sprite animations to see if that is causing it. It will be a while before I know because for this game I decided to try to take advantage of more of the features so I used tweens and sprite animations for everything I could. So they are used all over the program.

It's interesting I think that if I don't attempt to delete images at all there is no error and the program exits cleanly but I don't know if AppGameKit is freeing up everything on its own.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 7th Dec 2018 01:43
It's fully managed, it should be
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 7th Dec 2018 02:43 Edited at: 7th Dec 2018 02:45
Thanks @Ortu! That is what I have been wondering. I thought it seems like it should be because I remember seeing in the documentation at various places things like if you use Tier 2 you will need to free up this and that yourself but in Tier 1 it is handled for you. So I thought it should apply to this stuff too but just wasn't sure.

I have removed the use of sprite animations and tweens completely from the Enemies and the explosions and am currently working on the player GUI cursor, etc.

One nice thing is that code is much leaner now. Previously I had a bunch of code just to check things like if not SpriteTweenPlaying then.... and if SpriteTweenPlaying stop it, clear animation frames then load with new animation frames (inactive sprites being reused for a new enemy), etc. It's interesting because I always felt this kind of stuff added a little more complexity as in more things to handle and by converting it all to just my own code I can see that is really true. I'd say the new code does the same things in about half as many lines just due to not trying to check everything and clean up as needed because there is nothing to clean up doing it this way.

Well I will continue on I guess at this point. I am curious if removing all of this stuff will make it so the DeleteAllImages/DeleteImage issue goes away so might as well continue on and see.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 7th Dec 2018 03:03
i tend to implement my own handlers for those types of things as well. I guess i just like having full manual control over things like animations, transitions, and interpolations. Thats one thing that initially gave me some trouble with 3d animation in agk, it doesnt have the same fine grain manual control command set for working with frames that dbpro did. i dont want to work with animation in time, i want to work with it in frame and I will handle time myself. I've got it worked out the way I want it now, but it isnt as straightforward as it was in dbpro.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 7th Dec 2018 04:29
I understand that completely for sure! This is the first time I have used the sprite animation or the tweens. I wanted to try them because if it did make things easier then be silly not to use them. But having tried them I think my normal way is more efficient plus like you said (a huge part of why I always code my own stuff) I have complete control and know exactly what is going on and why.

Anyway, I have narrowed it down finally to the enemy bullets. The best I can figure at this point is the problem is caused by having a sprite that has an animation using sub images from one atlas image and then later clearing those out and replacing with an animation using sub images from a different atlas image. Again that is just a guess. All I know is when I completely comment out both the bullets normal animation and the bullet impact animation code the issue goes away. Maybe that is it. Maybe a sprite is not supposed to alternate back and forth between animations using sub images from different atlas images. I don't know really. Tomorrow I will recode the EnemyBulletManager to handle those two states of animation myself and hopefully that will be the end of it.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 7th Dec 2018 04:43
have you tried deleting the tweenchains prior to deleting sprites DeleteTweenChain( chainID )
fubar
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 7th Dec 2018 05:17 Edited at: 7th Dec 2018 05:19
I don't use any tween chains just had many simple tweens. A tween for moving the enemies from waypoint to waypoint on the path (could have used a tween chain for that but I just handle it one waypoint at a time), a tween for the color cycle FX on the cursor, etc. It looks like it is actually the animations causing it.

Anyway yes I delete everything... I'd have to post code for folks to get how thorough it is being cleaned up. I am literally even looping through millions of IDs checking if a tween exists if so is it playing yes then stop it, then delete it. Same for sprites looping checking if exists if so checking if playing an animation if yes stop it then if needed clearing animation frames then deleting the sprite.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 7th Dec 2018 05:43
Make sure you exit any loop where tween,gyros and gps etc are exited for deleteing after the sync in the loop.

This is to make agk execute anything in memory before terminating.

I had the same errors with gyros on mobiles before i started to do this..

This also is the same for the end command to be sure.


do

sync()
Here do we exit the loop for deleting
loop
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 7th Dec 2018 14:40 Edited at: 7th Dec 2018 15:14
Thanks @Cliff. I actually do that too.

Basically I have Program State which is the high level loop this passes control to TitleState, GamePlay, GameOver functions. Each of these state handling functions begin by loading & creating resources except for images which I changed due to this error to be loaded one time before the upper level loop is entered and freed after that upper level loop exits which is when the program ends. Anyway, the state specific loop handles processing for everything in that state of the program... and then when that loop exits all of the resources created & loaded before that loop entered are released

I also discovered the issue you are talking about and handle that as well. I found that some things such as deleting sprites, etc do not actually occur when you delete them but instead seem to only be released after calling either sync() Update() or update2D() in this case. So after deleting sprites I call update2D to apply those changes. After the upper level loop exits I call sync() to apply all deletes before trying to free the images. I tested that by deleting sprites, etc and using the benchmarking functions and saw the sprites count had not changed until the next time sync / update was called.

I have no way of knowing but I guessed that deleting tweens is not applied either til the next call to UpdateAllTweens() so I call that and Update after stopping and deleting the tweens which was done before handling sprites which was done before handling images.

I have thoroughly tested things trying to find it and found some interest behaviors like things not actually being deleted until the sync / update is called. But in the end I can make the error go away by either not trying to delete images at program exit OR by removing all animation from the enemy bullets. The only difference there from everything else is the enemy bullets use an animation with images from one image atlas for their bullet moving state and then upon impact (hitting one of the player's defensive units) that animation is stopped, the animation frames are cleared, new animation frames are added using images from a different atlas image and that impact animation is played.

I am going to just recode the bullets tonight to not use the built-in animation system. I am guessing it is the stopping an animation, clearing animation frames, adding new frames using images from a different image atlas and then playing that animation all within the same frame with no update or sync between the release of the one set and the adding and playing of the new set from a different image that is causing the issue. But that's a very common pattern for a game. I could make an intermediate state so the bullets wait one frame after releasing move animation but makes more sense to me to just code it myself without messing with the animation system at all.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 7th Dec 2018 20:14
We don't know if that is actually true about sprites and ao forth not actually being deleted until the next sync/update. It could very well be those numbers in the benchmarking are just stored from the last update and that is when the objects are counted while they are being processed. I think that may he what happens and the benchmarking may not actually be doing a count at that instant and instead using the value that was stored during the last update. Who knows really but not using the animation and other systems just seems like the best way to go.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 8th Dec 2018 01:10 Edited at: 8th Dec 2018 01:11
Just thought I'd follow up and share that coding the enemy bullet moving animation and impact animation myself removing the use of the built-in animation system resolves the issue.
The exact same sub images from two different atlas images are still being used it's just that now I am only calling SetSpriteImage. So just something to keep in mind if you ever run into this issue.
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 11th Dec 2018 21:18
If you can create an example program that replicates the crash I can use the debugger to track down the line that caused it, which should make it a simple fix.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 13th Dec 2018 17:50
Thanks Paul I appreciate that. I may try at some point to recreate the issue with a tiny program. But at this point I have it resolved and all working and am focusing hard on release. Just a much higher priority for me.

If I do revisit the issue and reproduce it at some point I will update here with a sample project.

Login to post a reply

Server time is: 2024-03-29 10:48:00
Your offset time is: 2024-03-29 10:48:00