Skip to content

Modifying mutable option in DirectGui modifyes the default value #1587

@Augustifolia

Description

@Augustifolia

Description

It appears that when DirectGui saves the default value for some option, it saves the same object that you can access with gui["option"]. This means that modifying the option (if it is mutable, like a list) also modifies the default value.

Fixing this should not be that difficult. Just check if the object is mutable before the default value is saved. If it is mutable, create a copy to save.

Steps to Reproduce

from direct.showbase.ShowBase import ShowBase
from direct.gui.DirectGui import DirectButton

ShowBase()
gui = DirectButton()
print(gui.configure("extraArgs"))  # the default value is "[]" and the current value is "[]"
gui["extraArgs"].append(1)  # this not only modifies the current value, but also the default value
print(gui.configure("extraArgs"))  # this will now give us the default value "[1]" 

base.run()

Environment

  • Operating system: Linux Mint
  • System architecture: x86_64
  • Panda3D version: 1.10.13
  • Installation method: pip
  • Python version (if using Python): 3.11
  • Compiler (if using C++):

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdirectFor problems in `direct` as opposed to the engine coredirectgui

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions