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 / Unhandled exception dim array

Author
Message
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Feb 2014 13:12 Edited at: 21st Feb 2014 13:14
Hi guys, I'm getting a very strange bug when I re-dim an array. It only seems to happen when I put a number of my light sprites in a scene and delete them in a particular order but I've checked the value I'm passing into the dim command and there's nothing wrong with it.

If I use my deleteLight function (below) when there are 4 items in my array to delete items 3,1 then 4 I get a crash :


I'll be sending the bug to Paul for checking but as yet I have been unable to replicate the bug in a simple example and my current project is around 5,500 lines so I'd rather not bother him until I have something easier to debug. I just thought I'd share in case anyone else is pulling their hair out...

oct(31) = dec(25)
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 21st Feb 2014 13:41
inside deleteLight(i)
i do not expect the use of i
lightID = i
player.light = i
litSprite[l].light = i

my suggestion is also,
do in a function only what the function name say.
means better split into more functions.

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Feb 2014 13:42
Ok, I get it replicated in this code. If you insert four sets in the following order: top-left, top-right, bottom-left, bottom-right. Then delete them in the following order: bottom-left, top-left, bottom-right [HERE IS WHERE MINE CRASHES]...

Now, it may well be that the cause is a bug in my code but the unhandled exception needs sorting.


I get this bug in V108.19 & V108.21 tested on Windows 7 64Bit.

oct(31) = dec(25)
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Feb 2014 13:46
Quote: "inside deleteLight(i)
i do not expect the use of i
lightID = i
player.light = i
litSprite[l].light = i"

Why not?

Quote: "my suggestion is also,
do in a function only what the function name say.
means better split into more functions."

I'm not sure how that helps with this bug but actually that's all I'm doing. deleteLight just deletes a light from my scene... everything in the function relates to that one operation.

oct(31) = dec(25)
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 21st Feb 2014 13:57 Edited at: 21st Feb 2014 13:59
(split into more functions bring order into.)

because u said delete the light i,
for me this one did not exist anymore.

same here, you put data in i


AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Feb 2014 14:06 Edited at: 21st Feb 2014 14:06
I'm deleting the light then moving the data from the end of the array 'lightNum' down to replace the data at 'i'. Then I just make the array one slot smaller to remove the data from the end. It's not that complicated once you get the hang of it. Unfortunately you can't just remove a single slot from an array in agk so you have to move the data around manually.

Yes I am deleting i but I am replacing the data in i from the end of the array rather than shuffling all the data along. I've been doing it this way for a long time and normally it doesn't glitch out.

oct(31) = dec(25)
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 21st Feb 2014 15:52
ah, understand.
i will try your example later.

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 21st Feb 2014 16:09
I probably wouldn't bother re-dimming for the sake of one or two lights - especially if it involves moving data.

Typically for array work like this I have a field .inUse, which I set to zero if the record is not used.

For reference, here's my standard array management functions - I use this regularly and all over the place so the code is as tight as it gets;

(this example is for adding and removing buttons)
Buttons.max is the array limit
Buttons.top is the last currently used entry
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Feb 2014 16:25 Edited at: 21st Feb 2014 17:08
I wouldn't bother re-dimming either if it was going to affect performance but I'm only going to delete a light occasionally, like maybe once per second if someone goes crazy in-game.

I also use an "in use" method for more regularly re-dimmed arrays such as particle arrays but it's really not necessary here.

I'm not really looking for coding tips (thanks all the same), I just wanted to let you all know that if you were having a problem with an unhandled exception it might be caused by this bug.

Whether the bug is triggered by my code or not is almost irrelevant but it would be nice if someone spotted the trigger rather than pointing out different methods of coding which I'm sure most of us have 'better' ways to code this one example.

EDIT: Sorry if I sound ungrateful I don't mean to.

EDIT 2: Getting this same crash in a number of places now...

oct(31) = dec(25)
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 21st Feb 2014 19:09 Edited at: 21st Feb 2014 19:10
i think at delete your pair array is wrong.
after delete all sprites/lights i still see there are a id and sprite id.
maybe forgotten a delLightPair, the replaceLightID function looks odd.
at test sometimes the corona sprite was not delete.
u use findLightID in this wrong pair array.



AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 21st Feb 2014 19:38
Quote: "EDIT: Sorry if I sound ungrateful I don't mean to."

Not at all, I wasn't meaning to teach grandma to suck eggs - I've been here long enough to know your coding skills.

Besides I know how frustrating these things are, sometimes you just want to chuck it and start again.

Which is why I put the "for reference" part, it was mainly for the benefit of anyone else who needs to follow along.

Quote: "EDIT 2: Getting this same crash in a number of places now..."

Related to arrays or in other places?

You mention "CRASH OCCURS HERE WHEN lightNum HAS A VALUE OF 1", presumably post Decrement.

