Skip to content

Shape Headling - Crash and Stack with Moebius#998

Open
dpasukhi wants to merge 8 commits intoOpen-Cascade-SAS:IRfrom
dpasukhi:shape_healing_mebius
Open

Shape Headling - Crash and Stack with Moebius#998
dpasukhi wants to merge 8 commits intoOpen-Cascade-SAS:IRfrom
dpasukhi:shape_healing_mebius

Conversation

@dpasukhi
Copy link
Member

No description provided.

Modifications in historical order:

/Users/dpasukhi/work/OCCT/src/ModelingAlgorithms/TKShHealing/GTests/ShapeUpgrade_UnifySameDomain_Test.cxx.cxx, BasicTest() - entry point

ShapeBuild_ReShape - added method ApplyImpl().
This is to prevent initial stackoverflow. Same implementation as original Apply() but accepts map of visited shapes.
If shape is found in the map, doesn't perform the recursive call.

ShapeProcess_ShapeContext.cxx, function RecModif()
Added map of visited shapes to prevent infinite loop in do/while cycle.
It exits the loop when encounters already visited shape.

ShapeExtend_WireData - added std::unordered set that duplicates the content of mySeams.
This is to prevent quase-infinite loop when calling ShapeExtend_WireData::IsSeam(const int num).
It was simply searching for the 'num' in the list mySeams that took enormous amount of time.

ShapeFix_Edge::FixVertexTolerance(const TopoDS_Edge& edge, const TopoDS_Face& face)
ShapeFix_Edge::FixVertexTolerance(const TopoDS_Edge& edge)
Added check that object returned by Context()->Apply(edge) is actually an edge.
Due to presumably incorrect previous processing it could return Wire which caused a crush.

ShapeFix_Wire, ShapeFix_Face
Latest attempts to add Message_ProgressRange. Didn't work for some reason.

Current state:

Stuck in quase-infinite (so long so it might as well be considered infinite) loop inside ShapeFix_Wire::Perform()
trying to fix the wire with more then 1'000'000 edges.
@dpasukhi dpasukhi requested a review from Copilot January 13, 2026 21:02
@dpasukhi dpasukhi self-assigned this Jan 13, 2026
@dpasukhi dpasukhi added the 1. Shape Healing Shape healing operation (fixing topology issue with BRep data) label Jan 13, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses crashes and stack overflow issues when processing shapes with non-orientable surfaces like Moebius strips. The changes prevent infinite loops from cyclic replacements and exponential edge growth from shared context.

Changes:

  • Added cycle detection in shape replacement chains to prevent infinite loops
  • Optimized wire update logic to prevent O(n²) behavior and edge explosion
  • Added progress tracking support to enable cancellation of long-running operations
  • Improved performance of seam detection with hash-based lookups

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ShapeProcess_ShapeContext.cxx Adds visited shapes tracking to prevent infinite loops in replacement chains
ShapeFix_Wire.hxx Adds progress tracking parameter and new wire update control parameter
ShapeFix_Wire.cxx Implements progress checks, optimizes UpdateWire to use Value() instead of Apply(), and prevents duplicate edge expansion
ShapeFix_IntersectionTool.cxx Prevents duplicate wires from being added to processing sequence
ShapeFix_Face.hxx Adds progress tracking parameter
ShapeFix_Face.cxx Propagates progress tracking to wire fixing
ShapeFix_Edge.cxx Adds validation for shape type after context application
ShapeExtend_WireData.hxx Adds cache for seam edge lookups
ShapeExtend_WireData.cxx Implements O(1) seam lookup using hash set
ShapeBuild_ReShape.cxx Refactors Apply() to use helper structure that defers replacement registration until after recursion completes

{
FixConnected(i, prec);
// Call without UpdateWire to avoid O(n^2) behavior in the loop
FixConnected(i, prec, false);
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'Headling' to 'Healing' in PR title.

Suggested change
FixConnected(i, prec, false);
(void)FixConnected(i, prec, false);

Copilot uses AI. Check for mistakes.
Comment on lines +54 to +57
//! Recursively applies substitutions to a shape.
//! @param theShape the shape to process
//! @param theUntil the shape type at which to stop recursion
//! @return the processed shape (original or replacement)
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment refers to 'theUntil' but the parameter is named 'theUntil' with capital U. The documentation should match the actual parameter name for consistency.

Suggested change
//! Recursively applies substitutions to a shape.
//! @param theShape the shape to process
//! @param theUntil the shape type at which to stop recursion
//! @return the processed shape (original or replacement)
//! @param theShape the shape to process
//! @param theUntil the shape type at which to stop recursion
//! @return the processed shape (original or replacement)
//! @return the processed shape (original or replacement)

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +29
#include <TColStd_PackedMapOfInteger.hxx>

Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The blank line after the include directive is inconsistent with the surrounding include block style. Consider removing the extra blank line for consistency with the rest of the header.

Copilot uses AI. Check for mistakes.
@dpasukhi dpasukhi changed the base branch from master to IR January 13, 2026 21:27
@github-project-automation github-project-automation bot moved this from Todo to Integration in Maintenance Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1. Shape Healing Shape healing operation (fixing topology issue with BRep data)

Projects

Status: Integration

Development

Successfully merging this pull request may close these issues.

3 participants