When calling TArray::Remove in an array with a single object (TArray store copies of objects), the CheckAddress() function report as following:
Assertion failed: Addr < GetData() || Addr >= (GetData() + ArrayMax) [File:C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\Core\Public\Containers\Array.h] [Line: 1409] Attempting to add a container element (0x8031bba0) which already comes from the container (0x8031bba0, ArrayMax: 4)!
If you notice, the error doesn't even make sense. The object pointer lies well between GetData() and GetData() + ArrayMax range. I solved the problem by calling RemoteAt, since it works properly. Following is the code that triggers the bug:
asked Mar 14 '16 at 01:59 AM in Bug Reports
The error is not related to index, but memory address related. GetData() returns pointer which points to first memory address of array and if you add ArrayMax it will point to address of last item. If you don't know that already, pointer is a memory address varable and it behaves same as int... yes you can do normal math on it and you have example of that here.
So what happens here is you create pointer of array item, which points to array memory space, then you try to remove it the argument of Remove function is reference, so memory address of item you give it same as pointer you used (which points to array). Remove function (and also Add and Insert functions) have check if address of argument not the range of array in memory, if it is not it rise the error. This was added probably to avoid buggy behavior of pointer, in which it starts to point at wrong item because things moved around in array. But i don't see point to do so remove, maybe to force developer to not direly address items in array to avoid unsafe situations, since if that Remove function was successful the pointer would point something else or be invalid (which is state that is not checkable).
RemoveAt indeed would solve this problem (in fact it much faster), also not using pointer is good solution, you could use varable that you copied which would naturally have diffrent memoery address then array.
answered Mar 14 '16 at 04:33 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here