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

Support for mutable lambdas in catch functions. #952

Merged
merged 2 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
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");
}
}
}
Loading