在虚幻引擎中删除NXOpen对象时崩溃

时间:2020-02-18 16:40:02

标签: c++ memory unreal-engine4 cad nomachine-nx

Hello stackoverflow社区,

第一次问。

我正在研究使用虚幻引擎在VR中为CAD数据建模的原型。 我设法使我的虚幻项目可以用我的CAD系统Siemens NX或API NXOpen构建。

总体而言,API可以正常工作,我可以调用NXOpen函数并可以创建基本对象 但是某些操作会导致崩溃,我的猜测是它与内存管理有关。 我无法全神贯注到底发生了什么。

例如,我有一些代码可以创建运行良好的NX块功能。 然后,我需要一个存储在块特征内的主体对象。访问也有效,但是当“主体”超出范围时,它会崩溃。 在NX功能中访问各种数据时,也会发生类似的崩溃。这个伪代码经常触发崩溃:


    // 'block' gets created here

    if (block) {
        std::vector<NXOpen::Body*> bodies = block->GetBodies();
        if (bodies.size() > 0) {
            NXOpen::Body* body = bodies.front();
        }
    } // <-- this line crashes

Exception thrown: read access violation.
**flag** was 0xFFFFFFFFFFFFFFFF. occurred

    [Inline Frame] UE4Editor-Core.dll!__TBB_machine_cmpswp1(volatile void *) Line 69    C++
