I have an array of a struct with another array of struct as a field.
The fields get initialized, but when in the third for loop the value of why[j].number_of_sub_structs gets outrageously high even though all I do is access it.
Can anyone tell me why the number of sub structs changes randomly from my input?
If anyone has any suggestions to clean up the code that would also be helpful :)
I do initialize them in ine 38(unless thats not initializing?). It even gives the correct output for the fist two passes through the last for loop but after that it goes haywire.
Actually i do not even know if that is the reason the program crashes with the exc_bad_access error.
I'm guessing it is because i put in cout statements and that was the only value that came up wrong.
The problem is your not allocating the array.
If you choose more than 1 substruct, your third loop is now accessing memory where xPosition, yPosition, etc exist.
I did 20 max as a test, and it did not bleed.
SubStruct sub[20];
I used a test of 7 main, then used a combo of 1,2 3,4 5,6 7,8 9,10 etc...
No bleeding occurred when I used 1 substruct.