Skip to content

Commit

Permalink
Merge pull request #952 from CesiumGS/mutable-catch-lambda
Browse files Browse the repository at this point in the history
Support for mutable lambdas in `catch` functions.
  • Loading branch information
j9liu authored Sep 30, 2024
2 parents f646271 + c7268cc commit 31e93ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- `GltfUtilities::intersectRayGltfModel` now reports a warning when given a model it can't compute the intersection with because it uses required extensions that are not supported.
- Errors while loading raster overlays are now logged. Previously, they were silently ignored in many cases.
- A raster overlay image failing to load will no longer completely prevent the geometry tile to which it is attached from rendering. Instead, once the raster overlay fails, the geometry tile will be shown without the raster overlay.
- Fixed a bug in the various `catchImmediately` and `catchInMainThread` functions in `CesiumAsync` that prevented use of a mutable lambda.

### v0.39.0 - 2024-09-02

Expand Down
4 changes: 2 additions & 2 deletions CesiumAsync/include/CesiumAsync/Impl/CatchFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct CatchFunction {
} catch (...) {
// Make an exception_ptr task, then scheduler to a wrapper around f that
// throws it, catches it, and calls f with a reference to it.
auto ptrToException = [f = std::move(f)](std::exception_ptr&& e) {
auto ptrToException = [f = std::move(f)](std::exception_ptr&& e) mutable {
try {
std::rethrow_exception(e);
} catch (std::exception& e) {
Expand Down Expand Up @@ -52,7 +52,7 @@ struct CatchFunction<Func, void, Scheduler, TaskParameter> {
} catch (...) {
// Make an exception_ptr task, then scheduler to a wrapper around f that
// throws it, catches it, and calls f with a reference to it.
auto ptrToException = [f = std::move(f)](std::exception_ptr&& e) {
auto ptrToException = [f = std::move(f)](std::exception_ptr&& e) mutable {
try {
std::rethrow_exception(e);
} catch (std::exception& e) {
Expand Down
18 changes: 18 additions & 0 deletions CesiumAsync/test/TestAsyncSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,5 +701,23 @@ TEST_CASE("AsyncSystem") {
CHECK_THROWS(future.waitInMainThread());
CHECK(!called);
}

SECTION(
"catchImmediately can return a value from a mutable lambda capture") {
auto promise = asyncSystem.createPromise<std::string>();
promise.reject(std::runtime_error("Some exception"));
std::string myValue = "value from catch";
Future<std::string> future =
promise.getFuture()
.catchImmediately([myValue = std::move(myValue)](
std::exception&& exception) mutable {
CHECK(std::string(exception.what()) == "Some exception");
return myValue;
})
.thenImmediately(
[](std::string&& result) { return std::move(result); });
std::string result = future.waitInMainThread();
CHECK(result == "value from catch");
}
}
}

0 comments on commit 31e93ac

Please sign in to comment.