Merge pull request #1276 from CesiumGS/removed-credit-sources
cesium-native / Quick Checks (push) Waiting to run Details
cesium-native / Linting (push) Waiting to run Details
cesium-native / Documentation (push) Waiting to run Details
cesium-native / ${{matrix.platform}} / ${{matrix.build_type}} (Debug, windows-2022) (push) Waiting to run Details
cesium-native / ${{matrix.platform}} / ${{matrix.build_type}} (RelWithDebInfo, windows-2022) (push) Waiting to run Details
cesium-native / ${{matrix.platform}} / ${{matrix.compiler}} / ${{matrix.build_type}} (Debug, clang, macos-13) (push) Waiting to run Details
cesium-native / ${{matrix.platform}} / ${{matrix.compiler}} / ${{matrix.build_type}} (Debug, clang, ubuntu-22.04) (push) Waiting to run Details
cesium-native / ${{matrix.platform}} / ${{matrix.compiler}} / ${{matrix.build_type}} (Debug, gcc, ubuntu-24.04) (push) Waiting to run Details
cesium-native / ${{matrix.platform}} / ${{matrix.compiler}} / ${{matrix.build_type}} (RelWithDebInfo, clang, macos-13) (push) Waiting to run Details
cesium-native / ${{matrix.platform}} / ${{matrix.compiler}} / ${{matrix.build_type}} (RelWithDebInfo, clang, ubuntu-22.04) (push) Waiting to run Details
cesium-native / ${{matrix.platform}} / ${{matrix.compiler}} / ${{matrix.build_type}} (RelWithDebInfo, gcc, ubuntu-24.04) (push) Waiting to run Details
cesium-native / Emscripten v${{matrix.version}} ${{matrix.memory}}bit memory (32, 3.1.39) (push) Waiting to run Details
cesium-native / Emscripten v${{matrix.version}} ${{matrix.memory}}bit memory (32, 4.0.13) (push) Waiting to run Details
cesium-native / Emscripten v${{matrix.version}} ${{matrix.memory}}bit memory (64, 4.0.13) (push) Waiting to run Details

Report credits with destroyed source as removed.
This commit is contained in:
Janine Liu 2025-11-25 10:30:10 -05:00 committed by GitHub
commit 5b3b30e0d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 5 deletions

View File

@ -315,6 +315,11 @@ private:
CreditsSnapshot _snapshot;
std::vector<int32_t> _referenceCountScratch;
// These are credits that were shown in the last snapshot but whose
// CreditSources have since been destroyed. They need to be reported in
// removedCredits in the next snapshot.
std::vector<Credit> _shownCreditsDestroyed;
// Each entry in this vector is an index into _credits that is unused and can
// be reused for a new credit.
std::vector<size_t> _unusedCreditRecords;

View File

@ -191,7 +191,11 @@ CreditSystem::getSnapshot(CreditFilteringMode filteringMode) noexcept {
std::vector<Credit>& currentCredits = this->_snapshot.currentCredits;
std::vector<Credit>& removedCredits = this->_snapshot.removedCredits;
currentCredits.clear();
removedCredits.clear();
// Any credits that were shown last snapshot and whose sources have since been
// destroyed need to be reported in removedCredits.
removedCredits = this->_shownCreditsDestroyed;
this->_shownCreditsDestroyed.clear();
std::vector<int32_t>& effectiveReferenceCounts = this->_referenceCountScratch;
effectiveReferenceCounts.assign(this->_credits.size(), 0);
@ -290,6 +294,12 @@ void CreditSystem::createCreditSource(CreditSource& creditSource) noexcept {
void CreditSystem::destroyCreditSource(CreditSource& creditSource) noexcept {
for (CreditRecord& record : this->_credits) {
if (record.pSource == &creditSource) {
if (record.shownLastSnapshot) {
this->_shownCreditsDestroyed.emplace_back(Credit(
uint32_t(&record - this->_credits.data()),
record.generation));
}
record.pSource = nullptr;
++record.generation;
this->_unusedCreditRecords.emplace_back(&record - this->_credits.data());

View File

@ -243,7 +243,7 @@ TEST_CASE("Test CreditSystem with CreditSources") {
}
SUBCASE("when the source of a credit last frame is destroyed, that credit is "
"not reported") {
"reported in removedCredits") {
std::unique_ptr<CreditSource> pTempSourceA =
std::make_unique<CreditSource>(creditSystem);
Credit credit0 = creditSystem.createCredit(*pTempSourceA, html0);
@ -257,13 +257,14 @@ TEST_CASE("Test CreditSystem with CreditSources") {
// this credit would show up in the `removedCredits`.
creditSystem.removeCreditReference(credit0);
// Destroy the source. Now, the removed credit should no longer be reported
// in the next snapshot.
// Destroy the source. The removed credit should still be reported in the
// next snapshot.
pTempSourceA.reset();
const CreditsSnapshot& snapshot1 = creditSystem.getSnapshot();
CHECK(snapshot1.currentCredits.empty());
CHECK(snapshot1.removedCredits.empty());
CHECK(snapshot1.removedCredits.size() == 1);
CHECK(snapshot1.removedCredits[0] == credit0);
}
SUBCASE("CreditSystem may be destroyed before CreditSource") {