net-lisias-ksp / DistantObject

Distant Object Enhancement (DOE) is a visual enhancement mod that makes objects realistically visible over large distances.
Other
10 stars 3 forks source link

Probable race condition when the vessel being drawn enters on the physics range. #12

Closed Lisias closed 2 years ago

Lisias commented 2 years ago

Fellow Kerbonaut Krazy1 found something interesting:

ust FYI, I saw some errors in my log. I only looked because I was getting EXC spam on something else (ModuleDockingNode. I believe they're unrelated). This was during rendezvous and docking.

[LOG 13:49:58.862] [DistantObject] ERROR: Tried to draw part hinge.03.s within rendering distance of active vessel! at error:0
[LOG 13:49:58.878] [DistantObject] ERROR: Tried to draw part hinge.03.s within rendering distance of active vessel! at error:0
[LOG 13:49:58.878] [DistantObject] ERROR: Tried to draw part solarPanels5 within rendering distance of active vessel! at error:0
[LOG 13:49:58.896] [DistantObject] ERROR: Tried to draw part trussPiece1x within rendering distance of active vessel! at error:0
…

log.zip

My best guess to this point is that he found a borderline situation: the craft entered into Physics Range in the exact same moment DOE checked if it was loaded or not, and we got a race condition.

Thinking about, I need to put something on the FixedUpdated handler. One of the speed ups I made was to remove the mesh building phase from the FixedUpdate (as it was before), and besides this handler is called fewer times then Update, it is called from the hottest code on the Game, the Physics Engine. But now I realised that there was a reason for using the FixedUpdated.

I will need to rework a bit this thing - shoving everything on FixedUpdate is not an option, I will not put render time code inside on the Physics Engine loop.

In the mean time, this bug is harmless - other than spamming a bit the KSP.log, nothing bad happens as the code abort the drawing.

Lisias commented 2 years ago

Thinks appears to be simpler than that. I was just "commiting" the Settings changes disregarding the current scene, and so VesselDraw was being ignited when it should not.

So it ended having always the current vessel on the database already and starting the scene without housekeeping the DB.

This was fixed by side effect on Release https://github.com/net-lisias-ksp/DistantObject/releases/tag/RELEASE%2F2.1.1.6 that essentially reworked VesselDraw and eliminated the problem.

So I'm closing this and marking it as 2.1.1.6 milestone.