Do you ever get this?

Started by
2 comments, last by irreversible 7 years, 11 months ago

Every now and then I come across the need to refactor or properly integrate some older code. I usually encapsulate my experimental stuff fairly well, so this is mostly reduced to just checking the code, updating some data structures and adjusting the logic from a sandbox to a production grade environment.

Every now and then things get weird, though.

Occasionally (and by occasionally I mean "on numerous occasions") I discover a very obvious bug in the old code that completely breaks the new code in a way that makes perfect sense. However, for some reason it used to work before without ever failing. Not once. This is usually code that has not been thoroughly tested (or rather hasn't been tested in the real world) and tends to look like a mess. Although - there are occasions when these kinds of curiosities also show up in fairly, or sometimes in the most, tested code, as shown below.

Right now I'm in the process of integrating some fairly involved navmesh generation stuff I wrote about two years ago and when I now ran it with exactly the same data set I used when I first wrote and used to debug it, it floored. After stepping through it I found three pretty obvious mistakes, including the following line:

{ uint32 cx = v->x; for(;;) { grid[(v->y / iBinSize) * gw + (cx / iBinSize)]->vertices.push_back(v); if(cx <= v->next->x) { break; } cx -= iBinSize; } }

Which will crash if cx becomes negative (or in this case overflows), because it is used to index a grid element. And for a given dataset it should crash every single time. Yet somehow, through some bit of sheer dark magic, it didn't in the past. Under seemingly identical circumstances.

Similar oddities I've come across are not creating a GL texture, yet through some backwards circumstance the same image is loaded in a completely unrelated part of the engine and for some reason everything works "correctly" for a VERY long time; or stuff like not initializing variables, very obvious overflows, etc.

The biggest one I can think of was a tracer related issue in my previous code, which extended way back to 2005 when my code wasn't thread-aware. The tracer essentially used a static local to store parts of the stack, which at one point, as my code became increasingly more multithreaded, started to cause extremely rare random crashes, which didn't really show up in the debugger. So it took me about seven years before I uncovered this monstrosity.

All this makes me wonder - what other demons am I burying in my code right now that I will completely forget and will come back to haunt me in several years...

So yeah - do you ever get this?

Advertisement

You mean, you write a compiler with a while and for statement, and break and continue statement, wrap it all up, release it, it gets used by several hundreds of people a year.

Then, 2-3 years later you write a test program to figure out some other problem, compile it with your compiler, and it acts weird. After some debugging, you find "continue" actually does "break" instead!

So indeed, it happens :p

So yeah - do you ever get this?

Not so similar but ... here is it anyway
I've had to write algorithms for triangles of different shapes, from normal to weird lately
Every time I thought I had written my algorithm to cover all the weird shaped triangles another weirder one appears and breaks the code.
And then after a while super weird shaped triangles began to appear that broke the code - triangles that are effectively a single line because you could draw a single straight line through all 3 points
I guess I probably hadn't read my books well enough, because i think veterans have standards ways of dealing with these weird shapes :lol:

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

When

So yeah - do you ever get this?


Not so similar but ... here is it anyway

I've had to write algorithms for triangles of different shapes, from normal to weird lately

Every time I thought I had written my algorithm to cover all the weird shaped triangles another weirder one appears and breaks the code.
And then after a while super weird shaped triangles began to appear that broke the code - triangles that are effectively a single line because you could draw a single straight line through all 3 points

I guess I probably hadn't read my books well enough, because i think veterans have standards ways of dealing with these weird shapes :lol:

I discovered the plentiful nuances of computational geometry firsthand when I wrote my triangulator. It took me months to iron out all the kinks and handle all special cases, and I'm sure there are still a few around that I simply haven't come across :).

A triangulator now seems like the perfect school assignment for students who think they know better. There's always that one special T junction, degenerate vertex or empty triangle they can't think of :)

This topic is closed to new replies.

Advertisement