Exception error when trying to convert lat/lon to UECoords (c++)

Trying to make a blueprint callable function that takes lat,lon,altitude as floats and converts them to a UE vector so I can move actors around. When I call the function UE crashes with an exception error.

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000388

UE4Editor_CesiumRuntime!CesiumGeospatial::Ellipsoid::cartographicToCartesian()
UE4Editor_CesiumRuntime!GeoTransforms::TransformLongitudeLatitudeHeightToUnreal() [D:\build\++Portal\Sync\LocalBuilds\PluginTemp\HostProject\Plugins\CesiumForUnreal\Source\CesiumRuntime\Private\GeoTransforms.cpp:109]
UE4Editor_CesiumRuntime!ACesiumGeoreference::TransformLongitudeLatitudeHeightToUnreal() [D:\build\++Portal\Sync\LocalBuilds\PluginTemp\HostProject\Plugins\CesiumForUnreal\Source\CesiumRuntime\Private\CesiumGeoreference.cpp:833]

I have a feeling it has to do with the GeoReference variable in my actor instance, I see the georeference in the list but when I click it, nothing happens. I also added a CesiumGlobeAnchor component to the actor but it still crashes. Any ideas?

Here’s my header…

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "CesiumGeoreference.h"
#include "Math/Vector.h"
#include "CesiumGeospatial/Ellipsoid.h"
#include "CesiumGeospatial/Cartographic.h"
#include "aircraft_4.generated.h"

UCLASS()
class ADSB_API Aaircraft_4 : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	Aaircraft_4();
	// A pawn from the Cesium for Unreal API that can convert between different coordinates
	UPROPERTY(EditAnywhere, Category = "FlightTracker")
		ACesiumGeoreference* CesiumGeoreference;

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	
	UFUNCTION(BlueprintCallable, Category = "calc")
		void getUePos(const float lat, const float lon, const float altitude, FVector& out);
public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

};

and my code

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


#include "aircraft_4.h"
#include "Runtime/Engine/Public/EngineGlobals.h"

// Sets default values
Aaircraft_4::Aaircraft_4()
{
 	// 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 Aaircraft_4::BeginPlay()
{
	Super::BeginPlay();
	
}

void Aaircraft_4::getUePos(const float lat, const float lon, const float altitude, FVector& out)
{
	float altitude_m = altitude * 0.3048;
	glm::dvec3 UECoords = this->CesiumGeoreference->TransformLongitudeLatitudeHeightToUnreal(glm::dvec3(lat, lon, altitude_m));
	out = FVector(UECoords.x, UECoords.y, UECoords.z);
	
}

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

}

The blueprint currently doesn’t do anything with the output vector. I even changed the function to not have a return or do anything else but do the transform and it still crashes so it must be that line. Not really experienced with unreal or c++ so I’d appreciate any help you can give. Thanks

I’m still stuck on this issue. I know it’s that the georeference is null but I can’t set it in the blueprint variables.

I also read in the changelog that the GlobeAnchor component replaced the georeference component. Should my code by trying to access that instead of the global georeference actor?

Hi @bavik94,

At first glance, it looks like you’re trying to set the blueprint’s georeference in the Blueprint Editor. You generally won’t be able to set level actors that way - you’ll have to add an instance of the blueprint actor to your level and set the georeference on that instance through the Details panel.

Or, you could try initializing the georeference in the constructor of your Aaircraft_4 class with the following code:

this->CesiumGeoreference = ACesiumGeoreference::GetDefaultGeoreference(this);

Let me know if any of this helps you out - if not, we’ll keep digging.

-Alex

That was it! I should have thought about that. Thanks for your help, works like a charm!

1 Like