Skip to content

[c++]ue4 crash when calling SVONMediator::GetLinkFromPosition #14

Open
@JetBelson

Description

Thanks for sharing such an amazing plugin, I have used it well by Behaviour Tree. While when I try to use by C++, the following error came out. Please advise how to solve it. Thanks a lot.

UE4.24.3 + VS2019

Build success in VS.

But when clicking PLAY in the UE 4 Editor, the UE4 crashed with the following error.

_Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x000002f8

UE4Editor_FindPath_1636!ADebugPath::BeginPlay() [C:\Users\User\Documents\Unreal Projects\FindPath\Source\FindPath\Private\DebugPath.cpp:58]_

`#include "DebugPath.h"

#include "Engine/World.h"
#include "Engine/Engine.h"
#include <Runtime/Engine/Classes/Kismet/GameplayStatics.h>
#include <Runtime/Engine/Classes/Components/ActorComponent.h>

#include "UESVON/Public/SVONNavigationPath.h"
#include "UESVON/Public/SVONFindPathTask.h"
#include "UESVON/Public/SVONLink.h"
#include "UESVON/Public/SVONNavigationPath.h"
#include "UESVON/Public/SVONPathFinder.h"
#include "UESVON/Public/SVONVolume.h"
#include "UESVON/Public/SVONMediator.h"

// Sets default values
ADebugPath::ADebugPath()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

if (FindVolume())
{
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("my_SVONVolume sucess"));

}

}

// Called when the game starts or when spawned
void ADebugPath::BeginPlay()
{
Super::BeginPlay();

const ASVONVolume* my_SVONVolume = GetCurrentVolume();
SVONPathFinderSettings settings;
settings.myUseUnitCost = true;
settings.myUnitCost = 10;
settings.myEstimateWeight = 1;
settings.myNodeSizeCompensation = 1;
settings.myPathCostType = ESVONPathCostType::EUCLIDEAN;
settings.mySmoothingIterations = 0.0;

FSVONNavPathSharedPtr path;
UWorld* my_world = GetWorld();

SVONPathFinder svonPathFinder(my_world, *my_SVONVolume, settings);

const FVector start_position(-8310.0, 1020.0, 140.0);
const FVector target_position(-8580.0, 5020.0, 2518.0);

SVONLink start_link;
SVONLink target_link;


SVONMediator::GetLinkFromPosition(start_position, *my_SVONVolume, start_link);
/*
SVONMediator::GetLinkFromPosition(target_position, *my_SVONVolume, target_link);




svonPathFinder.FindPath(start_link, target_link, start_position, target_position, &path);

TArray<FSVONPathPoint> points = path->GetPathPoints();

for (FSVONPathPoint point : points)
{

	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, point.myPosition.ToString());
}
*/

}

// Called every frame
void ADebugPath::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void ADebugPath::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);

}

bool ADebugPath::FindVolume()
{
TArray<AActor*> navVolumes;

UGameplayStatics::GetAllActorsOfClass(GetWorld(), ASVONVolume::StaticClass(), navVolumes);

for (AActor* actor : navVolumes)
{
	ASVONVolume* volume = Cast<ASVONVolume>(actor);
	if (volume)
	{
		aSVONVolumn = volume;
		return true;
	}
}
return false;

}
`

`// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "DebugPath.generated.h"
class ASVONVolume;

UCLASS()
class FINDPATH_API ADebugPath : public APawn
{
GENERATED_BODY()

public:
// Sets default values for this pawn's properties
ADebugPath();

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

public:
// Called every frame
virtual void Tick(float DeltaTime) override;

// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

bool FindVolume();

const ASVONVolume* aSVONVolumn;
const ASVONVolume* GetCurrentVolume() const { return aSVONVolumn; }

};`

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions