Recently I shrunk a TArray down to 25 by 25 without removing a line that set Array to 1 (I have a struct of TArrays so I can use them two dimension-ally). Reasonably enough, the game started crashing on startup with error message
"Assertion failed: (Index >= 0) & (Index < ArrayNum) [File:E:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\Array.h] [Line: 678]
Array index out of bounds: 25 from
I navigated to my project, opened by code in Visual Studio and expanded the array back to normal, the code would not compile and I could open the game in the editor by debugging from Visual Studio but it still crashes when trying to open it from the launcher, giving me that error message. Does this have to do with the launcher running from an old compile version? At one point I’m certain I had my code exactly like it was before the crash started happening and the editor still would not open the project. I assume this has to do with Unreal’s file structure but I don’t know how to fix it so the launcher will work again.
Well, in one fine day i was making my bullet system. All goes fine, system partially worked, so i continued making it. Suddenly editor started crashing randomly and/or when i stopping playing. About a week i didn’t known what is going on, but i figured it out: I made a custom destructor in AActor-inherited class, what was VERY bad for garbage collector.
I also thinked that everything is exactly like before these crashes started heppening, but i was wrong. Maybe you are missing something?
And if you want to make 2D array the safest way is make 1D array and get elements from it using (y * x_width + x) calculation. 2D too much fragmented, this may cause problems.
And yeah, dynamic arrays is bad, use constant if you can, even if their size is huge - some time it will fill to it’s max size, isn’t it?
That’s a fine story but it doesn’t explain how I could get an array index 25 out of bounds error when I made the array 50x50 again.
I am already planning to depreciate my current data structures and am considering swapping to constant size arrays, but I don’t expand or shrink the array often anyhow, so the flexibility of the dynamic array is nice while I am mostly avoiding the slowdown of allocating new memory.
One last symbol of error is missed. It says 25 from ???
If it says 0, then your array not initialized yet, maybe because you forget about second dimension (for(int i = 0; i < 25; ++i)) Array[i].SetNum(25)), but i don’t think that you altually forget about that.
If it says 1 or 25, then the problem is even more interesting - you are trying to get element with index 25 from arrays size of 25 (0->24 index space) or even 1. You can check where it happens by opening Visual Studio and starting debugging. When error happens you now at the point where you can watch stack trace - this is cool thing. Try to find your code somewhere there, it will show the line where you are used TArray in a not proper way.
Although i still not understanding how debugger works, but launcher not. Try recompile it for debug and developement game editors, maybe that should work. As I know launcher uses developement build.
The problem was that I hadn’t recompiled using the development editor, only the debug editor so the launcher was working off of an old executable. Thank you for your help.
The problem was that I hadn’t recompiled using the development editor, only the debug editor so the launcher was working off of an old executable.
I thought I should put it down in the answer section too and mark it as the solution for other people who come through