Howto:Troubleshooting Nasal Callbacks: Difference between revisions

Jump to navigation Jump to search
Line 90: Line 90:
|2= {{cite web
|2= {{cite web
   | url    = http://forum.flightgear.org/viewtopic.php?p=274633#p274633
   | url    = http://forum.flightgear.org/viewtopic.php?p=274633#p274633
  | title  = <nowiki>Re: 777 freezes and FPS loss</nowiki>
  | author = <nowiki>Hooray</nowiki>
  | date  = Jan 31st, 2016
  | added  = Jan 31st, 2016
  | script_version = 0.23
  }}
}}
{{FGCquote
|1= To learn more about timers and how they work in Nasal, see $FG_SRC/Scripting/NasalSys.cxx
The settimer() API is mapped to the f_settimer() C function here: http://sourceforge.net/p/flightgear/flightgear/ci/next/tree/src/Scripting/NasalSys.cxx#l781
The C code for this extension function can be seen here: http://sourceforge.net/p/flightgear/flightgear/ci/next/tree/src/Scripting/NasalSys.cxx#l471
That's only 3 lines of code, which ends up calling the FGNasalSys::setTimer() API at: http://sourceforge.net/p/flightgear/flightgear/ci/next/tree/src/Scripting/NasalSys.cxx#l1265
<dl class="codebox"><dt></dt></dl>
|2= {{cite web
  | url    = http://forum.flightgear.org/viewtopic.php?p=274643#p274643
  | title  = <nowiki>Re: 777 freezes and FPS loss</nowiki>
  | author = <nowiki>Hooray</nowiki>
  | date  = Jan 31st, 2016
  | added  = Jan 31st, 2016
  | script_version = 0.23
  }}
}}
{{FGCquote
|1= What  this will do is create a temporary NasalTimer object, for the class/struct refer to: http://sourceforge.net/p/flightgear/flightgear/ci/next/tree/src/Scripting/NasalSys.hxx#l163
It will then set up the NasalTimer object according to the arguments you passed to settimer() - and ultimately, it will invoke the event manager to register the timer object: http://sourceforge.net/p/flightgear/flightgear/ci/next/tree/src/Scripting/NasalSys.cxx#l1298
That really is all you need to know in order to check if a Nasal callback gets re-added, or if it is already running, because the "handler" parameter can be checked (e.g. use SG_LOG() to print out the address of the pointer).
Most of this would be also applicable to the setlistener() API, with the difference being that calls will not be specific to any particular subsystem like "events", but can be triggered by arbitrary subsystems which end up writing/modifying a property with a registered Nasal callback/listener.
These two are the most likely suspects when it comes to leaking callbacks and having redundant callbacks registered to be executed unnecessarily.
Note that the event manager lives in SimGear, and one simple thing you can do is to log the number of active timers to the console and/or to the property tree (e.g. using a propertyObject) - you will almost certainly see those grow over time, probably even with identical callbacks: http://api-docs.freeflightsim.org/simgear/classSGEventMgr.html
The other thing that can be done is to use SGTimeStamp::now() to benchmark the execution time of different callbacks.
None of this would be specific to the 777 - it would benefit any/all aircraft and other Nasal code suffering from these coding errors
Even if you don't feel comfortable writing C++ code, all you need to know is how to use the SG_LOG() macro to dump the sie of a the timer queue: http://api-docs.freeflightsim.org/simgear/classSGTimerQueue.html
It's '''_numEntries''' that's relevant here, which is private, but can be exposed by adding a corresponding method
|2= {{cite web
  | url    = http://forum.flightgear.org/viewtopic.php?p=274643#p274643
   | title  = <nowiki>Re: 777 freezes and FPS loss</nowiki>
   | title  = <nowiki>Re: 777 freezes and FPS loss</nowiki>
   | author = <nowiki>Hooray</nowiki>
   | author = <nowiki>Hooray</nowiki>

Navigation menu