Skip to content

Commit

Permalink
Merge pull request #1596 from CesiumGS/shmd-null-check
Browse files Browse the repository at this point in the history
Check for null tileset in SampleHeightMostDetailed
  • Loading branch information
kring authored Jan 29, 2025
2 parents 04d58b5 + 2abe952 commit 36a48bf
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
##### Fixes :wrench:

- Fixed another bug in `CesiumSubLevelSwitcherComponent` that could prevent all sub-levels from loading if a single sub-level failed to load.
- Fixed crash when calling `SampleHeightMostDetailed` blueprint function without a valid tileset.

### v2.12.0 - 2025-01-02

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@ UCesiumSampleHeightMostDetailedAsyncAction::SampleHeightMostDetailed(
}

void UCesiumSampleHeightMostDetailedAsyncAction::Activate() {
this->RegisterWithGameInstance(this->_pTileset);
if (!IsValid(this->_pTileset)) {
TArray<FString> Warnings;
Warnings.Push(TEXT(
"Invalid Tileset parameter passed to UCesiumSampleHeightMostDetailedAsyncAction, returning no results"));

this->_pTileset->SampleHeightMostDetailed(
this->_longitudeLatitudeHeightArray,
FCesiumSampleHeightMostDetailedCallback::CreateUObject(
this,
&UCesiumSampleHeightMostDetailedAsyncAction::RaiseOnHeightsSampled));
this->RaiseOnHeightsSampled(
this->_pTileset,
TArray<FCesiumSampleHeightResult>(),
Warnings);
} else {
this->RegisterWithGameInstance(this->_pTileset);

this->_pTileset->SampleHeightMostDetailed(
this->_longitudeLatitudeHeightArray,
FCesiumSampleHeightMostDetailedCallback::CreateUObject(
this,
&UCesiumSampleHeightMostDetailedAsyncAction::
RaiseOnHeightsSampled));
}
}

void UCesiumSampleHeightMostDetailedAsyncAction::RaiseOnHeightsSampled(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void FSampleHeightMostDetailedSpec::Define() {
});

LatentIt(
"",
"invalid tileset URL",
EAsyncExecution::TaskGraphMainThread,
[this](const FDoneDelegate& done) {
// Two slightly different error messages will occur, depending on
Expand Down Expand Up @@ -354,5 +354,28 @@ void FSampleHeightMostDetailedSpec::Define() {
done.ExecuteIfBound();
}));
});

LatentIt(
"tileset parameter is nullptr",
EAsyncExecution::TaskGraphMainThread,
[this](const FDoneDelegate& done) {
UCesiumSampleHeightMostDetailedAsyncAction* pAsync =
UCesiumSampleHeightMostDetailedAsyncAction::
SampleHeightMostDetailed(
nullptr,
{FVector(144.93406, -37.82457, 1.0)});

USampleHeightCallbackReceiver::Bind(
pAsync->OnHeightsSampled,
[this, done](
const TArray<FCesiumSampleHeightResult>& result,
const TArray<FString>& warnings) {
TestEqual("Number of results", result.Num(), 0);
TestEqual("Number of warnings", warnings.Num(), 1);
done.ExecuteIfBound();
});

pAsync->Activate();
});
});
}

0 comments on commit 36a48bf

Please sign in to comment.