Skip to content

Fix infinite document update loop caused by filter bounding box calculations

This MR fixes issue #3797 which made Inkscape freeze when manipulating certain documents containing filters. In fact, doing File > Open and navigating to the file was enough to freeze Inkscape when preview was enabled.

The root cause of the problem was an infinite document update loop caused by an unbounded growth of the computed bounding boxes of filter regions. This problem occurred primarily when the same filter was applied to a group and its parent group.

The most important part of the fix has to do with the removal of this comment:

// Calling bbox instead of visualBound() avoids re-requesting filter regions
 Geom::OptRect v_box = item->bbox(Geom::identity(), SPItem::VISUAL_BBOX);

The intent of the comment is correct: we are calculating the bounding box of a filtered item from its original bounding box, so we must not take filters into account when computing that original box, otherwise there will be an infinite recursion.

However, the comment's conclusion is incorrect because calling bbox() does not always do the right thing. In fact, SPGroup::bbox() calls SPItem::bounds() which in turn will call SPItem::visualBounds() with default arguments, and these do not cause filters to be ignored.

Upon inspecting the code, I found out that there was no way to compute the visual bounding box of a group with filters turned off. So a part of the fix is to override visualBounds() for the class SPGroup in a way that forwards all of the arguments to the group's children's visual bounds calls. In this way, the request to ignore filters can be propagated to any level of nesting.

Fixes #3797
Fixes #3833 (closed)

Edited by Rafał Siejakowski

Merge request reports