[go: up one dir, main page]

Infinite loop when using iterdescendants and moving elements around

Might be an upstream issue? Just documenting what I found.

import inkex

svg  = inkex.load_svg("""
<svg xmlns="http://www.w3.org/2000/svg">
    <defs>
        <g>
            <symbol>
                <path id='p1'/>
            </symbol>
            <symbol>
                <path id='p2'/>
            </symbol>
        </g>
    </defs>
</svg>""").getroot()

svg2 = inkex.SvgDocumentElement()
for def_child in svg.defs.iterdescendants():
    print("Current element: " + def_child.get_id())
    print([i.get_id() for i in svg.defs.iterdescendants()])
    
    if not isinstance(def_child, inkex.Symbol):
        svg2.defs.append(def_child)

Output (truncated):

Current element: g1580
['g1580', 'symbol5341', 'p1', 'symbol6619', 'p2']
Current element: symbol5341
[]
Current element: p1
[]
Current element: symbol6619
[]
Current element: p2
[]
Current element: p1
[]
Current element: p2
[]
Current element: p1
[]
Current element: p2
[]

The conditions seem to be minimal. The error doesn't occur

  • without the svg2.defs.append(def_child) call
  • without the filter for Symbols (PathElement and Group instead of Symbol is alright)
  • with only one symbol
  • without the wrapping group in the defs
Edited by Jonathan Neuhauser