From 1f412a00463715e2f1ca270beb0477abd609cfac Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Tue, 12 Aug 2025 20:10:09 +0300 Subject: [PATCH] Only draw caches owned by the cache object are checked --- src/DrawingProgram/DrawingProgramCache.cpp | 12 ++++++++---- src/DrawingProgram/EraserTool.cpp | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/DrawingProgram/DrawingProgramCache.cpp b/src/DrawingProgram/DrawingProgramCache.cpp index 410da06..0b7b319 100644 --- a/src/DrawingProgram/DrawingProgramCache.cpp +++ b/src/DrawingProgram/DrawingProgramCache.cpp @@ -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& 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(); diff --git a/src/DrawingProgram/EraserTool.cpp b/src/DrawingProgram/EraserTool.cpp index d072a49..8f17e98 100644 --- a/src/DrawingProgram/EraserTool.cpp +++ b/src/DrawingProgram/EraserTool.cpp @@ -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();