Here's an idea out of left field..

Have you tried replacing the dec with a subtract - I've still got doubts about inc and dec myself - in case it's not the redim, but the value its getting

or... perhaps replace with

for debugging purposes.
The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 21st Feb 2014 21:38
Why not create a new array with the same number of elements as your list containing the light you wish to delete minus 1...


Then copy the elements you want to keep from 'old' array (not copying the light you want to delete)...

So new array has ONLY the elements you want to keep.....then delete the old array?


Maybe too slow but a simple solution?

www.bitmanip.com
All the juicy you could ever dream of!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Feb 2014 11:31 Edited at: 22nd Feb 2014 11:33
I haven't pinned it down completely but it seems related to this, it's an extract from a debug log I created:



The last deletion tries to delete sprite 1951426586. You can see at the top it was created as 10048.

I can't reproduce consistently, here I created 24 lights before it broke.

I observed another error where the small sprite was deleted, and the larger transparent one was left behind. Interestingly in this scenario the log shows no redimming (an extra log line I added after the one above was taken)This example shows a good delete followed by a bad one. You can also see the program doesn't crash and allows me to add another light:



[EDIT] I also just noticed, the sprite hit isn't registered either for this scenario.

I think as someone mentioned the dec, inc commands can be flaky. I replaced those but it still broke.

You can't run this directly but here's the code with my debug lines, so you can see where they were:



baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 22nd Feb 2014 11:45
Thanks for the help guys! Batvink, seems like there's a problem with the dim command not replacing values correctly to me. This is the first major bug I haven't been able to avoid somehow and it's got me so frustrated I've even downloaded the latest version of Unity with a view to moving the project over. I don't really want to do that but I really am bored of this bug now... it's actually stopped development.

In the meantime the only other option I can see is to dim the array once and have a maximum number of lights in a scene. Not ideal and it doesn't solve the issue. Maybe I'll start using memblocks and create my own array system somehow...

oct(31) = dec(25)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Feb 2014 12:05 Edited at: 22nd Feb 2014 12:20
I think it is a bug, and I think it is because you are using a typed variable in the array.

