Race condition in inkex.command.inkscape

Summary:

Repeatedly calling out to inkex.command.inkscape to compute a bounding box (using arguments -X, -Y, -W, and -H) will, on rare occasions, return incorrect values.

Steps to reproduce:

  • Extract into your Inkscape extensions directory the contents of the bbox-bug.zip file (see Sample Attachments below).
  • Repeatedly launch Inkscape and run ExtensionsRenderBounding Box Bug to try to trigger the race condition. I recommend automating this process with the Bash command,
for i in $(seq -w 20) ; do
    inkscape --with-gui --actions="org.pakin.filter.bbox-bug;export-filename:test$i.svg;export-do;quit" ;
done
  • Brew a cup of coffee while you wait for the preceding command to complete. 😀

What happened?

Roughly every 6–7 runs, one (or in very rare cases, more than one) of the text objects appears in the wrong location:

bad-run.svg

What should have happened?

As there is no randomness in the extension code, all text objects should be placed as follows on every run:

good-run.svg

Sample attachments:

The following extension can be used to reproduce the problem: bbox-bug.zip

The bbox-bug extension code was derived from the draw.py script included in Simple Inkscape Scripting issue #74, "Text position is lost randomly". Simple Inkscape Scripting is an Inkscape extension that helps automate repetitive drawing tasks. bbox-bug is a standalone version of the failing code with no dependency on Simple Inkscape Scripting.

Version info

Inkscape 1.3-dev (c5490bb, 2023-02-09)

    GLib version:     2.64.6
    GTK version:      3.24.20
    glibmm version:   2.64.2
    gtkmm version:    3.24.2
    libxml2 version:  2.9.10
    libxslt version:  1.1.34
    Cairo version:    1.17.7
    Pango version:    1.44.7
    HarfBuzz version: 2.6.4

    OS version:       Ubuntu 22.10