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

Add SampleHeightMostDetailed tileset load failure test #511

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 30 additions & 0 deletions Tests/TestCesium3DTileset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,34 @@ public IEnumerator SampleHeightMostDetailedIndicatesNotSampledForPositionOutside
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].y, -33.87100, 1e-12);
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].z, 1.0, 1e-12);
}

[UnityTest]
public IEnumerator SampleHeightMostDetailedFailsIfTilesetFailsToLoad()
{
GameObject go = new GameObject();
go.name = "Invalid";
Cesium3DTileset tileset = go.AddComponent<Cesium3DTileset>();
tileset.tilesetSource = CesiumDataSource.FromUrl;
tileset.url = "http://localhost/notgonnawork";

Task<CesiumSampleHeightResult> task = tileset.SampleHeightMostDetailed(new double3(151.20972, -33.87100, 1.0));

yield return new WaitForTask(task);

CesiumSampleHeightResult result = task.Result;
Assert.IsNotNull(result);
Assert.IsNotNull(result.longitudeLatitudeHeightPositions);
Assert.IsNotNull(result.sampleSuccess);
Assert.IsNotNull(result.warnings);
Assert.AreEqual(result.longitudeLatitudeHeightPositions.Length, 1);
Assert.AreEqual(result.sampleSuccess.Length, 1);
Assert.AreEqual(result.warnings.Length, 1);

Assert.AreEqual(result.sampleSuccess[0], false);
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].x, 151.20972, 1e-12);
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].y, -33.87100, 1e-12);
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].z, 1.0, 1e-12);

Assert.IsTrue(result.warnings[0].Contains("failed to load"));
}
}
35 changes: 24 additions & 11 deletions native~/Runtime/src/Cesium3DTilesetImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,17 +412,30 @@ Cesium3DTilesetImpl::SampleHeightMostDetailed(
position.z));
}

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

std::move(future)
auto sampleHeights = [this, &positions]() mutable {
if (this->getTileset()) {
return this->getTileset()
->sampleHeightMostDetailed(positions)
.catchImmediately([positions = std::move(positions)](
std::exception&& exception) mutable {
std::vector<bool> sampleSuccess(positions.size(), false);
return Cesium3DTilesSelection::SampleHeightResult{
std::move(positions),
std::move(sampleSuccess),
{exception.what()}};
});
} else {
std::vector<bool> sampleSuccess(positions.size(), false);
return getAsyncSystem().createResolvedFuture(
Cesium3DTilesSelection::SampleHeightResult{
std::move(positions),
std::move(sampleSuccess),
{"Could not sample heights from tileset because it has not "
"been created."}});
}
};

sampleHeights()
.thenImmediately(
[promise](Cesium3DTilesSelection::SampleHeightResult&& result) {
System::Array1<Unity::Mathematics::double3> positions(
Expand Down