I've got a general, hand waving sort of question here. In the video game we're working on we have a bunch of AI cars running around. These are all stored in a 1D array AICars() of a TYPE that is quite large. In a previous version of the game any time you change the number of AICars() I simply REDIM'd the array, zeroing it out, then reset the cars' positions and so forth one at a time. Recently what I wanted to do is REDIM PRESERVE this structure instead so we could add or remove a car now and then without changing the states of the previously created cars.
For some mysterious reason though I've been having serious problems doing this. At the moment REDIM PRESERVE is called everything is fine and works as advertised. The previous elements in the array are preserved if the array is increased in size, and if it's decreased in size the upper end elements are eliminated.
When I do this, however, later on the main game loop I start getting the typical nonsense indicative of bad pointers (there are no pointers in the AICar structure) and out of bounds arrays. One concrete example is the position (AICar(i).Position, basically). Immediately when REDIM PRESERVE is called, everything is fine. The first time through the game loop the position gets updated correctly. The second time through the game loop when it gets to the position update:
AICar(CurrentAICar).WorldPositionVector(%X) suddenly becomes 0, as does (CurrentAICar).WorldVelocityVector(%X). Immediately before this line I write the position to a debug file and it is not 0. So I am seeing 10 + 0 = 0. I've tried getting around this by storing the position to another variable, storing the additive term to another one, then adding them together to a third, and finally setting position equal to this at the end of it, as well as several other workarounds, all to no avail.
My question, besides the obvious "what the heck could be happening here to make 10+0=0" is this:
If I REDIM PRESERVE a big enough array (maybe a MB or so), and I then enter a very large function, is it possible there could be some stack corruption going on? This crazy mathematical glitch (and others later on in the code; this is just the start of the ensuing avalanche) does not occur unless I PRESERVE the structure as described. It also does NOT happen the first time through the game loop after the REDIM PRESERVE was exectued. Only the second, third, etc.. This happens identically with both PB8 and PB9, so I doubt it's a compiler issue. As my associates say: "the problem is between the chair and the keyboard"
If it's possible there's a stack corruption issue here at play, what sort of things should I be looking at to figure out what I'm doing wrong?
My newly beloved #DEBUG DISPLAY ON triggers no out of bounds, bad pointers, etc.. No errors at all. This one has me really scratching my head and we're going to have to make a (very minor) game design change as a result of it if I can't solve it. Either way, it's just a frightening thing to me that this sort of thing can happen even when there's no out of bounds stuff happening. Has anyone else had similar experiences or have tips on what to do to minimize the risk of this sort of thing?
Thanks
For some mysterious reason though I've been having serious problems doing this. At the moment REDIM PRESERVE is called everything is fine and works as advertised. The previous elements in the array are preserved if the array is increased in size, and if it's decreased in size the upper end elements are eliminated.
When I do this, however, later on the main game loop I start getting the typical nonsense indicative of bad pointers (there are no pointers in the AICar structure) and out of bounds arrays. One concrete example is the position (AICar(i).Position, basically). Immediately when REDIM PRESERVE is called, everything is fine. The first time through the game loop the position gets updated correctly. The second time through the game loop when it gets to the position update:
Code:
AICar(CurrentAICar).WorldPositionVector(%X) = _ AICar(CurrentAICar).WorldPositionVector(%X) _ + AICar(CurrentAICar).WorldVelocityVector(%X) * TStep
My question, besides the obvious "what the heck could be happening here to make 10+0=0" is this:
If I REDIM PRESERVE a big enough array (maybe a MB or so), and I then enter a very large function, is it possible there could be some stack corruption going on? This crazy mathematical glitch (and others later on in the code; this is just the start of the ensuing avalanche) does not occur unless I PRESERVE the structure as described. It also does NOT happen the first time through the game loop after the REDIM PRESERVE was exectued. Only the second, third, etc.. This happens identically with both PB8 and PB9, so I doubt it's a compiler issue. As my associates say: "the problem is between the chair and the keyboard"

If it's possible there's a stack corruption issue here at play, what sort of things should I be looking at to figure out what I'm doing wrong?
My newly beloved #DEBUG DISPLAY ON triggers no out of bounds, bad pointers, etc.. No errors at all. This one has me really scratching my head and we're going to have to make a (very minor) game design change as a result of it if I can't solve it. Either way, it's just a frightening thing to me that this sort of thing can happen even when there's no out of bounds stuff happening. Has anyone else had similar experiences or have tips on what to do to minimize the risk of this sort of thing?
Thanks

Comment