#9220·kivy

Graphics instructions don't seem to be designed to have multiple parents, yet there is no check preventing this.

Author: gottadiveintopythonCreated Nov 28, 2025Updated May 28, 2026
LabelsComponent: graphicsType: FeaturePriority: Low

Software Versions

  • Python: CPython 3.13
  • OS: Linux Mint
  • Kivy: 91dc72d7cc979f37e2b1344bf9edd5db7957bbd1 (master branch around Sep 2025)
  • Kivy installation method: development install ($ pip install -e ".[dev,full]")

Describe the bug

The Instruction class has an attribute that holds its parent.

https://github.com/kivy/kivy/blob/8ac27255c6c07e88577855c078eedfd16da66d0f/kivy/graphics/instructions.pxd#L22-L25

To me, this implies that graphics instructions cannot be shared between multiple parents.
However, when you run the following code, no error or warning is raised:

python
import kivy.core.window  # Ensures OpenGL context exists. This doesn't seem to matter, though.
from kivy.graphics import InstructionGroup, Color

g1 = InstructionGroup()
g2 = InstructionGroup()
color = Color()

g1.add(color)
g2.add(color)

I have made this mistake a couple of times when working with stencil instructions:

python
with canvas:
    StencilPush()
    shared = RoundedRectangle(...)
    StencilUse()
    ...
    StencilUnUse()
    canvas.add(shared)
    StencilPop()

I haven't encountered any incorrect rendering results from this, though. Still, I feel that some kind of check—or at least documentation—is neccesarry.

Additional context

InstructionGroup.add() calls Instruction.radd()

https://github.com/kivy/kivy/blob/8ac27255c6c07e88577855c078eedfd16da66d0f/kivy/graphics/instructions.pyx#L196-L201

which calls Instruction.set_parent()

https://github.com/kivy/kivy/blob/8ac27255c6c07e88577855c078eedfd16da66d0f/kivy/graphics/instructions.pyx#L107-L109

which performs no check.

https://github.com/kivy/kivy/blob/8ac27255c6c07e88577855c078eedfd16da66d0f/kivy/graphics/instructions.pyx#L121-L122