[Bug] Game freezes after window is left unfocused for a while

User: bblizzard
Bug: Game freezes after window is left unfocused for a while.

How to Replicate the Bug:
  • Start up a game.
  • Switch focus to something else and leave the game running in background for usually 20-30 minutes. (I am not 100% sure that a longer time frame is required or not. I provided more info below.)
  • The bug doesn't reproduce every time. I experienced it only a handful of times in hundreds of runs and switching the focused window.
Other: The last time this happened, I used to console to get some data. I noticed that Graphics._skipCount was negative. Looking at the implementation of Graphics.render(), I assume that the error lies in the first if condition that checks for:

Code:
if (this._skipCount === 0)
rather than:

Code:
if (this._skipCount <= 0)
As JavaScript uses double-precision floating point values internally, this leads me to believe that this bug might be caused by a floating point precision error after a while which is why the bug usually only happened after leaving the game running in background for a while. In any case, I am pretty confident that changing this if condition will fix the issue. I did a drop-in change of the method in the console and the game unfroze.
It's been bothering me for a long time. I hope this will fix it.

Thx a lot.
I've been using this fix since I discovered it and haven't had that issue anymore since then. Here, if you want it in plugin form:

Code:
//=============================================================================
// SkipCountFix
//=============================================================================

(function() {
   
//=============================================================================
// Graphics
//=============================================================================

var SkipCountFix_Graphics_render = Graphics.render;
Graphics.render = function(stage)
{
    if (this._skipCount <= 0)
    {
        this._skipCount = 0;
    }
    SkipCountFix_Graphics_render.call(this, stage);
};

//=============================================================================

})();
Once the MV team confirms this issue/fix and integrates it into the default code, you can simply remove the plugin.
So glad that I discovered this thread and your fix for the bug! It helped with a graphics-freezing problem that one my playtesters had. Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/bug-game-freezes-after-window-is-left-unfocused-for-a-while.115895/