Within 10 minutes I had written a test environment to try to trigger the bug. It didn't. But the test environment in combination with moving the sliders around triggered the bug reliably. There were 2 sliders out of 27 that would cause the symptoms I was dreading. But in making the problem reproducible, I had made it much easier to find the problem. Within another 10 minutes I had fixed it. Yay!!

I believe I have fixed the bug, but it's possible there's another bug hiding in there.

Why was I able to find this now but not earlier?

I was frustrated earlier. After taking a break, I'm calm. Being frustrated makes it harder for me to figure things out.

I was looking in the wrong place. I was convinced it was a problem with my multithreading (in part because multithreading is such a common source of bugs), but it wasn't.

By taking a break, my brain generated new hypotheses in the background. At some point, maybe a week ago, a thought came to me: there's some weird behavior with rivers. When I came back to this project, I discovered that the weird behavior was linked to the bug. The problem is that occasionally, no rivers are large enough to be drawn, and my code tries to draw 0 rivers. This seems to mess up the graphics state. I fixed it by only drawing if the number of rivers was greater than 0.

I'm posting this in part to remind myself to take more breaks and to get frustrated less.

In this project I was optimizing for speed. I picked simpler algorithms that would run fast instead of cooler algorithms that would produce nicer output. I think it worked pretty well, but there were soooooo many times I had to skip something that would improve the maps.