Skip to content

Commit

Permalink
Rename, doc, test, CHANGES.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Dec 7, 2023
1 parent 0aa888d commit 262846e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

### ? - ?

##### Fixes :wrench:

- Fixed a crash in `SubtreeAvailability::loadSubtree`.

### v0.30.0 - 2023-12-01

##### Breaking Changes :mega:
Expand Down
6 changes: 3 additions & 3 deletions Cesium3DTilesContent/src/SubtreeAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ SubtreeAvailability::loadSubtree(
const std::shared_ptr<spdlog::logger>& pLogger,
const std::string& subtreeUrl,
const std::vector<CesiumAsync::IAssetAccessor::THeader>& requestHeaders) {
auto reader = std::make_shared<SubtreeFileReader>();
return reader->load(asyncSystem, pAssetAccessor, subtreeUrl, requestHeaders)
auto pReader = std::make_shared<SubtreeFileReader>();
return pReader->load(asyncSystem, pAssetAccessor, subtreeUrl, requestHeaders)
.thenInMainThread(
[pLogger, subtreeUrl, subdivisionScheme, levelsInSubtree, reader](
[pLogger, subtreeUrl, subdivisionScheme, levelsInSubtree, pReader](
ReadJsonResult<Subtree>&& subtree)
-> std::optional<SubtreeAvailability> {
if (!subtree.value) {
Expand Down
7 changes: 4 additions & 3 deletions Cesium3DTilesContent/test/TestSubtreeAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <CesiumGeometry/QuadtreeTileID.h>
#include <CesiumNativeTests/SimpleAssetAccessor.h>
#include <CesiumNativeTests/SimpleTaskProcessor.h>
#include <CesiumNativeTests/ThreadTaskProcessor.h>
#include <CesiumNativeTests/waitForFuture.h>

#include <catch2/catch.hpp>
#include <libmorton/morton.h>
Expand Down Expand Up @@ -284,7 +286,7 @@ std::optional<SubtreeAvailability> mockLoadSubtreeJson(
std::make_shared<SimpleAssetAccessor>(std::move(mapUrlToRequest));

// mock async system
auto pMockTaskProcessor = std::make_shared<SimpleTaskProcessor>();
auto pMockTaskProcessor = std::make_shared<ThreadTaskProcessor>();
CesiumAsync::AsyncSystem asyncSystem{pMockTaskProcessor};

auto subtreeFuture = SubtreeAvailability::loadSubtree(
Expand All @@ -296,8 +298,7 @@ std::optional<SubtreeAvailability> mockLoadSubtreeJson(
"test",
{});

asyncSystem.dispatchMainThreadTasks();
return subtreeFuture.wait();
return waitForFuture(asyncSystem, std::move(subtreeFuture));
}
} // namespace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class CESIUM3DTILESREADER_API SubtreeFileReader {
/**
* @brief Asynchronously loads a subtree from a URL.
*
* Please note that the `SubtreeFileReader` instance must remain valid until
* the returned future resolves or rejects. Destroying it earlier will result
* in undefined behavior. One easy way to achieve this is to construct the
* reader with `std::make_shared` and capture the `std::shared_ptr` in the
* continuation lambda.
*
* @param asyncSystem The AsyncSystem used to do asynchronous work.
* @param pAssetAccessor The accessor used to retrieve the URL and any other
* required resources.
Expand Down
14 changes: 14 additions & 0 deletions CesiumNativeTests/include/CesiumNativeTests/ThreadTaskProcessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <CesiumAsync/ITaskProcessor.h>

#include <thread>

namespace CesiumNativeTests {
class ThreadTaskProcessor : public CesiumAsync::ITaskProcessor {
public:
virtual void startTask(std::function<void()> f) override {
std::thread(f).detach();
}
};
} // namespace CesiumNativeTests

0 comments on commit 262846e

Please sign in to comment.