This bug is in reference to [r5089] and [r5130]. Prior to r5089, Y-sort could crash on certain combinations of compilers/optimizations and operating system. But discussion with zeromus suggests I only covered up the bug in r5089, but not actually fixed it. r5130 was introduced to check the sorting predicate function, which is the piece of code currently in question.
To trigger the assert, first you need to revert std::stable_sort to std::sort in gfx3d_doFlush(), as this assert will not get triggered with std::stable_sort. Next, I've provide two test cases to trigger the assert:
Note that these are the exact same moments that would cause a crash prior to r5089, but now cause an assert in r5130.
Commit: [r5089]
Commit: [r5130]
Anonymous
At the time of assert, there are comparisons being made between NaNs and real numbers. This would explain a lot of what's happening!
The predicate functions do one comparison each on the POLY.miny and POLY.maxy values. Both of these values are set in gfx3d_doFlush() at gfx3d.cpp:2192.
So if we use this hack...:
if (vertw == 0.0f) vertw = 0.000001f;
Now the assert is satisfied and everything works. When reverting back to using std::sort with gfx3d_ysort_compare_kalven() as the predicate, no crashes occur as long as the NaN is avoided.
So two new questions arise from this:
Diff:
Actually implement the hack workaround in [r5132].
I'll keep this bug open until we can answer both the questions I posted above with some level of certainty, or if there is a test case that actually reveals something.
Related
Commit: [r5132]
After years of testing without any reported issues, I think it should be safe to close out this one. See commit git#35e834f for more details.