From 6608096ea3f7654a21d5af58babb2a8905dc6d32 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 21 Dec 2021 09:09:23 +0100 Subject: [PATCH] - added a bit more debug validation to the new clipper code. --- source/core/rendering/scene/hw_clipper.cpp | 42 ++++++++++++++++------ source/core/rendering/scene/hw_clipper.h | 1 + 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/source/core/rendering/scene/hw_clipper.cpp b/source/core/rendering/scene/hw_clipper.cpp index 602c0d723..91fc049b6 100644 --- a/source/core/rendering/scene/hw_clipper.cpp +++ b/source/core/rendering/scene/hw_clipper.cpp @@ -41,6 +41,25 @@ #include "printf.h" +//----------------------------------------------------------------------------- +// +// +// +//----------------------------------------------------------------------------- + +void Clipper::ValidateList() +{ +#ifdef _DEBUG + // Make sure we catch ordering issues right away in debug mode. + auto check = cliphead; + while (check) + { + assert(!check->next || check->end <= check->next->start); + check = check->next; + } +#endif +} + //----------------------------------------------------------------------------- // // RemoveRange @@ -61,6 +80,7 @@ void Clipper::RemoveRange(ClipNode * range, bool free) } if (free) Free(range); + ValidateList(); } //----------------------------------------------------------------------------- @@ -118,16 +138,7 @@ bool Clipper::InsertRange(ClipNode* prev, ClipNode* node) node->prev = prev; if (node->next) node->next->prev = node; -#ifdef _DEBUG - // Make sure we catch ordering issues right away in debug mode. - auto check = cliphead; - while (check) - { - assert(!check->next || check->end <= check->next->start); - check = check->next; - } -#endif - + ValidateList(); return false; } @@ -288,12 +299,14 @@ void Clipper::AddClipRange(int start, int end) } } // we're done and do not need to add a new node. + ValidateList(); return; } else { // if the old node is a window, restrict its size to the left of the new range and continue checking node->end = start; + ValidateList(); } } // range overlaps at the end. @@ -303,6 +316,7 @@ void Clipper::AddClipRange(int start, int end) if (node->topclip <= node->bottomclip) { node->start = start; + ValidateList(); return; } // node is a window - so restrict its size and insert the new node in front of it, @@ -460,6 +474,7 @@ void Clipper::AddWindowRange(int start, int end, float topclip, float bottomclip if (node->topclip < node->bottomclip) { start = node->end; + ValidateList(); if (start >= end) return; // may have been crushed to a single point. } else @@ -471,6 +486,7 @@ void Clipper::AddWindowRange(int start, int end, float topclip, float bottomclip if (mtopclip > mbottomclip && mtopclip >= node->topclip && mbottomclip <= node->bottomclip) { start = node->end; + ValidateList(); if (start >= end) return; // may have been crushed to a single point. } @@ -478,6 +494,7 @@ void Clipper::AddWindowRange(int start, int end, float topclip, float bottomclip else if (topclip <= bottomclip || (topclip < node->topclip && bottomclip > node->bottomclip)) { node->end = start; + ValidateList(); assert(node->end > node->start); // ensured by initial condition. } @@ -507,6 +524,7 @@ void Clipper::AddWindowRange(int start, int end, float topclip, float bottomclip if (node->topclip < node->bottomclip) { end = node->start; + ValidateList(); if (start >= end) return; // may have been crushed to a single point. } else @@ -518,6 +536,7 @@ void Clipper::AddWindowRange(int start, int end, float topclip, float bottomclip if (mtopclip > mbottomclip && mtopclip >= node->topclip && mbottomclip <= node->bottomclip) { end = node->start; + ValidateList(); if (start >= end) return; // may have been crushed to a single point. } @@ -525,6 +544,7 @@ void Clipper::AddWindowRange(int start, int end, float topclip, float bottomclip else if (topclip <= bottomclip || (topclip < node->topclip && bottomclip > node->bottomclip)) { node->start = end; + ValidateList(); assert(node->end > node->start); } @@ -533,7 +553,7 @@ void Clipper::AddWindowRange(int start, int end, float topclip, float bottomclip { int nodestart = node->start; SplitRange(node, nodestart, end, mtopclip, mbottomclip); - end = node->start; + end = nodestart; if (start >= end) return; // may have been crushed to a single point. if (mtopclip <= mbottomclip) next = cliphead; // list may have become out of sync. } diff --git a/source/core/rendering/scene/hw_clipper.h b/source/core/rendering/scene/hw_clipper.h index 4251c048f..ea0defeb0 100644 --- a/source/core/rendering/scene/hw_clipper.h +++ b/source/core/rendering/scene/hw_clipper.h @@ -70,6 +70,7 @@ private: bool InsertRange(ClipNode* prev, ClipNode* node); bool InsertBlockingRange(ClipNode* prev, ClipNode* node, int start, int end); void SplitRange(ClipNode* node, int start, int end, float topclip, float bottomclip); + void ValidateList(); public: