Swatch disappears on original object when deleting clones

Summary:

In specific circumstances involving an object with a swatch applied, which is cloned multiple times, will have its swatch removed when the clones are deleted.

Steps to reproduce:

  1. open Inkscape, new file
  2. Create a text object, with no stroke and a fill using a swatch (just click the swatch icon)
  3. Create a rectangle with no fill and any stroke
  4. Group the text and rectangle
  5. Clone the group
  6. Duplicate the clone twice
  7. Delete all three clones
  8. Toggle layer visibility off and on (to force a redraw)

What happened?

The original text is no longer visible.

What should have happened?

The text should still be visible. ...

Sample attachments:

drawing.svg

This file was created between step 4. and 5. Saving a file after step 6. cannot reproduce the problem, unless you delete both clones, undo that, and delete both clones again, so it seems to happen only when at least one (it seems) clone has been created in the current inkscape session.

Some additional observations:

  • The swatch is implemented using a fill style that refers to a first linearGradient object, with a href pointing to a second linearGradient. When multiple objects use the same swatch, they share the second linearGradient, but each have a unique first linearGradient (so the first one links the object to the second, the actual swatch that also carries the swatch name).
  • When this problem happens, this first linearGradient object is deleted, making the original text object's fill style refer to a non-exist id.
  • Cloning the text directly, or omitting the rect from the group prevents reproducing the problem.
  • Making two clones (instead of duplicating the first clone) does not seem to reproduce the problem.
  • A swatch applied to another rect instead of a text does not show the problem, so this seems to be text-specific somehow.
  • This also happens when undo-ing, e.g. select two clones (that seems sufficient), duplicate them, undo, and the problem occurs.
  • Reproducing is prettty reliable, though sometimes it is also a bit unexpected (it seems I need one clone and two duplicates directly after loading the sample file, but after some duplicating and undo'ing, just one clone and one duplicate seems sufficient).
  • The problem also occurs when deleting the clones one by one (sometimes already when deleting two of them).

Version info

Originally noticed on Inkscape 1.1, but still happens on a few weeks old dev version:

Inkscape 1.2-dev (e371b2f82, 2022-01-29, custom)

    GLib version:     2.68.4
    GTK version:      3.24.30
    glibmm version:   2.64.2
    gtkmm version:    3.24.5
    libxml2 version:  2.9.12
    libxslt version:  1.1.34
    Cairo version:    1.16.0
    Pango version:    1.48.10
    HarfBuzz version: 2.7.4

    OS version:       Ubuntu 21.10
Edited by Matthijs Kooijman