archive by month
Skip to content

bizarre bug

I was making changes to squad membership updating and tactical targeting, which happens once every 8 frames. And I hit a bug which had these symptoms: Steamhammer appeared to run normally, but extremely slowly. Each frame took a second or more. Not each eighth frame, each single frame. Also Steamhammer was unable to recognize its slowness; its timer said that the mean frame took 0.1 milliseconds, normal for the very early game which was as far as I let it run. What could cause such bizarre behavior?

It took a long time to debug. I finally traced it to a misplaced } character which included too much in an if, with the result that an important value was never initialized. It was not easy to see in the code. How this caused a slowdown and how the slowdown stayed outside the timed code (or otherwise broke the timer's behavior) I do not know, and don't expect to find out....

It is worth it to use a prickly language like C++? One wrong touch and you get glochids in your skin for who knows how long. Some days I think about recoding Steamhammer in a pleasant language like Haskell, where new code more often than not works the first time. But that also comes with big disadvantages.

Trackbacks

No Trackbacks

Comments

Nininene on :

Gcc and clang both provide Address Sanitizer, which is a huge help to catch this kind of problems. Msvc does not appear to, unfortunately. Time to start developing on Linux using openBW?

McRave on :

0.1ms is still incredibly fast. Many bots suffer being much much longer, at the benefit of some cool features. I added pathfinding to my sim and I'm using almost 3ms a frame for my simulation!

Jay Scott on :

0.1 ms is in the earliest game when all it has to do is occasionally order a new drone or set a drone to work. There is no mineral locking (yet), so once the drone is set to work, Steamhammer issues it no other commands. It spends its 100 microseconds checking production status, looking to see whether anything is in danger of attack, and so on.

Marian on :

C++ requires more thought on design that languages like java or C#.
On the other hand you get more power and freedom.
Also I am a big fan of const-correctness.

Stanislaw Halik on :

Is Haskell able to provide "soft realtime" guarantees? One thing I'd hate is coding around the GC, in Haskell's case with thunks that's additionally challenging. See that even the .NET runtime with corporate backing doesn't do "soft realtime", only JVM does. In fact I saw a game cons 2 GB of garbage each frame handling 60 FPS with busy scenes. JVM didn't break a sweat with a parallel mark-and-sweep collector.

I wonder how much time you'd save using Haskell (or ML), a modern language, compared to the C++ standard you're using now. One thing I'm sure you'd chain lots of stuff together using random infix operators. To each his own I guess.

C++17 is a decent language and Microsoft compilers now support it. It's not the "old C++" that made me a C89 holdout. Interestingly, C++11 and above supports higher-kinded types (in fact, variadic "infinite" kinds). I do much work using template partial specialization that's sort-of-equivalent to class/instance in Haskell.

Jay Scott on :

The garbage collector is one of the disadvantages. It can be dealt with—there are plenty of soft real-time systems written in Haskell—but it adds complexity to development. There are even hard real-time systems: Use high-level Haskell code to generate low-level code for a runtime system that provides strong timing guarantees.

Stanislaw Halik on :

If this applies, C++17 allows for class-inline non-constexpr initializers. They can't be constructor parameters but it respects initialization order nonetheless, so in this case:

int foo;
Bar bar { ... foo, ... };
-- where `int foo' is initialized in the constructor.

Using C++11 and above I've had no need in my own code to use bare pointers and explicit "delete". I've only had few cases needing Valgrind, and no cases needing asan or ubsan.

Finally, Visual Studio now supports the _full_ C++17 standard, no exceptions. You can write portable code for this standard across all supported platforms with no need for mingw-w64. MSVC++ has a better linker for PE/COFF targets sadly.

Add Comment

E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Form options

Submitted comments will be subject to moderation before being displayed.