dennisat, on 16 April 2014 - 04:40 AM, said:
Does this fit the bill? It renders everything I've tried correctly but I've no access to the original problem:
//var xd = (x.XNAMatrix.Translation - XNAViewerPos).Length() - x.RenderPrimitive.SortIndex; //var yd = (y.XNAMatrix.Translation - XNAViewerPos).Length() - y.RenderPrimitive.SortIndex; var xd = (x.XNAMatrix.Translation - XNAViewerPos).Length(); var yd = (y.XNAMatrix.Translation - XNAViewerPos).Length(); if (yd > xd) return 1; else if (xd > yd) return -1; else if (y.RenderPrimitive.SortIndex > x.RenderPrimitive.SortIndex) return -1; else if (x.RenderPrimitive.SortIndex > y.RenderPrimitive.SortIndex) return 1; else return 0; //return Math.Sign(yd - xd);
The main reason I was attracted to the above is that it's fairly proof against bad format float values. They will just drop through the greater and less than checks so there should be no crashes at this point. Even hugely different valid float values can only be greater than, less than, or neither (exactly the same hopefully). Now what will happen to the Render task subsequently if any of these values are bad I've got no idea! Moves the crash on a bit, I suppose.
My recent attempts at debugging have all either started with, or ended up with finding bad float values so I'm now a bit suspicious of them. Does C# have a debugging mode that will validate numeric fields as the program runs? Very resource consuming, of course, but if you've got a problem that's hard to spot this can be a very useful tool.
Dennis