studio icon indicating copy to clipboard operation
studio copied to clipboard

[Dashboard] SetVariable action will cause the original variable to be modified

Open dong-king opened this issue 1 year ago • 2 comments

Describe the bug

struct TREE_NODE:
{
    key: string,
    title: string,
    info: string
}

originalData and treeData are array:struct:TREE_NODE Use variable originalData to initialize treeData with SetVairable action. When the button is clicked, the info field of treeData is modified, and the info field of originalData is modified too.

Expected behavior originalData need remain unchanged.

Screenshots image

before clicking button: image

after clicking button: image

Desktop (please complete the following information):

  • OS: win10
  • eez-studio v0.13.0

dong-king avatar Jul 03 '24 11:07 dong-king

You need to use Array.clone(originalData) in SetVariable to make a deep clone of originalData.

mvladic avatar Jul 03 '24 12:07 mvladic

If Array.clone is not used then both treeData and originalData variables points to the same data.

mvladic avatar Jul 03 '24 12:07 mvladic