Sorry for the long post, I have no idea what the cause of this weird bug might be, so I included many details just in case. I'm making a game inspired by HmH, in C++, on Windows, currently 22,000 LoC.
The problem seems weird to me: everything works fine, until a couple minutes go by, at which point the game graphics freeze. But the game doesn't crash, in fact programatically everything keeps functioning, and you can still hear the sounds respond to the input. I put a frame counter in the screen to see if the bug is consistent, and indeed every time the counter reaches 9987 the graphics stop.
Also, I noticed in the Task Manager that right after this, memory usage starts consistently going up by 3.3MB/s without stopping. More accurately, 53kB per frame, because when I change the framerate this seems to be kind of proportional to it. When I change the framerate, the bug still happens after 9987 frames.
I also tried disabling certain code blocks one by one with the debugger, for 1000 frames (by "frames" I mean game updates, which are coupled with frames) and then enabling them back, to see if the bug would still happen after 9987 frames. I disabled the part that sorts the render commands, the part that renders them, and the part that calls SwapBuffer(), separately and together, and every time the bug still happened after 9987 frames, which means the source of the problem lies elsewhere. I commented out the Input, the Sound and the dynamic saving/loading stuff, and still, after 9987 frames the graphics stop and the memory starts to go up by the same amount.
Maybe there's something in the game layer that's causing this? I disabled the game update call for two frames, and the counter, which lies in the game update, was 9985 when the graphics stopped, two less than usual, so it is not the cause. (Also, strangely, the memory usage started going up by 13kB/frame rather than 53kB). So it must be something inside the platform layer. What? I don't know. As I said, I commented out most stuff, there's not much there. It makes no sense to me. My only imaginable answer is that the WinAPI or OpenGL are doing something on the background implicitly...
I hope someone has some idea of what it could be, or can propose a general direction to investigate towards, otherwise I'll have to make a speedrun game haha. Here are some more details of the code: it has keyboard and mouse input via Windows API, gamepad input via XInput, audio via DirectSound, graphics through OpenGL, and I load some asset files with Windows API. The game layer is a dll that gets loaded, and also there's full-state saving/loading like there was in HmH. To draw graphics the game puts commands into a list that then gets passed back to the platform layer, and OpenGL goes through the list and draws. But whatever I disable, the graphics seem to stop after the main platform-layer loop has iterated 9987 times.