Some background information first.
I'm currently trying to write a c++ class that can parse a file and generate a tree structure from it that I will be able to use for Inverse Kinematics. To do this I'm making use of some ROS libraries that are able to incorporate the functionality that I need, namely urdf and kdl.
I've managed to link the libraries into the build system through following the instructions here https://wiki.unrealengine.com/Linking_Static_Libraries_Using_The_Build_System
My class can now recognize the structures that I want to make use of, and compiles successfully, but unfortunately Unreal crashes when I try to stop it running,
The code below is from my c++ file, and the issue seems to revolve around garbage collection of my urdf model, as it manages to successfully parse the file only to crash on stopping.
#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;
}
}
And here is the included header file:
#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();
};
I've tried to get my head around the call stack, but unfortunately I can't get any clarity about how to solve this problem. The error code and call stack seem to change every other time running it, most recently displaying:
Exception thrown at 0x00007FF80FEE731E (nvwgf2umx.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
Any help would be greatly appreciated, thanks.
User contributions licensed under CC BY-SA 3.0