>   [Inline Frame] UE4Editor-Core.dll!__TBB_TryLockByte(unsigned char &) Line 917   C++
    UE4Editor-Core.dll!__TBB_LockByte(unsigned char & flag) Line 924    C++
    [Inline Frame] UE4Editor-Core.dll!MallocMutex::scoped_lock::{ctor}(MallocMutex &) Line 66   C++
    UE4Editor-Core.dll!rml::internal::Block::freePublicObject(rml::internal::FreeObject * objectToFree) Line 1382   C++
    [Inline Frame] UE4Editor-Core.dll!rml::internal::internalPoolFree(rml::internal::MemoryPool * memPool, void *) Line 2571    C++
    UE4Editor-Core.dll!rml::internal::internalFree(void * object) Line 2595 C++
    UE4Editor-Core.dll!FMemory::Free(void * Original) Line 76   C++
    UE4Editor-GestEnUE-Win64-DebugGame.dll!operator delete(void * Ptr, unsigned __int64 Size) Line 6    C++
    [External Code] 
    UE4Editor-GestEnUE-Win64-DebugGame.dll!UNXConnection::AddPointSetsToBody(const FString & name) Line 268 C++
    UE4Editor-GestEnUE-Win64-DebugGame.dll!ANXPart::AddCylinder(FVector pos, FVector axis, float height, float diameter, bool WorldSpace) Line 103  C++
    UE4Editor-GestEnUE-Win64-DebugGame.dll!ANXPart::execAddCylinder(UObject * Context, FFrame & Stack, void * const Z_Param__Result) Line 18    C++
    UE4Editor-CoreUObject.dll!UFunction::Invoke(UObject * Obj, FFrame & Stack, void * const Z_Param__Result) Line 4643  C++
    UE4Editor-CoreUObject.dll!UObject::CallFunction(FFrame & Stack, void * const Z_Param__Result, UFunction * Function) Line 904    C++
    [Inline Frame] UE4Editor-CoreUObject.dll!FFrame::Step(UObject *) Line 319   C++
    UE4Editor-CoreUObject.dll!UObject::ProcessContextOpcode(FFrame & Stack, void * const Z_Param__Result, bool bCanFailSilently) Line 2314  C++
    [Inline Frame] UE4Editor-CoreUObject.dll!FFrame::Step(UObject *) Line 319   C++
    UE4Editor-CoreUObject.dll!UObject::execLetObj(UObject * Context, FFrame & Stack, void * const Z_Param__Result) Line 2136    C++
    [Inline Frame] UE4Editor-CoreUObject.dll!FFrame::Step(UObject *) Line 319   C++
    UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction(UObject * Context, FFrame & Stack, void * const Z_Param__Result) Line 974  C++
    UE4Editor-CoreUObject.dll!ProcessScriptFunction<void (__cdecl*)(UObject *,FFrame &,void *)>(UObject * Context, UFunction * Function, FFrame & Stack, void * const Z_Param__Result, void(*)(UObject *, FFrame &, void *) ExecFtor) Line 809  C++
    UE4Editor-CoreUObject.dll!ProcessLocalFunction(UObject * Context, UFunction * Fn, FFrame & Stack, void * const Z_Param__Result) Line 1033   C++
    [Inline Frame] UE4Editor-CoreUObject.dll!FFrame::Step(UObject *) Line 319   C++
    UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction(UObject * Context, FFrame & Stack, void * const Z_Param__Result) Line 974  C++
    UE4Editor-CoreUObject.dll!ProcessScriptFunction<void (__cdecl*)(UObject *,FFrame &,void *)>(UObject * Context, UFunction * Function, FFrame & Stack, void * const Z_Param__Result, void(*)(UObject *, FFrame &, void *) ExecFtor) Line 809  C++
    UE4Editor-CoreUObject.dll!ProcessLocalFunction(UObject * Context, UFunction * Fn, FFrame & Stack, void * const Z_Param__Result) Line 1033   C++
    [Inline Frame] UE4Editor-CoreUObject.dll!FFrame::Step(UObject *) Line 319   C++
    UE4Editor-CoreUObject.dll!UObject::ProcessContextOpcode(FFrame & Stack, void * const Z_Param__Result, bool bCanFailSilently) Line 2314  C++
    [Inline Frame] UE4Editor-CoreUObject.dll!FFrame::Step(UObject *) Line 319   C++
    UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction(UObject * Context, FFrame & Stack, void * const Z_Param__Result) Line 974  C++
    UE4Editor-CoreUObject.dll!ProcessScriptFunction<void (__cdecl*)(UObject *,FFrame &,void *)>(UObject * Context, UFunction * Function, FFrame & Stack, void * const Z_Param__Result, void(*)(UObject *, FFrame &, void *) ExecFtor) Line 809  C++
    UE4Editor-CoreUObject.dll!ProcessLocalFunction(UObject * Context, UFunction * Fn, FFrame & Stack, void * const Z_Param__Result) Line 1033   C++
    [Inline Frame] UE4Editor-CoreUObject.dll!FFrame::Step(UObject *) Line 319   C++
    UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction(UObject * Context, FFrame & Stack, void * const Z_Param__Result) Line 974  C++
    UE4Editor-CoreUObject.dll!UObject::ProcessInternal(UObject * Context, FFrame & Stack, void * const Z_Param__Result) Line 1058   C++
    UE4Editor-CoreUObject.dll!UFunction::Invoke(UObject * Obj, FFrame & Stack, void * const Z_Param__Result) Line 4643  C++
    UE4Editor-CoreUObject.dll!UObject::ProcessEvent(UFunction * Function, void * Parms) Line 1464   C++
    UE4Editor-Engine.dll!AActor::ProcessEvent(UFunction * Function, void * Parameters) Line 769 C++
    UE4Editor-GestEnUE-Win64-DebugGame.dll!ABuilderBase::commit() Line 37   C++
    UE4Editor-GestEnUE-Win64-DebugGame.dll!AGestEnLeapPawn::Tick(float DeltaTime) Line 138  C++
    UE4Editor-Engine.dll!AActor::TickActor(float DeltaSeconds, ELevelTick TickType, FActorTickFunction & ThisTickFunction) Line 970 C++
    UE4Editor-Engine.dll!FActorTickFunction::ExecuteTick(float DeltaTime, ELevelTick TickType, ENamedThreads::Type CurrentThread, const TRefCountPtr<FGraphEvent> & MyCompletionGraphEvent) Line 164    C++
    [Inline Frame] UE4Editor-Engine.dll!FTickFunctionTask::DoTask(ENamedThreads::Type) Line 285 C++
    UE4Editor-Engine.dll!TGraphTask<FTickFunctionTask>::ExecuteTask(TArray<FBaseGraphTask *,FDefaultAllocator> & NewTasks, ENamedThreads::Type CurrentThread) Line 842  C++
    [Inline Frame] UE4Editor-Core.dll!FBaseGraphTask::Execute(TArray<FBaseGraphTask *,FDefaultAllocator> & CurrentThread, ENamedThreads::Type) Line 511 C++
    UE4Editor-Core.dll!FNamedTaskThread::ProcessTasksNamedThread(int QueueIndex, bool bAllowStall) Line 686 C++
    UE4Editor-Core.dll!FNamedTaskThread::ProcessTasksUntilQuit(int QueueIndex) Line 582 C++
    [Inline Frame] UE4Editor-Core.dll!FTaskGraphImplementation::ProcessThreadUntilRequestReturn(ENamedThreads::Type) Line 1406  C++
    UE4Editor-Core.dll!FTaskGraphImplementation::WaitUntilTasksComplete(const TArray<TRefCountPtr<FGraphEvent>,TInlineAllocator<4,FDefaultAllocator> > & Tasks, ENamedThreads::Type CurrentThreadIfKnown) Line 1457 C++
    UE4Editor-Engine.dll!FTickTaskSequencer::ReleaseTickGroup(ETickingGroup WorldTickGroup, bool bBlockTillComplete) Line 557   C++
    UE4Editor-Engine.dll!FTickTaskManager::RunTickGroup(ETickingGroup Group, bool bBlockTillComplete) Line 1505 C++
    UE4Editor-Engine.dll!UWorld::RunTickGroup(ETickingGroup Group, bool bBlockTillComplete) Line 789    C++
    UE4Editor-Engine.dll!UWorld::Tick(ELevelTick TickType, float DeltaSeconds) Line 1568    C++
    UE4Editor-UnrealEd.dll!UEditorEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 1618    C++
    UE4Editor-UnrealEd.dll!UUnrealEdEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 403   C++
    UE4Editor-Win64-DebugGame.exe!FEngineLoop::Tick() Line 3967 C++
    [Inline Frame] UE4Editor-Win64-DebugGame.exe!EngineTick() Line 62   C++
    UE4Editor-Win64-DebugGame.exe!GuardedMain(const wchar_t * CmdLine, HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, int nCmdShow) Line 168   C++
    UE4Editor-Win64-DebugGame.exe!WinMain(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow) Line 261   C++

如果我正确理解了调用栈,则删除对象时会发生错误。但是,为什么会这样呢? 难道虚幻和NX第三方库都试图管理内存?

有人知道会导致这些崩溃的原因,甚至知道如何解决吗? 如有必要,我很乐意提供更多信息。

问候, LaRanaRica

1 个答案:

答案 0 :(得分:1)

我发现使用调试运行时库通常会在使用NXOpen时导致内存错误。 您可以使用链接器设置/ MD(而不是/ MDd)来更改此设置。