From 1415ccca61fc7295a4a20b59c55d2f2450dab928 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 2 Jul 2021 15:11:33 +0200 Subject: [PATCH] pgraph: Fix assertion error in get_num_unused_states() Fixes #1172 --- panda/src/pgraph/renderState.cxx | 9 +++++++++ panda/src/pgraph/transformState.cxx | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/panda/src/pgraph/renderState.cxx b/panda/src/pgraph/renderState.cxx index fdc187ecbb..3bdb4096f1 100644 --- a/panda/src/pgraph/renderState.cxx +++ b/panda/src/pgraph/renderState.cxx @@ -752,6 +752,14 @@ get_num_unused_states() { for (size_t si = 0; si < size; ++si) { const RenderState *state = _states->get_key(si); + std::pair ir = + state_count.insert(StateCount::value_type(state, 1)); + if (!ir.second) { + // If the above insert operation fails, then it's already in the + // cache; increment its value. + (*(ir.first)).second++; + } + size_t i; size_t cache_size = state->_composition_cache.get_num_entries(); for (i = 0; i < cache_size; ++i) { @@ -1865,6 +1873,7 @@ init_states() { // is declared globally, and lives forever. RenderState *state = new RenderState; state->local_object(); + state->cache_ref_only(); state->_saved_entry = _states->store(state, nullptr); _empty_state = state; } diff --git a/panda/src/pgraph/transformState.cxx b/panda/src/pgraph/transformState.cxx index efbb97f2bb..5a95e6871d 100644 --- a/panda/src/pgraph/transformState.cxx +++ b/panda/src/pgraph/transformState.cxx @@ -1025,6 +1025,14 @@ get_num_unused_states() { for (size_t si = 0; si < size; ++si) { const TransformState *state = _states->get_key(si); + std::pair ir = + state_count.insert(StateCount::value_type(state, 1)); + if (!ir.second) { + // If the above insert operation fails, then it's already in the + // cache; increment its value. + (*(ir.first)).second++; + } + size_t i; size_t cache_size = state->_composition_cache.get_num_entries(); for (i = 0; i < cache_size; ++i) {