Crash when using dynamic array structures
-
I was finally able to isolate a crash I had in my larger program related to dynamic arrays.
NOTE: I have encountered some occasions where the sample code does NOT crash, but running the program from a rebooted FUZE always seem to crash it.
Here is the full code. The "{1}" in the code preview should just be empty lines, don't know how to remove them...
struct StructTest i = 0 endstruct struct StructArrayHolder int count = 0 StructTest arr = [] // Crashes with arr = [], but not with f.e. arr[5] endstruct StructArrayHolder FullArray[8] function AddRecord(val) curridx = FullArray[0].count StructTest n // Local StructTest n will crash, global will not n.i = val FullArray[0].arr[curridx] = n FullArray[0].count += 1 return void AddRecord(10) AddRecord(50) test = FullArray[0].arr[0] print(test) // Crash loop update() repeat
-
@Nisse5 Interesting, to be honest I don't know the F4NS language dialect properly yet :) and guessing on behavior from my knowledge from other languages. E.g. In golang you'd have to do something like
FullArray[0] = new StructArrayHolder()
before accessing the elements - this would allocate the memory at index 0 of FullArray.
In F4NS I made this little change to your code:
function AddRecord(val) currIdx = FullArray[0].count // should be 0 // guessing that this will call malloc() or some custom version of allocation FullArray[0].arr[currIdx] = [ .i = val ] FullArray[0].count += 1 return void
-
I shared this program just a sec ago.
-
@mixaal Thanks a lot!
-
@Kaiser said in Crash when using dynamic array structures:
I also don't know how to fix that problem, but one of the FUZE team members has asked for Errors in the game, so why don't you ask there for help or to fix that error?
It crashes FUZE. FUZE shouldn't crash. This is a bug.
-
Just to say this thread isn't being ignored! Thanks for reporting.