From 862730999eef74cbc8795bd4a892bc9da896a5c5 Mon Sep 17 00:00:00 2001 From: torsten Date: Sun, 11 Oct 2009 11:57:58 +0000 Subject: [PATCH] Anders Gidenstam: I suspect that work around for the /ai/models/model-added listener problem (i.e. that the listener is called in the middle of the process of adding/removing a MP entry) isn't the right way to solve the problem. The attached patch instead defer processing of the added/removed MP entries in the multiplayer Nasal module until the next time the Nasal subsystem is executed. This should prevent the problematic execution of the Nasal listener callback in the middle of C++ MP code. --- Nasal/multiplayer.nas | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Nasal/multiplayer.nas b/Nasal/multiplayer.nas index 371101144..270650724 100644 --- a/Nasal/multiplayer.nas +++ b/Nasal/multiplayer.nas @@ -358,8 +358,16 @@ var model = { me.L = []; me.warned = {}; me.fg_root = string.normpath(getprop("/sim/fg-root")) ~ '/'; - append(me.L, setlistener("ai/models/model-added", func(n) me.update(n.getValue()))); - append(me.L, setlistener("ai/models/model-removed", func(n) me.update(n.getValue()))); + append(me.L, setlistener("ai/models/model-added", func(n) { + # Defer update() to the next convenient time to allow the + # new MP entry to become fully initialized. + settimer(func me.update(n.getValue()), 0); + })); + append(me.L, setlistener("ai/models/model-removed", func(n) { + # Defer update() to the next convenient time to allow the + # old MP entry to become fully deactivated. + settimer(func me.update(n.getValue()), 0); + })); me.update(); }, update: func(n = nil) { @@ -367,18 +375,13 @@ var model = { if (n != nil and changedNode.getName() != "multiplayer") return; - var changedNodeIndex = changedNode != nil ? changedNode.getIndex() : -1; - me.data = {}; me.callsign = {}; me.available = []; me.unavailable = []; foreach (var n; props.globals.getNode("ai/models", 1).getChildren("multiplayer")) { - # Ignore valid property for the newly added multiplayer aircraft. - # It is false when model-added is triggered and will become true after this - # listener is finished - if (n.getIndex() != changedNodeIndex and !n.getNode("valid", 1).getValue()) + if (!n.getNode("valid").getValue()) continue; if ((var callsign = n.getNode("callsign")) == nil or !(callsign = callsign.getValue()))