Closed ada-foss closed 12 years ago
Okay, so, when this error does occur (and it does not happen 100% of the time), the drawing thread typically gets stuck in a call to awaitClearGLData, suggesting that GL_data_impede has been incorrectly set or something has failed to clear it.
GL_data_impede, a boolean inherited from LagDisplay, is assigned values in 4 places:
So, the assertion that must hold for a correct call to ::mainimage is something like: awaitClearGLData AND (InitGLDraw OR DrawGLToCard) The issue being that the drawing thread must grab ahold of the rights to use GL data, and then fail to release said rights because it was interrupted, and then go to grab them again at the start of the call to ::mainimage on line 423.
Located and eliminated the race condition that was occuring. interrupt_drawing, when set after GL exclusive data access was obtained but before the GL draw signal was emitted, the GL draw signal would be skipped and the GL data access rights were never released. Now, they are released when the drawing thread detects an interrupt at that point.
It seems uncomfortably easy for bugs like this to slip through the net. Really, a better framework should be in place to manage rights to the GL data vectors. The code has been left as-is since it should be a small enough component to not need maintenance too frequently.
It seems that the original threading architecture within lag was intended to be capable of indicating to the drawing thread that it should terminate if a call to drawviewable occured before it was naturally able to do so. I doubt, from the implementation, that this ever worked originally.
The idea is good in concept and ought to be implemented using the new mutex and condition system, in the TwoDeeOverview::drawviewable method. An attempt was previously made, as follows, but causes rendering to fail completely for an unknown reason.
This may be that, first of all, the drawing thread does what it can for every drawviewable call, explaining the occasional artifacts that do render. And secondly, the final call to drawviewable in any short period of time leaves the drawing thread in a state where it thinks it is not supposed to render.