Peculiar Structure Array Bug

Hi, a description:

- It's a 3D structure array, like voxels[x][y][z].
- It has been constructed correctly by an array of pointers to pointers to pointers to the structure and its already completely in memory.
- It always occurs at the last element, like given size 100, when x = 99.
- I can always access it once! Upon which I change an integer member from 0 to 1 in the structure by using ++. Like voxels[99][0][7].genericInteger++;
- I cannot access it a second time! It says I'm illegally accessing that memory location. Exact report:
... raised exception class EAccessViolation with message "Access violation at address 004288B6. Read of address 00000190'.

- BUT the debugger (when hovering my mouse over the variable) CAN retrieve the correct value of the integer member, which means somehow he is legally accessing it to give me the value.

This is a really frustrating bug since it's filled with so many contradictions that I cannot pinpoint the cause myself.

Any knowledgeable input from more seasoned programmers?
The access violation is always right while the debugger might not (due to the debug changes).

You should find out the 'path' that leads to the problem. It may help to output/printf a certain number(counting 1,2,3..) after each line. So you might see that '4' is supposed to appear but doesn't always (as an example)
Even in the debugger it throws the access violation. It might be giving me the false impression that it can fetch the value, but it still accesses the location correctly once, and then fails the second time.

I do know the path. It accesses each voxel and marks it with a 1 (or later 2, 3, ...) whenever it passess, until a certain number is reached. It might access the same voxel the next iteration, or hundreds of other voxels later.

The problem is after marking that specific voxel for the first time, it fails to access it a second time. And this only occurs for this last voxel, since other voxels (like [0][0][0] get accessed multiple times correctly).
Last edited on
I do know the path.
doubtful. If you knew what's really going on everything would work fine.

The problem is after marking that specific voxel for the first time, it fails to access it a second time. And this only occurs for this last voxel, since other voxels (like [0][0][0] get accessed multiple times correctly).
You said that already. Don't cling to much to such an effect it's often misleading.

Try the common approach: Something is going wrong that affects your array. It might be very well an indirect effect. So you really have to watch the whole execution (path) until the crash. Bear in mind that the error takes places before the crash and you don't know how far before.
Bear in mind that the error takes places before the crash and you don't know how far before.


I don't see how accessing the array can invalidate it. Only accesses occur, and the only write is an integer that is sporadically augmented.

It might be very well an indirect effect.


That's why I'm asking here, if you guys know of a way in which reads can actually invalidate arrays, or change them, or modify their memory locations, etc... I sure won't figure it out myself because I simply never worked with this language before.
All I see is that it's the same 20 lines of code being run and rerun over and over, and none affects the array except by reading it and incrementing an integer.

Last edited on
According to your first post, you don't simply access it, but increment a value. Since you say you only need to set an int from 0 to 1, try using the assignment operator instead. Better yet, try printing the values, then incrementing, then printing again. With sufficient info in your prints, you'll be able to see at which step it goes wrong.
Found it. A check used && instead of ||, which caused the array to access faulty locations....
Last edited on
Topic archived. No new replies allowed.