Assertion failed: IsValidLowLevel() in UObject\Obj.cpp] [Line: 667]

My app sometimes crashed with following stack:

Assertion failed: IsValidLowLevel() [File:D:\Build\++UE4+Release-4.12+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\Obj.cpp] [Line: 667] 



UE4Editor_Core!FDebug::AssertFailed() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\core\private\misc\outputdevice.cpp:440]
UE4Editor_CoreUObject!UObject::ConditionalBeginDestroy() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\coreuobject\private\uobject\obj.cpp:668]
UE4Editor_HuaiKX_6834_Win64_DebugGame!GroupEntity::Clear() [d:\workspace\unreal_project\huaikongxin\program\server\huaikxsrv\source\huaikx\logic\private\pvpmodule\groupentity.cpp:142]

and this issue occurs at AllUnits_[i]->ConditionalBeginDestroy(); of my code:

void GroupEntity::Clear()
{
	for (int i = 0; i < WARRIOR_COUNT_MAX; i++)
	{
		if (AllUnits_[i])
		{
			AllUnits_[i]->ConditionalBeginDestroy();
			AllUnits_[i] = NULL;
		}
	}
	}
}

but I can’t reproduce this issue, it occurs irregularly. I wonder what situation would make an Actor Invalid and not NULL.

If don’t invoke ConditionalBeginDestroy() when IsValidLowLevel() return false, does it cause memory leak?

Hey ,

My best guess is that the current “AllUnits_[ i ]” element may still be a valid pointer but a invalid UObject, resulting in the Assert on IsValidLowLevel( ).

If AllUnits_ is a TArray, you could change the loop from relying on WARRIOR_COUNT_MAX to something like:

for (auto& Unit : AllUnits_)
{
   Unit->ConditionalBeginDestroy( );
   Unit = NULL;
}

or

for( int32 = Index = 0; Index < AllUnits_.Num( ); Index++ )
{
    AllUnits_[Index]->ConditionalBeginDestroy( );
    AllUnits_[Index] = NULL;
}

Thx so much for your help! I will try it later.
Have a nice day!