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 / Problem resizing empty array

Author
Message
Eqqman
9
Years of Service
User Offline
Joined: 15th Jul 2015
Location:
Posted: 5th Mar 2017 07:29
Given this type where member vtx is an array:

I use this type as a member of another type. In this block of code:

The operation crashes when attempting to adjust vtx.length since object vtx is empty. However, if I uncomment the do-loop, this exact same command works correctly in there. Given that this was an issue, I also attempted to rewrite the `map.tiles[r, q].vtx[v] =` command to use vtx.insert() instead, but I get the same crash. The error complains about addressing element 0 in an empty array, and by using Print statements I can confirm that only array vtx is empty at this point in program execution, yet operations that should be fine to use on empty arrays fail here. I'm not sure if this is a bug or I'm just doing something wrong.
Goo Goo G\'Joob!
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 5th Mar 2017 16:00
Normally to resize an array you simply define it again at the larger size. In DB you had an undim command, but in AppGameKit as far as I am aware it doesn't exist and you simply re-dim the array. Generally I dim the new array size and then re-setup the array data again all over to avoid any issues. Looking at your code I am unsure what you are doing exactly, it looks a little oddly structured to me, why have a do loop inside a for next loop? In this case, inside 2 for next loops? I'd definitely look into replacing that do loop with another for next one myself, once it hits that do loop it's not going anywhere.

Q6600. Nvidia 260GTX. 8 Gig Ram.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Mar 2017 16:31
Quote: "why have a do loop inside a for next loop?"

I assume he just did that for testing purposes?

Can you show us where you define/initialize map? And are you certain the error is with the vtx array and not tiles?

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 5th Mar 2017 18:12
I was trying to point to the fact that once in the do loop, the rest of the code is ignored, for ever. So obviously when you rem the loop in, the code will run fine (the for next loop will halt and the values set stay the same). Rem it out and it will crash due to actually trying to read data that doesn't exist. Even for a test I see no point of a do loop in that part of the code, it completely negates the rest of the code. The error is definitely somewhere in the actual array setup somewhere I would imagine. It's difficult to diagnose a fault like this with just snippets I'm also really rusty with AppGameKit

Q6600. Nvidia 260GTX. 8 Gig Ram.
GameDevGuy
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location:
Posted: 5th Mar 2017 21:20 Edited at: 6th Mar 2017 00:08
I see that the for loop for the q variable, is using the length of the first element of tiles.



Is there any possibility that in your code, the second dimension of map.tiles the length of map.tiles[r] has not been set for some values of r?

In other words, the problem is not related to vtx, but the tiles array, and should the code be like this?



Anyway, this is just a wild guess with some lateral thinking. Without knowing more about how the tiles array is setup, my hunch could be completely off the mark.
Eqqman
9
Years of Service
User Offline
Joined: 15th Jul 2015
Location:
Posted: 6th Mar 2017 07:33
Quote: "I was trying to point to the fact that once in the do loop, the rest of the code is ignored, for ever."

Yes. And as pointed out, that is only there for testing purposes.
Quote: "Is there any possibility that in your code, the second dimension of map.tiles the length of map.tiles[r] has not been set for some values of r?"

Possibly, but I used Print() statements to verify that the array lengths are nonzero for r, q = 0 where the crash occurs. Vtx is the only empty array, and as you can see the call to resize the array in the test do-loop and the "real" one are at the same levels of nesting in the for-loops, but one crashes and one doesn't.

Since I resize the vtx array anyway in my loops, I worked around this problem by changing the definition of vtx in the mpTile UDT so that it is nonempty. I was able to proceed with my coding but the mystery of why the resize didn't work eludes me, and this isn't the first time I've run into this situation.

Goo Goo G\'Joob!
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 8th Mar 2017 15:59
I couldn't replicate the crash using the code in your post, but there are bits missing meaning I may have set things up differently. If you can send me an example of it crashing I can use the debugger to find the cause.
Eqqman
9
Years of Service
User Offline
Joined: 15th Jul 2015
Location:
Posted: 10th Mar 2017 05:39
Unfortunately I re-factored the code to work around the crash, and I can't reproduce it in a new project. I didn't save it out separately in the bugged state.
Goo Goo G\'Joob!

Login to post a reply

Server time is: 2024-09-29 23:20:09
Your offset time is: 2024-09-29 23:20:09