Only draw caches owned by the cache object are checked

This commit is contained in:
Yousef Khadadeh 2025-08-12 20:10:09 +03:00
parent e5e885794a
commit 1f412a0046
2 changed files with 9 additions and 5 deletions

View file

@ -46,8 +46,12 @@ void DrawingProgramCache::clear() {
}
void DrawingProgramCache::clear_own_cached_surfaces() {
std::erase_if(nodesWithCachedSurfaces, [&](auto& s) {
return s->drawCache.value().attachedCache == this;
std::erase_if(nodesWithCachedSurfaces, [&](auto& n) {
if(n->drawCache.value().attachedCache == this) {
n->drawCache = std::nullopt;
return true;
}
return false;
});
}
@ -251,7 +255,7 @@ void DrawingProgramCache::invalidate_cache_before_pos(uint64_t placementToInvali
// For now, we will ignore worldAABB and just clear cache by placement in list
std::erase_if(nodesWithCachedSurfaces, [&](auto& n) {
if(placementToInvalidateAt <= n->drawCache.value().lastDrawnComponentPlacement) {
if(n->drawCache.value().attachedCache == this && placementToInvalidateAt <= n->drawCache.value().lastDrawnComponentPlacement) {
n->drawCache = std::nullopt;
return true;
}
@ -268,7 +272,7 @@ void DrawingProgramCache::invalidate_cache_at_optional_aabb_before_pos(const std
void DrawingProgramCache::invalidate_cache_at_aabb_before_pos(const SCollision::AABB<WorldScalar>& aabb, uint64_t placementToInvalidateAt) {
std::for_each(nodesWithCachedSurfaces.begin(), nodesWithCachedSurfaces.end(), [&](auto& n) {
if(SCollision::collide(aabb, n->bounds)) {
if(n->drawCache.value().attachedCache == this && SCollision::collide(aabb, n->bounds)) {
auto& dCache = n->drawCache.value();
if(dCache.invalidBounds.has_value()) {
auto& iBounds = dCache.invalidBounds.value();

View file

@ -26,7 +26,7 @@ void EraserTool::switch_tool(DrawingProgramToolType newTool) {
// NOTE: Ideally, you would just recalculate the lastDrawnPos of every cache instead of invalidating and redrawing the caches
// However, the eraser might have other visual glitches during drawing that i am unaware of, so for now, just refresh the
// cache after a draw
drawP.compCache.invalidate_cache_before_pos(0);
drawP.compCache.clear_own_cached_surfaces();
}
erasedComponents.clear();
erasedBVHNodes.clear();