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 / AGK 108 stability with large projects

Author
Message
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 12th Mar 2015 07:30
So I'm still on AppGameKit V108, to preface this. I'm sure a number of other people are, too. I was wondering if anyone has had any experience working on "larger" projects in AGK. I have a project with maybe 4000 lines of code across 21 files, and it's started to become pretty unstable. Some days I'll have random crashes ("Program has stopped working"-type crashes) about 50% of the time I execute the program. I've also run into bizarre cases where commenting out a specific line of code seems to fix the crash - but adding a seemingly irrelevant statement (like a print) nearby can sometimes also fix it.

So I have a couple of questions:
- Has anyone else worked on a project this large? Have you had problems, or was it fine? What about in V2 - does this improve?
- Is there some way I'm unaware of that I might get more information from these crashes?

Thanks for any help.


On Steam!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 12th Mar 2015 08:26 Edited at: 12th Mar 2015 08:28
Quote: " I have a project with maybe 4000 lines of code across 21 files"


I have a project with around 8,000 lines (in 20 files), and it runs OK in V1.
I don't think the number of lines is important. It's what you do with them!
I have a background in optimising code, so most things I do are quite efficient. For example, arrays are never bigger than they need to be and they get expanded in blocks of elements rather than one element at a time. Everything that gets loaded is unloaded at the appropriate time.

It might be time to take a look at your code and see where it can be streamlined.


Quote: "I've also run into bizarre cases where commenting out a specific line of code seems to fix the crash - but adding a seemingly irrelevant statement (like a print) nearby can sometimes also fix it"


Yes, that one is weird and I've also had it before. I haven't experienced it in V2.

Quidquid latine dictum sit, altum sonatur
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 12th Mar 2015 15:38
Version 2 had its compiler rewritten for this very reason and I've yet to hear any similar issues with it, so I think those days are behind us. Unfortunately repairing the old compiler would be too much of a challenge and I would recommend you upgrade to version 2, your code should continue to function the same.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 12th Mar 2015 15:54
We sometimes come across issues with EatDrinkSlay - which is huge by now, probably 10,000 lines at least. We did instil some practices like Batvink has, which makes a big difference - usually a crash will be about a sprite not existing, whereas before we'd get the silent crashes.

Some things we do to try and avoid errors:

Arrays and media are cleaned out as much as possible, like clearing out game media when going back to the main menu.

Function parameters are stored before being passed - mostly we avoid referencing arrays (esp typed arrays) in function calls.

Checks to ensure that arrays are never overflown - like with fixed size arrays especially.

Decide on an ID allocation system and stick to it - for example sprites, either use fixed ID's or auto-ID's, but don't ever mix the 2... same applies to images and objects and anything that has auto-ID. Personally I'd say that any project over 1000 lines should avoid using auto-ID's, it just becomes too messy and unpredictable - make your own media ID system that you can easily add extra control functions to, replace the AppGameKit auto-ID with your own custom one... I mean we end up having to keep track of ID numbers in arrays regardless, so might as well go the whole hog.

Be mindful of the order that you delete media in, I mean if your gonna delete an image, make sure any sprites using that image are deleted first.


Some of this stuff will have no positive impact, but it's a safety thing to avoid the possibility of issues. The project is going onto AGK2 soon which should make things much easier to work with, especially once that debugger makes it in - but I really think it's a good idea to get your project working as best it can in v1 first - because at least then you know that any issues are new issues, not just old bugs that v1 might not have been reporting very efficiently.

I am the one who knocks...
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 12th Mar 2015 16:21
Quote: "Personally I'd say that any project over 1000 lines should avoid using auto-ID's, it just becomes too messy and unpredictable"


Just curious, why would you entertain creating your own ID system? What benefit would that add? I've only ever used the Auto-ID system (even with +1000 line projects), hence my curiosity

Using AppGameKit V2 Tier 1
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 12th Mar 2015 16:41
I use auto-IDs, but they are all stored in an array with other related information. So I never have a rogue element that I can't track down.

Quidquid latine dictum sit, altum sonatur
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 12th Mar 2015 16:53
I think the main benefit is keeping track of ID's. For example, a particle system that uses sprites, you could let AppGameKit designate the ID's itself, but you'd have to keep track of them in an array, you'd have to reference that array every time you wanted to update the sprite and also ensure that the sprite ID is maintained throughout.

It's a lot of extra code for a system that is supposed to make things less complicated.

