TwinFan / LiveTraffic

LiveTraffic is an X-Plane multiplayer plugin, which fills your sky with live air traffic based on public flight tracking data.
https://twinfan.gitbook.io/livetraffic/
Other
99 stars 24 forks source link

No X-Plane SDK calls from outside main thread #190

Closed TwinFan closed 4 years ago

TwinFan commented 4 years ago

Describe the bug Calling X-Plane SDK functions from outside XP's main thread is and has always been forbidden. A recent crash unveiled that there might be overlooked examples.

Ben Supnik in a mail also very clearly stated that restrictions might be enforced even more in future versions:

Thanks for looking into this - the main thread rule applies to every AI call, so please just make sure that everything gets deferred back to the main thread even loggign calls. The sim will only kill you for some calls now but it will be all calls in the future, matching the API spec.

In the above mentioned case, calls to SHOW_MSG were handled by deferring creation of the message area window.

Todo

To be changed centrally:

Technical Info:

Additional Info Blog post on thread-validation in Beta 14

TwinFan commented 4 years ago

Aircraft invalidation happens from the "CalcPosThread" (LTFlightData.cpp:657 in LTFlightData::DataCleansing()), which can now crash XP. Has been reported twice in the support forum (one, two) and looks like this in the log:

1:54:40.620 LiveTraffic DEBUG LTFlightData.cpp:1534/IsPosOK: AB6784 N834DC: Invalid vector <h 282,   108m @ -83kt, -nan(ind)ft/m> with headingDiff = 151
1:54:40.620 LiveTraffic DEBUG LTFlightData.cpp:1534/IsPosOK: AB6784 N834DC: Invalid vector <h 139,   801m @ 173kt, 1912ft/m> with headingDiff = -144
1:54:40.620    LT/XPMP2 ERROR Aircraft.cpp:615/SetInvalid: Aircraft 0xAB6784 set INVALID
1:54:40.620 E/SYS: THREAD FATAL ASSERT: rel_assert Error! Possibly an out of range vector! Attach the debugger and see who called this!
1:54:40.620 E/SYS: THREAD FATAL ASSERT: !THREAD_is_inited() || THREAD_is_main_thread()
1:54:40.620 E/SYS: THREAD FATAL ASSERT: XPDestroyInstance
1:54:40.620 E/SYS: THREAD FATAL ASSERT: Please report this to Laminar Research.
1:54:40.620 E/SYS: THREAD FATAL ASSERT: C:\jenkins\design-triggered\source_code\engine\plugins\glue\XPCallbacks.cpp:2658
--=={This application has crashed!}==--
TwinFan commented 4 years ago

Technically all done.

But we'll need to fix a shortcoming in logging, especially in picking the network time, with which all log lines start: In the current implementation there is no guarantee that the cached value is update before the first fetch in a new flight loop cycle. Rather, update is called from fixed points. That means that sometimes messages are logged with outdated network time stamps if they happen before the update is called.

We probably need to handle the cache differently: Always fetch the dataRef and update the cache value when in main thread.