首先是一些背景信息。
我目前正在尝试编写一个可以解析文件并从中生成树结构的c ++类,我将可以将其用于反向运动学。为此,我使用了一些能够包含我需要的功能的ROS库,即urdf和kdl。
我已按照此处的说明设法将图书馆链接到构建系统https://wiki.unrealengine.com/Linking_Static_Libraries_Using_The_Build_System
我的类现在可以识别我想要使用的结构,并成功编译,但不幸的是,当我试图阻止它运行时,Unreal会崩溃,
下面的代码来自我的c ++文件,问题似乎是围绕我的urdf模型的垃圾收集,因为它设法成功解析文件只是在停止时崩溃。
#include "AIKTester.h"
#include "Runtime/Core/Public/Misc/Paths.h"
#include "Runtime/Core/Public/HAL/FileManager.h"
#include <string>
// Sets default values
AAIKTester::AAIKTester()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AAIKTester::BeginPlay()
{
Super::BeginPlay();
urdfParser();
}
// Called every frame
void AAIKTester::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
bool AAIKTester::urdfParser()
{
// Grab relative project path for file system and convert to string
FString RelativeProjPath = FPaths::ProjectDir();
std::string ProjPath(TCHAR_TO_UTF8(*RelativeProjPath));
// Try parse urdf file into model using relative project path and urdf file location
if (!my_model.initFile(ProjPath + "Source/Project/robot.urdf")) {
UE_LOG(LogTemp, Log, TEXT("Failed to parse urdf file"));
return false;
}
else {
UE_LOG(LogTemp, Log, TEXT("Parsed the urdf file"));
return true;
}
}
这是包含的头文件:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "../../ThirdParty/ROS2/Includes/urdf/model.h"
#include "../../ThirdParty/ROS2/Includes/kdl/tree.hpp"
#include "../../ThirdParty/ROS2/Includes/kdl_parser/kdl_parser.hpp"
#include "AIKTester.generated.h"
UCLASS()
class PROJECT_API AAIKTester : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AAIKTester();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
urdf::Model my_model;
bool urdfParser();
};
我试图绕过调用堆栈,但遗憾的是我无法清楚地知道如何解决这个问题。错误代码和调用堆栈似乎每隔一次运行它,最近显示:
UE4Editor.exe中的0x00007FF80FEE731E(nvwgf2umx.dll)抛出异常:0xC0000005:访问冲突读取位置0xFFFFFFFFFFFFFFFF。
非常感谢任何帮助,谢谢。