Board index FlightGear Development Nasal

remove listener odd count

Nasal is the scripting language of FlightGear.

remove listener odd count

Postby gkick » Tue Jun 18, 2019 2:01 am

Hi all,

attempting to improve performance and part of that is to remove onetime listeners once the event has been triggered. Found this piece of code I think
in the function library and it seems to do the right thing, that is if a fire up fg and the aircraft the console tells me I have 221 odd listeners
remaining, yet once I want to check if another listener has been removed because lets say wow has changed, the same code now tells me there are now 414 listeners
remaining even though no additional code was added?

here is the code

Code: Select all
var ls = setlistener("/sim/test", func(){
                           print("Property '/sim/test' has been changed");
                        });
                        setprop("/sim/test", "blah"); # trigger listener
                        var rem = removelistener(ls); # remove listener
                        gui.popupTip("There are  " ~ rem ~ " listeners open  " , 4);


So where do the extras come from ? C++ ?
gkick
 
Posts: 106
Joined: Sun Jan 01, 2017 11:04 pm

Re: remove listener odd count

Postby wkitty42 » Tue Jun 18, 2019 11:07 am

just reading your verbal description of the listeners increasing seems to indicate that a loop has run and possibly duplicated some existing listeners... there was a similar problem a little while back that resulted in similar which caused FG to lag more and more and more until it was basically inoperable... i forget what the actual fix was but it involved moving the instantiation of the listeners outside of the loop... looking at your numbers, an eWAG seems to indicate that 28 listeners are either outside the loop or they have checks to see if they are already instantiated or not...

which craft are you working on?
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5502
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: remove listener odd count

Postby gkick » Tue Jun 18, 2019 1:35 pm

Hi, thanks for the response the explanation making sense. Could well be my coding, cut. paste, trial and error....
Working on the FG Platypus based on the PA28-Warrior
github.com/inmavi
gkick
 
Posts: 106
Joined: Sun Jan 01, 2017 11:04 pm

Re: remove listener odd count

Postby wkitty42 » Tue Jun 18, 2019 9:09 pm

yeah, you def don't want listeners being duplicated over the loops... they can bring the sim to its knees and if it is too late to quit the sim, the system may very well follow it to its knees, too...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5502
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5


Return to Nasal

Who is online

Users browsing this forum: No registered users and 1 guest