As a workaround you could have a set number of elements as you suggested (more than you need, they aren't taking up very much space). Have a second array that lists only the active lights by array index number. This array should contain all the indexes, with active ones at the beginning and inactive at the end. Add an extra variable that saves the position of the last element in use.

Practically, you do all your element swapping in this secondary array. Because you are only swapping an integer, it's more efficient. You never delete data from your primary array, you just overwrite it when you reuse it.




[EDIT] in this example, if you deleted light 7...

Swap element 3 and 5 in the second array
set LastActiveLight to 4
element 5 is now red (light 7 inactive)
because light 3 is now in element 3 you still have a consecutive list of active lights.

[EDIT 2]
I use this method all of the time in AppGameKit and it never fails. I have scenarios where I have up to a hundred elements being switched in and out every few frames, as it controls my effects (fade ins, rotations, movements etc). I also redim the arrays to make them larger (never smaller). If I run out of elements I increase by 10% at a time.

Maybe shrinking the array with a typed variable is the problem, leaving uncollected garbage behind?

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 22nd Feb 2014 14:24
Good idea Batvink but for now it's only really an issue in the Level Editor as in levels I have a good idea how many lights will be in each level as it is loaded.

It's a pretty major bug nevertheless.

oct(31) = dec(25)
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 22nd Feb 2014 17:35
I don't think Paul will get to this bug until he gets started on the compiler. Which is part of the v2 roadmap, stretch goal 2 from the Kickstarter. OUYA support should be the only thing remaining on stretch goal 1.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Feb 2014 12:35
I hope you're wrong DA, it's looking pretty serious and it's in V1 & V2.

I just changed my code so I dim only once at the start and suddenly a whole bunch of my repeatable bugs just vanished. Re-dimming arrays is completely broken as far as I can tell.

For now I can live with it because there is a really dumb workaround (IE. dim all arrays to be maximum size all the time) but if this bug isn't fixed soon it may well tip me over to a new engine which would be a shame because I am AppGameKit all the way as most of you know.

This bug breaks most of the systems I've been building up for this game; animation, lighting, particles etc. These are not easily replaced using this workaround. Also I can't afford bloating the memory usage on this game as it will be heavily media intensive and hard to run lean as it is.

I can only assume that nobody is using arrays to the extent I am because I can't turn around without hitting a wall at the moment.

oct(31) = dec(25)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Feb 2014 12:49
Quote: "I can only assume that nobody is using arrays to the extent I am because I can't turn around without hitting a wall at the moment."


I am, but with a significant difference. I only ever expand arrays, never decrease them. I believe from my experience that increasing them is not an issue. This would suggest a memory leak when removing elements and the old data not being cleaned up.

So...can you manage with a scenario where you only increase? Let's say your default scenario only needs 10 elements, but you may need 100. Can you start with 10, and increase 10 at a time where necessary? I often end up with lots of empty elements as the demand decreases, but all of my apps can adapt as necessary.

There is another option which I believe will work. Where appropriate and all data can be deleted (e.g end of a game or level) you undim the entire array and start again. I do this also and it seems to handle the removal of the complete array well.

Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 24th Feb 2014 13:13
Lee wrote the compiler. And part of the plan for v2 was that Paul was going to take time to learn how it works. I have asked Paul about the dynamic lists quite some time ago, and that's what he told me. If it's an easy fix, like the one with passing UDTs to functions that I fought for. Then maybe they can fix it earlier.

Since AppGameKit doesn't have the dynamic lists of DBP, I decided from start to go with fixed array sizes. I have not tried redimming arrays at all.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 24th Feb 2014 13:47
If you go upwards it will screw up. Bax does not show us the original code that calls the function, but I suspect it's going up, not down.

-- Jim - When is there going to be a release?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Feb 2014 14:26
I am adding and removing items. It's after I remove an item that it gets screwed up. I could only increase the array sizes but I think I'll just wait for a fix in AppGameKit because I honestly don't want to edit my entire engine to avoid this one stoopid bug.

Being able to dynamically store data is vital to programming anything more complicated than flappy bird so I'm stuck. I guess it's a question of what I decide to do while I wait. I have a few ideas and none of them include AppGameKit unfortunately.

oct(31) = dec(25)
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 24th Feb 2014 16:23
Yes, Bax. But are your removal routines solid along the lines I've mentioned above?

-- Jim - When is there going to be a release?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Feb 2014 17:37
JimHawkins, I can confirm from my tests up above that it's the dim statement that causes the crash when you are reducing the array size. I had exactly the same thoughts as you and went looking for a moment of glory when I came in with the easy fix. I was thwarted but at least my attempt backed up the cause.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Feb 2014 19:26
Quote: "Yes, Bax. But are your removal routines solid along the lines I've mentioned above?"

The code is all there and I'm using a system I've been using for years now. There is something squiffy in either moving data from one part of an array to another or in re-dimming an array.

I was hoping for someone to spot something stupid in my code and would have been happy for them to do so because my eyes were going funny and it would not have meant abandoning the project for the time-being.

oct(31) = dec(25)
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th Feb 2014 21:16 Edited at: 24th Feb 2014 21:22
i believe this problem occur because moving (and then wrong) indexes.
i had rename and edit something for better understanding (also for myself).
this did nod crash at me:
with this test= condition at mouse clicks, i had paint 10 seconds
and then i delete all with all lights gone.
please try if you can crash this example.


AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Feb 2014 22:41
Markus, your version doesn't crash for me but it also doesn't change the size of the pair array back down after a pair is deleted. It could be that this is where the error is but I need all arrays to be dynamic. I have a version that does not crash if I do not redim the arrays. I have not changed the way the arrays work or how the indexes are changed in my version so it is not the indexes that are wrong it is something that only happens when the array is redimmed.

Thanks for the effort though, it is appreciated. There is definitely an error in AppGameKit here.

oct(31) = dec(25)
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 24th Feb 2014 23:43
Bax:
I can't seem to replicate your problem. I always do these little test programs to isolate bugs. Have a look.



Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 25th Feb 2014 00:06 Edited at: 25th Feb 2014 00:09
baxslash,
i did not saw you resize the pair array before, in your example.
the light array redim up and down.

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 25th Feb 2014 08:26
DA, yes your example works fine but perhaps a simple example does not have the same problem? I'll be very happy if you can find it is just down to a bug in my code but if it is I can't find the bug. Maybe I spent too long looking at it.

I don't get this issue in some of the simpler array systems in my code either, perhaps it's because of the number of items in the UDT?

If I get time I'll do some more tests on my 'simplified' version of the code tonight. See if I can't pin it down further but I'm late home from working away tonight...

oct(31) = dec(25)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Feb 2014 08:40
Quote: "I don't get this issue in some of the simpler array systems in my code either, perhaps it's because of the number of items in the UDT?"


It is going to be something weird, such as the sequence of fields in the UDT. For example it may need a string between two integers. I have tried a few combinations, as well as adding to the array again before completely deleting all elements, and running it 100 times over. Code below if anyone wants to keep adding to it until it breaks.



Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 25th Feb 2014 08:44
baxslash,
before your example crash if i add lights(sprite pairs) 1 2 3
and then remove 1 2 3 in this order, (i believe), sometimes
one sprite did not delete, sometimes crash.
but there was chaos in pair array.
i still don't know why agk crashed in this example.
but it maybe interesting for paul to look at to improve agk.

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670

Login to post a reply

Server time is: 2024-11-25 02:44:14
Your offset time is: 2024-11-25 02:44:14