Skip to content

Current FitNode can crash or modifiy itself when being printed

Alright my friends buckle up for what is going to be a fun ride 🎢

It probably took me way too long to figure it out but at least it's another bug that's fun to remember.

Our current FitNode class has some interesting behavior when printing it via e.g. info() << yourFitNode << endmsg.
The class has it's own nice overloaded print function which makes printing the entire thing easy and nice.
But then you try debugging with it and start wondering... hey something isn't adding up here. These values don't make sense....
Let's put another print further at the top to follow the modifications you say to yourself... but 💥 SegFault
Now for brevity (or has that ship sailed already? ) I'm not going to take you along for the entire debugging ride but point to the error.

Here in the print function the node actually calls its state function, defined here.
The return value however depends on the member m_parent, a pointer to a KalmanFitResult object. Dereferencing this pointer when printing a FitNode before it's been made aware of it's parent leads to a SegFault (deref of nullptr 💥 ) .
Normally FitNodes are in a NodeContainer inside a KalmanFitResult, and the code eventually calls establishNodeLinks which sets this pointer.
So our current code works fine if you don't print anything "too early". But I'd argue that printing an object earlier shouldn't crash like this.

The other problem IMHO is that if the parent is set and you don't crash, calling state will either return the already smoothed state or if this state hasn't been calculated yet, the FitNode will go on and const_cast itself to then calculate this smoothed state thus modifying it's internal state....

Now hopefully I'll have some time soon to try and patch this, but after loosing way to much of my Friday to this, I first need some distance... 🤦