Software Versions
- Python: CPython 3.13
- OS: Linux Mint
- Kivy: 91dc72d (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.
|
cdef class Instruction(ObjectWithUid): |
|
cdef int flags |
|
cdef public str group |
|
cdef InstructionGroup parent |
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:
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:
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()
|
cpdef add(self, Instruction c): |
|
'''Add a new :class:`Instruction` to our list. |
|
''' |
|
c.radd(self) |
|
self.flag_data_update() |
|
return |
which calls Instruction.set_parent()
|
cdef void radd(self, InstructionGroup ig): |
|
ig.children.append(self) |
|
self.set_parent(ig) |
which performs no check.
|
cdef void set_parent(self, Instruction parent): |
|
self.parent = parent |
Software Versions
$ pip install -e ".[dev,full]")Describe the bug
The
Instructionclass has an attribute that holds its parent.kivy/kivy/graphics/instructions.pxd
Lines 22 to 25 in 8ac2725
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:
I have made this mistake a couple of times when working with stencil instructions:
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()callsInstruction.radd()kivy/kivy/graphics/instructions.pyx
Lines 196 to 201 in 8ac2725
which calls
Instruction.set_parent()kivy/kivy/graphics/instructions.pyx
Lines 107 to 109 in 8ac2725
which performs no check.
kivy/kivy/graphics/instructions.pyx
Lines 121 to 122 in 8ac2725