> In your example the first dimension returns a pointer to a row, then the next is the offset into that row so your lookup needs to be grid[y][x]
Correct, it should be [y][x] indeed. I would have spotted that had I bothered to.
> Also you seem to be bounds checking for 0s, but to do that in the first dimension you need null pointers to pad your row selection and a second set of 0s at the end of your rows.
Not sure which is the first dimension but for an array of 10 if(arr[100]) returns false. Anything behind the && is ignored.
Looking at this again the really funny part is that it doesn't work if num = 0 since if(arr[100]) returns false if there is a zero at position 100.
> It's interesting that both you and the person you replied to used arrays of arrays which is the very first mistake everyone makes...
I copy that part from their solution but probably would have myself. I've been found out not being a graphics programmer. The experiment was a success.
Of course I've made all these mistakes to test if anyone was paying attention. (I always say that)
Not sure which is the first dimension but for an array of 10 if(arr[100]) returns false
This is taking the first pointer and offsetting it by the length of 100 pointers. There are only 10 pointers in the array so it is going into other data.
If your pointers are 64 bit and your numbers are 32 bit, even if that is referencing the memory mapped data of the sub arrays it is going twice as far as the end of the array and returning 0 purely by chance of some other memory you're dealing with by accident.
A better way would be to keep things simple and bounds check that x is less than width and y is less than height while using the single buffer method.
The point here isn't to be too harsh with criticism, it's just that it's easy to see something as more trivial than it really is.
Correct, it should be [y][x] indeed. I would have spotted that had I bothered to.
> Also you seem to be bounds checking for 0s, but to do that in the first dimension you need null pointers to pad your row selection and a second set of 0s at the end of your rows.
Not sure which is the first dimension but for an array of 10 if(arr[100]) returns false. Anything behind the && is ignored.
Looking at this again the really funny part is that it doesn't work if num = 0 since if(arr[100]) returns false if there is a zero at position 100.
> It's interesting that both you and the person you replied to used arrays of arrays which is the very first mistake everyone makes...
I copy that part from their solution but probably would have myself. I've been found out not being a graphics programmer. The experiment was a success.
Of course I've made all these mistakes to test if anyone was paying attention. (I always say that)