From 5c3c4a67330a6fb5fd086c6d6a2b4a1447e5648a Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 3 Jul 2018 00:34:33 +0100 Subject: [PATCH] Fix property-inspector Nasal module hookup We need to clone the binding nodes so that we can set / override the module on each binding, when opening a dialog multiple times. --- src/GUI/FGPUIDialog.cxx | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/GUI/FGPUIDialog.cxx b/src/GUI/FGPUIDialog.cxx index 2b017b739..23ee3ca78 100644 --- a/src/GUI/FGPUIDialog.cxx +++ b/src/GUI/FGPUIDialog.cxx @@ -1172,11 +1172,25 @@ FGPUIDialog::setupObject (puObject *object, SGPropertyNode *props) if (props->hasValue("key")) info->key = getKeyCode(props->getStringValue("key", "")); + for (auto bindingNode : bindings) { const char *cmd = bindingNode->getStringValue("command"); - if (!strcmp(cmd, "nasal")) - bindingNode->setStringValue("module", _module.c_str()); - + if (!strcmp(cmd, "nasal")) { + // we need to clone the binding node, so we can unique the + // Nasal module. Otherwise we always modify the global dialog + // definition, and cloned dialogs use the same Nasal module for + // bindings, which goes wrong. (Especially, the property + // inspector) + + // memory ownership works because SGBinding has a ref to its + // argument node and holds onto it. + SGPropertyNode_ptr copiedBinding = new SGPropertyNode; + copyProperties(bindingNode, copiedBinding); + copiedBinding->setStringValue("module", _module.c_str()); + + bindingNode = copiedBinding; + } + info->bindings.push_back(new SGBinding(bindingNode, globals->get_props())); } object->setCallback(action_callback);