Hi, everyone. I have integrated some functions of Point Cloud Library into a plugin of unreal engine, one of the most important of them is surface reconstruction. All the steps works great except the last stage, which is to represent the mesh using dynamic mesh. However, the generated dynamic mesh is well displayed ONLY in editor, causing crash when running a packed program. This is part of the code:
void APCLController::DrawGeneratedDynamicMesh( FDynamicMesh3& MeshToBeDraw)
{
// Check is valid
if (MeshToBeDraw.VertexCount() == 0 || MeshToBeDraw.TriangleCount() == 0) {
UE_LOG(PCLController, Error, TEXT("Generated mesh is invalid: VertexCount=%d, TriangleCount=%d"),
MeshToBeDraw.VertexCount(), MeshToBeDraw.TriangleCount());
return;
}
if(!DynamicMeshActor)
{
return;
}
DynamicMeshActor->GetDynamicMeshComponent()->GetDynamicMesh()->Reset();
DynamicMeshActor->GetDynamicMeshComponent()->SetMesh(MoveTemp(MeshToBeDraw));
DynamicMeshActor->GetDynamicMeshComponent()-> bEnableFlatShading=true;
DynamicMeshActor->GetDynamicMeshComponent()->ColorMode=EDynamicMeshComponentColorOverrideMode::VertexColors;
DynamicMeshActor->GetDynamicMeshComponent()->ColorSpaceMode=EDynamicMeshVertexColorTransformMode::SRGBToLinear;
// Log
FString Msg=FString::Printf( TEXT("Mesh successfully generated and set: VertexCount=%d, TriangleCount=%d"),
MeshToBeDraw.VertexCount(), MeshToBeDraw.TriangleCount());
UE_LOG(PCLController, Display, TEXT("%s"), *Msg);
}
After check line by line, it crashed when executing:
DynamicMeshActor->GetDynamicMeshComponent()->SetMesh(MoveTemp(MeshToBeDraw));
The crash report is reporting:
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000000
UE544_Lidar!FBaseDynamicMeshSceneProxy::GetDynamicMeshElements()
UE544_Lidar!FDynamicMeshElementContext::GatherDynamicMeshElementsForPrimitive()
UE544_Lidar!`FComputeShaderUtils::AddPass<FHZBBuildCS>'::`2'::<lambda_1>::operator()()
UE544_Lidar!UE::Tasks::Private::FTaskBase::TryExecuteTask()
UE544_Lidar!LowLevelTasks::TTaskDelegate<LowLevelTasks::FTask * __ptr64 __cdecl(bool),48>::TTaskDelegateImpl<`LowLevelTasks::FTask::Init<`UE::Tasks::Private::FTaskBase::Init'::`2'::<lambda_1> >'::`13'::<lambda_1>,0>::CallAndMove()
UE544_Lidar!LowLevelTasks::FTask::ExecuteTask()
UE544_Lidar!LowLevelTasks::FScheduler::ExecuteTask()
UE544_Lidar!LowLevelTasks::FScheduler::WorkerMain()
UE544_Lidar!UE::CompressedBuffer::Private::FHeader::CalculateCrc32()
UE544_Lidar!FThreadImpl::Run()
UE544_Lidar!FRunnableThreadWin::Run()
It seems that the function SetMesh(…) caused the crash, to ensure that, I even crated a FDynamicMesh3 TestMesh, and make it to be a cube. The cube is displayed very well in editor, but still, caused crash after I packed the project, leading to the same crashing report. WHAT IS MORE INTERESTING IS, after I have done the work of reconstruction, every thing goes well, nothing crashed, it suddenly crashed at the time I turn my view to the position of generated mesh…