So I'd just use a range of sprites for those particles, say sprite 500 to 1000, and I'll always know what the sprite numbers should be - I will know that sprite 500 is the first particle and nothing else, if that sprite doesn't exist then particle 0 doesn't exist. I think it makes things much easier to maintain but it also allows for more efficient collision detection. I mean, if your checking a sprite for collision against several other sprites, auto-ID's might well obfuscate that, like I am guessing that a small range of sprites in a sequence is better for cross reference checks - but if you have spurious auto-ID's happening, the sprites might not have a distinct or convenient ID order. It's easy to cycle through sprites 500 to 1000 and know that they're all particles and know exactly how a sprite should be re-created or handled separately from it's controlling array (which doesn't even necessarily exist). I mean, what if particle 0 gets ID 500, then particle 500 gets ID 32,002 - Does a collision check have to go through that whole range?, we just don't know how efficient the collision list is, so we have to best guess and try and enforce the logic that works for us.

Mainly though, the thought of having everything spuriously identified scares me, I think I have auto-ID trust issues

I am the one who knocks...
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 12th Mar 2015 16:59
IanM had a nice system in DBPro. You could ask for the next ID in a given range.

Quidquid latine dictum sit, altum sonatur
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 12th Mar 2015 17:11
Quote: "I think I have auto-ID trust issues "


Lol...

I think perhaps this discussion may well be out of my depth :-| and this is where I may make myself sound like a wally lol, but what I don't understand, is why would you ever need to reference ID's at all? I mean, when creating sprites you provide a variable name, right? Like so;



So any future collision detection would be simply;



It doesn't matter what the ID is and/or whether it is sporadic as I do not reference an actual ID?...

Using AppGameKit V2 Tier 1
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 12th Mar 2015 20:33
I have had projects why bigger then 4,000 lines of code. That should actually be an average range for an app size.

Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps. Developed the tiled map engine seen on the showcase. Veteran for the military.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 13th Mar 2015 03:58 Edited at: 13th Mar 2015 04:00
Thanks for the tips, guys. It's good to hear the V2 is fixing this stuff (and getting a debugger!)

Do you think that unloading unused assets helps? I load up everything at startup and I never unload it - it can take some time, but it seems a lot simpler and less error-prone than trying to keep track of loading and unloading on the fly.

I do use auto-ids for everything - I just store them with the appropriate data for those objects. Your tip about passing function parameters is probably one I should try, though. I know I've had some problems when passing around UDTs or fields of UDTs in the past.


On Steam!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Mar 2015 11:45
Quote: "It doesn't matter what the ID is and/or whether it is sporadic as I do not reference an actual ID?"


I use the same method as you describe Funnell7, but I see what VanB is saying. We don't know if checking collision on sprite 10000 and 11000 requires a check of 10001 to 10999 also. I doubt it does, but it is unknown to us.

Quote: " I load up everything at startup and I never unload it - it can take some time, but it seems a lot simpler and less error-prone than trying to keep track of loading and unloading on the fly."


you may load and unload at known times, but the operating system may also be loading and unloading in between, because there is too much to put into memory. You should minimise this as much as possible by unloading resources when you want to, within your control.

Quidquid latine dictum sit, altum sonatur
Jambo B
15
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 15th Mar 2015 03:06 Edited at: 15th Mar 2015 03:07
One rule I really try to live by is:

"As soon as I write code which creates or loads a sprite/image/anything else, I write the code which deletes or cleans it up as well."

On the times when I haven't done that (late-night coding/too tired to do it properly/just want to get it working/etc.) it has come back to bite me royally on the backside.

Cheers,

James
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 15th Mar 2015 11:06
Quote: ""As soon as I write code which creates or loads a sprite/image/anything else, I write the code which deletes or cleans it up as well.""


Good advice, whenever I create a scene, for example the TitleScreen, the first thing I do is;



And then do exactly as you say...

Using AppGameKit V2 Tier 1
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 15th Mar 2015 18:16 Edited at: 15th Mar 2015 18:17
Quote: "One rule I really try to live by is:

"As soon as I write code which creates or loads a sprite/image/anything else, I write the code which deletes or cleans it up as well.""


I've given this advice so many times

Quidquid latine dictum sit, altum sonatur

Login to post a reply

Server time is: 2024-11-25 18:50:54
Your offset time is: 2024-11-25 18:50:54