From ba47a22553c9c98cfcbbebc64574af74ac723729 Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Sat, 28 Sep 2024 08:46:56 +1000 Subject: [PATCH 1/3] Add tileset load failure test. --- Tests/TestCesium3DTileset.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Tests/TestCesium3DTileset.cs b/Tests/TestCesium3DTileset.cs index 74c5adfc..af094e6c 100644 --- a/Tests/TestCesium3DTileset.cs +++ b/Tests/TestCesium3DTileset.cs @@ -126,4 +126,21 @@ 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(); + tileset.tilesetSource = CesiumDataSource.FromUrl; + tileset.url = "http://localhost/notgonnawork"; + + Task task = tileset.SampleHeightMostDetailed(new double3(151.20972, -33.87100, 1.0)); + + yield return new WaitForTask(task); + + Assert.NotNull(task.Exception); + Assert.IsTrue(task.Exception.Message.Contains("failed to load")); + } } \ No newline at end of file From c66231a9c2463f00ad1bd255336738c1ecee8451 Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Sat, 28 Sep 2024 09:36:38 +1000 Subject: [PATCH 2/3] Correct size of sampleSuccess array when tileset not created. --- native~/Runtime/src/Cesium3DTilesetImpl.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/native~/Runtime/src/Cesium3DTilesetImpl.cpp b/native~/Runtime/src/Cesium3DTilesetImpl.cpp index b42c8082..1d09afbc 100644 --- a/native~/Runtime/src/Cesium3DTilesetImpl.cpp +++ b/native~/Runtime/src/Cesium3DTilesetImpl.cpp @@ -412,13 +412,15 @@ Cesium3DTilesetImpl::SampleHeightMostDetailed( position.z)); } + size_t count = positions.size(); + CesiumAsync::Future future = this->getTileset() ? this->getTileset()->sampleHeightMostDetailed(positions) : getAsyncSystem().createResolvedFuture( Cesium3DTilesSelection::SampleHeightResult{ std::move(positions), - std::vector(positions.size(), false), + std::vector(count, false), {"Could not sample heights from tileset because it has not " "been created."}}); From b5f44ccac863e1bbd91d1b1f93280199720ad327 Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Tue, 1 Oct 2024 07:38:40 +1000 Subject: [PATCH 3/3] Provide result even if tileset sampling fails completely. --- Tests/TestCesium3DTileset.cs | 17 ++++++++-- native~/Runtime/src/Cesium3DTilesetImpl.cpp | 37 +++++++++++++-------- native~/extern/cesium-native | 2 +- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/Tests/TestCesium3DTileset.cs b/Tests/TestCesium3DTileset.cs index af094e6c..3a174a4c 100644 --- a/Tests/TestCesium3DTileset.cs +++ b/Tests/TestCesium3DTileset.cs @@ -140,7 +140,20 @@ public IEnumerator SampleHeightMostDetailedFailsIfTilesetFailsToLoad() yield return new WaitForTask(task); - Assert.NotNull(task.Exception); - Assert.IsTrue(task.Exception.Message.Contains("failed to load")); + 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")); } } \ No newline at end of file diff --git a/native~/Runtime/src/Cesium3DTilesetImpl.cpp b/native~/Runtime/src/Cesium3DTilesetImpl.cpp index 1d09afbc..fde18b58 100644 --- a/native~/Runtime/src/Cesium3DTilesetImpl.cpp +++ b/native~/Runtime/src/Cesium3DTilesetImpl.cpp @@ -412,19 +412,30 @@ Cesium3DTilesetImpl::SampleHeightMostDetailed( position.z)); } - size_t count = positions.size(); - - CesiumAsync::Future future = - this->getTileset() - ? this->getTileset()->sampleHeightMostDetailed(positions) - : getAsyncSystem().createResolvedFuture( - Cesium3DTilesSelection::SampleHeightResult{ - std::move(positions), - std::vector(count, 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 sampleSuccess(positions.size(), false); + return Cesium3DTilesSelection::SampleHeightResult{ + std::move(positions), + std::move(sampleSuccess), + {exception.what()}}; + }); + } else { + std::vector 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 positions( diff --git a/native~/extern/cesium-native b/native~/extern/cesium-native index b56b1a2e..31e93ac2 160000 --- a/native~/extern/cesium-native +++ b/native~/extern/cesium-native @@ -1 +1 @@ -Subproject commit b56b1a2ee709e1c9b53996a6073c66d9cf01955b +Subproject commit 31e93ac2992eeac7600357710dc50b7c70d54b85