Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle SampleHeightMostDetailed on tilesets that completely fail to load, and add a test. #1526

Merged
merged 5 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions Source/CesiumRuntime/Private/Cesium3DTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,30 @@ void ACesium3DTileset::SampleHeightMostDetailed(
position.Z));
}

size_t count = positions.size();

CesiumAsync::Future<Cesium3DTilesSelection::SampleHeightResult> future =
this->_pTileset
? this->_pTileset->sampleHeightMostDetailed(positions)
: getAsyncSystem().createResolvedFuture(
Cesium3DTilesSelection::SampleHeightResult{
std::move(positions),
std::vector<bool>(positions.size(), false),
std::vector<bool>(count, false),
{"Could not sample heights from tileset because it has not "
"been created."}});

std::move(future).thenImmediately(
[this, OnHeightsSampled = std::move(OnHeightsSampled)](
Cesium3DTilesSelection::SampleHeightResult&& result) {
std::move(future)
.catchImmediately([positions = std::move(positions)](
j9liu marked this conversation as resolved.
Show resolved Hide resolved
std::exception&& exception) mutable {
size_t count = positions.size();
return Cesium3DTilesSelection::SampleHeightResult{
std::move(positions),
std::vector<bool>(count, false),
{exception.what()}};
})
.thenImmediately([this, OnHeightsSampled = std::move(OnHeightsSampled)](
Cesium3DTilesSelection::SampleHeightResult&&
result) {
if (!IsValid(this))
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,59 @@ void FSampleHeightMostDetailedSpec::Define() {
}));
});
});

Describe("Broken tileset", [this]() {
BeforeEach([this]() { CesiumTestHelpers::pushAllowTickInEditor(); });

AfterEach(EAsyncExecution::TaskGraphMainThread, [this]() {
CesiumTestHelpers::popAllowTickInEditor();
});

LatentIt(
"",
EAsyncExecution::TaskGraphMainThread,
[this](const FDoneDelegate& done) {
// Two slightly different error messages will occur, depending on
// whether there's a web server running on localhost.
this->AddExpectedError(
TEXT("(Errors when loading)|(error occurred)"));

UWorld* pWorld = CesiumTestHelpers::getGlobalWorldContext();

ACesium3DTileset* pTileset = pWorld->SpawnActor<ACesium3DTileset>();
pTileset->SetTilesetSource(ETilesetSource::FromUrl);
pTileset->SetUrl("http://localhost/notgonnawork");

pTileset->SampleHeightMostDetailed(
{FVector(-105.1, 40.1, 1.0)},
FCesiumSampleHeightMostDetailedCallback::CreateLambda(
[this, done](
ACesium3DTileset* pTileset,
const TArray<FCesiumSampleHeightResult>& result,
const TArray<FString>& warnings) {
TestEqual("Number of results", result.Num(), 1);
TestEqual("Number of warnings", warnings.Num(), 1);
TestFalse("SampleSuccess", result[0].SampleSuccess);
TestEqual(
"Longitude",
result[0].LongitudeLatitudeHeight.X,
-105.1,
1e-12);
TestEqual(
"Latitude",
result[0].LongitudeLatitudeHeight.Y,
40.1,
1e-12);
TestEqual(
"Height",
result[0].LongitudeLatitudeHeight.Z,
1.0,
1e-12);
TestTrue(
"Error message",
warnings[0].Contains(TEXT("failed to load")));
done.ExecuteIfBound();
}));
});
});
}