TArray remove* function call cause editor crash


When I use TArray with iterator, and selectively remove some of the elements, editor will crash during execution.

source code:

class TestElem {
	int ID;
	TestElem(int idx);
    TArray<TestElem *> TestTArray2;


for (i = 0; i < 10; ++i)
	TestTArray2.Add(new TestElem(i));

for (auto it : TestTArray2)
	UE_LOG(LogSanguo, Warning, TEXT("index for tarray2 %d"), TestTArray2.Find(it));

	if (it->ID == 3)
		// TestTArray2.RemoveAll([&it](TestElem *& Element) { return Element->ID == it->ID; });    --> cause crash
		// TestTArray2.RemoveAt(TestTArray2.Find(it), 1, true);    --> cause crash, in the code I comment them all

	UE_LOG(LogSanguo, Warning, TEXT("remove done for tarray2"));

All remove* has issues, takes Remove() as an example, in the array.h, it looks like:

int32 Remove(const ElementType& Item)

	// Element is non-const to preserve compatibility with existing code with a non-const operator==() member function
	return RemoveAll([&Item](ElementType& Element) { return Element == Item; });

the checkAddress function here is to “Checks that the specified address is not part of an element within the container.” Certainly it is in the range, and I want to remove it. So it will fail…

I believe removesingle() and remove*() has similar issue…

Could you help to confirm it? :slight_smile: