I’m creating custom meshes (a table and a chair) by extending the UProceduralMeshComponent
class.
I defined a base class UBasicProcMesh
that derives from UProceduralMeshComponent
and then I created 2 subclasses, UTableProcMesh
and UChairProcMesh
, that derive from UBasicProcMesh
.
Then, I defined 2 actors, ATable
and AChair
, with ATable
having a UTableProcMesh
object and AChair
having a UChairProcMesh
object.
Inside both actors I overridden the methods PostActorCreated()
, PostLoad()
and BeginPlay()
: their behaviour is pretty much the same for both actors (below an example for the chair actor).
void AChair::BeginPlay()
{
Super::BeginPlay();
SetupMesh();
}
...
void AChair::SetupMesh()
{
Chair->DrawMesh("MeshChair");
Chair->SetWorldScale3D(ChairScale);
RootComponent->SetWorldLocation(SceneLocation);
}
...
void UChairProcMesh::DrawMesh(FString MeshType)
{
Vertices.Reset();
Triangles.Reset();
Normals.Reset();
Tangents.Reset();
UVs.Reset();
Colors.Reset();
UChairProcMesh::DefineMesh(MeshType);
this->CreateMeshSection_LinearColor(0, Vertices, Triangles, Normals, UVs, Colors, Tangents, true);
}
If I put a table and a chair in the editor everything is fine, if I put only a table and then use PIE everything is fine but if I put a chair and use PIE then I get exception errors.
If I use the Development Editor
or the DebugGame Editor
build I get
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffff
UE4Editor_CoreUObject!StaticDuplicateObjectEx() [D:\Build\++UE4\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp:2111]
UE4Editor_CoreUObject!StaticDuplicateObject() [D:\Build\++UE4\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp:1961]
UE4Editor_UnrealEd!UEditorEngine::CreatePIEWorldByDuplication() [D:\Build\++UE4\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:2098]
UE4Editor_Engine!UGameInstance::InitializeForPlayInEditor() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Engine\Private\GameInstance.cpp:289]
UE4Editor_UnrealEd!UEditorEngine::CreateInnerProcessPIEGameInstance() [D:\Build\++UE4\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:2652]
UE4Editor_UnrealEd!UEditorEngine::OnLoginPIEComplete_Deferred() [D:\Build\++UE4\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:1474]
UE4Editor_UnrealEd!UEditorEngine::CreateNewPlayInEditorInstance() [D:\Build\++UE4\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:1708]
UE4Editor_UnrealEd!UEditorEngine::StartPlayInEditorSession() [D:\Build\++UE4\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:2580]
UE4Editor_UnrealEd!UEditorEngine::StartQueuedPlaySessionRequestImpl() [D:\Build\++UE4\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:1089]
UE4Editor_UnrealEd!UEditorEngine::StartQueuedPlaySessionRequest() [D:\Build\++UE4\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:1016]
UE4Editor_UnrealEd!UEditorEngine::Tick() [D:\Build\++UE4\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:1611]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [D:\Build\++UE4\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:414]
UE4Editor!FEngineLoop::Tick() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:4850]
UE4Editor!GuardedMain() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:169]
UE4Editor!GuardedMainWrapper() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:137]
UE4Editor!WinMain() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:268]
UE4Editor!__scrt_common_main_seh() [d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
kernel32
ntdll
If I use the DebugGame Editor
build and start UE from Visual Studio with the Local Debugger, I get
[2021.09.17-13.25.24:450][293]LogOutputDevice: Warning:
Script Stack (0 frames):
Ensure condition failed: Lhs.CurrentNum == Lhs.InitialNum [File:D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Public\Containers/Array.h] [Line: 216]
Array has changed during ranged-for iteration!
[2021.09.17-13.25.24:450][293]LogOutputDevice: Error: Ensure condition failed: Lhs.CurrentNum == Lhs.InitialNum [File:D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Public\Containers/Array.h] [Line: 216]
Array has changed during ranged-for iteration!
[2021.09.17-13.25.24:450][293]LogStats: FDebug::EnsureFailed - 0.000 s
UE4Editor-Win64-DebugGame.exe has triggered a breakpoint.
Exception thrown at 0x00007FFA022E5C29 (UE4Editor-Core.dll) in UE4Editor-Win64-DebugGame.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
with callstack
UE4Editor-Core.dll!rml::internal::isLargeObject<0>(void * object) Line 2476 C++
[Inline Frame] UE4Editor-Core.dll!rml::internal::internalPoolFree(rml::internal::MemoryPool * memPool, void *) Line 2618 C++
[Inline Frame] UE4Editor-Core.dll!rml::internal::internalFree(void *) Line 2644 C++
UE4Editor-Core.dll!scalable_free(void * object) Line 2932 C++
> UE4Editor-Core.dll!FMemory::Free(void * Original) Line 80 C++
[Inline Frame] UE4Editor-Engine.dll!TSizedHeapAllocator<32>::ForAnyElementType::{dtor}() Line 465 C++
[Inline Frame] UE4Editor-Engine.dll!TArray<UActorComponent *,TInlineAllocator<24,TSizedDefaultAllocator<32>>>::{dtor}() Line 599 C++
UE4Editor-Engine.dll!AActor::BeginPlay() Line 3458 C++
[External Code]
UE4Editor-Engine.dll!AActor::DispatchBeginPlay(bool bFromLevelStreaming) Line 3397 C++
UE4Editor-Engine.dll!AWorldSettings::NotifyBeginPlay() Line 246 C++
UE4Editor-Engine.dll!AGameStateBase::HandleBeginPlay() Line 205 C++
UE4Editor-Engine.dll!UWorld::BeginPlay() Line 4184 C++
UE4Editor-Engine.dll!UGameInstance::StartPlayInEditorGameInstance(ULocalPlayer * LocalPlayer, const FGameInstancePIEParameters & Params) Line 478 C++
UE4Editor-UnrealEd.dll!UEditorEngine::CreateInnerProcessPIEGameInstance(FRequestPlaySessionParams & InParams, const FGameInstancePIEParameters & InPIEParameters, int InPIEInstanceIndex) Line 2792 C++
UE4Editor-UnrealEd.dll!UEditorEngine::OnLoginPIEComplete_Deferred(int LocalUserNum, bool bWasSuccessful, FString ErrorString, FPieLoginStruct DataStruct) Line 1474 C++
UE4Editor-UnrealEd.dll!UEditorEngine::CreateNewPlayInEditorInstance(FRequestPlaySessionParams & InRequestParams, const bool bInDedicatedInstance, const EPlayNetMode InNetMode) Line 1708 C++
UE4Editor-UnrealEd.dll!UEditorEngine::StartPlayInEditorSession(FRequestPlaySessionParams & InRequestParams) Line 2580 C++
UE4Editor-UnrealEd.dll!UEditorEngine::StartQueuedPlaySessionRequestImpl() Line 1089 C++
UE4Editor-UnrealEd.dll!UEditorEngine::StartQueuedPlaySessionRequest() Line 1016 C++
UE4Editor-UnrealEd.dll!UEditorEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 1611 C++
UE4Editor-UnrealEd.dll!UUnrealEdEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 414 C++
UE4Editor-Win64-DebugGame.exe!FEngineLoop::Tick() Line 4850 C++
[Inline Frame] UE4Editor-Win64-DebugGame.exe!EngineTick() Line 62 C++
UE4Editor-Win64-DebugGame.exe!GuardedMain(const wchar_t * CmdLine) Line 169 C++
UE4Editor-Win64-DebugGame.exe!WinMain(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow) Line 257 C++
[External Code]
What’s more weird is that when I first got the exception with the Development Editor
build I switched to DebugGame Editor
, opened UE using the debugger of Visual Studio and I could actually use PIE with a chair and a table without problems; then, I switched to Development Editor
, opened UE with Visual Studio, got the exception, switched to the DebugGame Editor
again and got another exception.
I tried to re-generate the Visual Studio project with UE and re-build but nothing changed.