RMMV JavaScript Unofficial Bugfix Snippets

Discussion in 'JS Plugin Releases (RMMV)' started by Shaz, Oct 23, 2015.

  1. Liquidize

    Liquidize Caffeine Overload Developer

    Messages:
    466
    Likes Received:
    455
    Location:
    Somewhere.
    First Language:
    English
    Primarily Uses:
    RMMV
    Basically because the game engine/the game doesn't run at a fixed tick rate, or frame rate the game logic (movement,event processing,input processing, etc) will run at whatever FPS you are running it  at. So if you have a 144hz monitor, the game will run at 2-4 times the speed of a normal game, and everything will be faster, not just movement. That may seem like its not so bad till you get to where EVERYTHING runs faster, so all your events that you have made too run at a specific "Time" and such also don't execute at the speed you'd like them too because of someones faster computer, which can inherently ruin your game for them. I don't think this is the original thread, but the introduction to this plugin explains it more: http://forums.rpgmakerweb.com/index.php?/topic/50709-fluidtimestep-fix-the-game-speed/?hl=144hz
     
    #21
  2. orlando

    orlando Veteran Veteran

    Messages:
    177
    Likes Received:
    84
    Sure, it affects the entire game including the speed of all effects like rain.

    You can test it on any machine where for some reason, the game runs very slowly (around 10FPSish):
    If I run nwjs-win on Linux in wine I get 10FPS when I enable color tinting (possibly because WebGL doesn't work in wine and it uses the Canvas backend), where this problem is pretty apparent: the character walks notably slower and the rain falls slower from the sky. With my fix applied, the game is still 10FPS and very laggy, but the character speed isn't slower.

    I tested this myself, and there are various other places where this problem has been noticed:

    It would be nice if this was eventually fixed in the core. Feel free to use my code or a variation of it, consider my changes public domain.
     
    Last edited by a moderator: Nov 22, 2015
    #22
  3. Ramiro

    Ramiro Now with an army of Mecha-Ralphs! Veteran

    Messages:
    860
    Likes Received:
    366
    Location:
    Argentina
    First Language:
    Spanish
    Omg, this is a horrible bug, when you clean the cache, it never releases the webGL objects attached to the bitmaps, so memory leaks filled with webGL textures on VRAM...

    ImageManager.clear = function() {  this._cache = {}};It should be something like:

    Code:
    ImageManager.clear = function() {  for (var p in this._cache) {     if (this._cache.hasOwnProperty(p) && this._cache[p] instanceof Bitmap) {      if (this._cache[p].baseTexture) this._cache[p].baseTexture.destroy();     }  }  this._cache = {}};
     
    #23
    SilverDash likes this.
  4. Shaz

    Shaz Veteran Veteran

    Messages:
    37,793
    Likes Received:
    11,502
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    thanks. Logged.
     
    #24
  5. orlando

    orlando Veteran Veteran

    Messages:
    177
    Likes Received:
    84
    Is ImageManager.clear() even called ever? Because I can't find any reference. If it isn't, that would be another bug. (A good idea where to call it would be map change)
     
    Last edited by a moderator: Nov 27, 2015
    #25
  6. Shaz

    Shaz Veteran Veteran

    Messages:
    37,793
    Likes Received:
    11,502
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    no, I couldn't find it. But then Ace had a Cache.clear method that was also never called. The method is there to use if we ever want it for any reason.
     
    #26
  7. orlando

    orlando Veteran Veteran

    Messages:
    177
    Likes Received:
    84
    I disagree. I think it's simply a massive bug. RPG Maker loads images and more images and never unloads them. How is that supposed to work ever for any sort of non-trivially sized games?? It's just asking for trouble. Also the unload function (ImageManager.clear) is clearly there, they just forgot to call it.

    Read the latest response here which clearly indicates adding the snippet I provided to fix this improved his memory troubles: http://forums.rpgmakerweb.com/index.php?/topic/51350-ios-memory-leak/ (and the snippet doesn't do anything more than simply calling this function on map change!)
     
    Last edited by a moderator: Nov 27, 2015
    #27
  8. Shaz

    Shaz Veteran Veteran

    Messages:
    37,793
    Likes Received:
    11,502
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    The point of the cache is to reduce loading times. By keeping everything in memory, the only delay is the very first time each resource is accessed. It would defeat the purpose of having a cache if you cleared it.


    You either have memory issues (which is only an issue now that we're playing on mobile devices), or you have loading issues. It's a case of "choose one".
     
    Last edited by a moderator: Nov 27, 2015
    #28
  9. orlando

    orlando Veteran Veteran

    Messages:
    177
    Likes Received:
    84
    A proper cache clears out stuff that hasn't been used for a while (for the exact reason that "choose one" is insane and you usually want a middle ground, for obvious reasons). Just keeping every image that was ever accessed loaded forever is not how a useful cache system operates.


    Edit:

    Also this alone should be enough to require a fix for this, right? You're acting like mobile not working properly would be not that bad - but after all, mobile export is one of the special cool new advertised main features of RPG Maker MV. And the game working without crashes is way more important than slightly higher loading times, so IMHO if in doubt ImageManager.clear() should rather be called too often than too rarely.
     
    Last edited by a moderator: Nov 28, 2015
    #29
  10. Shaz

    Shaz Veteran Veteran

    Messages:
    37,793
    Likes Received:
    11,502
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    I am not sure how you draw that conclusion from what I said. What I said was that the memory issues due to keeping everything in cache are only a problem now because we HAVE the ability to export to devices that have very low memory.


    That says nothing at all about whether it's important or not. It says it wasn't important before because we couldn't do it before, which potentially explains why "keep everything in cache" was an acceptable solution in previous makers.


    I have already stated, either in this thread or in another, that the ideal would be to keep track of how many times each resource is used, to update that when the resource is no longer used, and to remove it from cache when the use count hits zero. And that it would require a fairly significant rewrite of the engine because there is currently no updating of resource counts when a scene is closed or a resource is "let go", as well as the added complexities due to resources being copied or cloned rather than just used straight out of cache.


    I wouldn't do it via ImageManager.clear() though, as I don't believe fixing one problem by causing another is an acceptable trade-off.


    So some time ago I already said what you said - that the way it's handled is not good for mobile devices. Please stop putting words in my mouth. What you said is just not true.
     
    #30
  11. orlando

    orlando Veteran Veteran

    Messages:
    177
    Likes Received:
    84
    Alright, I misread. Sorry. I just sometimes feel people here are quick to reject obvious improvements to fix situations where RPG Maker MV breaks entirely while pointing at increase in loading times, "works on desktop" etc.
    Well but in a way it is: when one problem is simply slightly higher loading times, and the other one is that your game stops working entirely, the choice isn't that hard to make.
    RPG Maker has also a function to detect whether it runs on mobile, so it would be pretty easy to just enable this for the mobile devices. (although I believe it would be a useful improvement for all platforms. With a sufficiently large game also the desktop platforms will have issues eventually)


    Of course the proper approach you outlined would be performing superior in all situations. I'd be the last person to reject that. I'm just hoping we get some sort of improvement soon.
     
    Last edited by a moderator: Nov 30, 2015
    #31
  12. Shaz

    Shaz Veteran Veteran

    Messages:
    37,793
    Likes Received:
    11,502
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    If you read through the threads here, you will find there are many more complaints about delays due to loading-on-demand than there are about crashes due to memory overflow.


    You've given me an idea, but this probably isn't the thread to talk about it. Let me see what I can do ...
     
    #32
  13. eivl

    eivl Villager Member

    Messages:
    20
    Likes Received:
    1
    First Language:
    English
    I have written about this somewhere else in October, but TL;DR is that you need to to one of the following, reduce the cache (or clear it) or decouple the prototype chain of unused objects in memory so that it will be picked up by the garbage collector. 

    I would be happy to assist since this is something i normally do in my day job ;)
     
    #33
    ArkDG likes this.
  14. Megablackdragon31

    Megablackdragon31 Veteran Veteran

    Messages:
    215
    Likes Received:
    35
    Location:
    Argentina
    First Language:
    Spanish
    I dont know if this is important,but a Japanese scripter has done a patch for fix the memory leak issue. But i dont have permission for post it.
     
    #34
    ArkDG likes this.
  15. ArkDG

    ArkDG Veteran Veteran

    Messages:
    143
    Likes Received:
    45
    First Language:
    portuguese
    Can you post the scripter page link or a place from where to see and download it?
     
    #35
  16. Megablackdragon31

    Megablackdragon31 Veteran Veteran

    Messages:
    215
    Likes Received:
    35
    Location:
    Argentina
    First Language:
    Spanish
    Last edited by a moderator: Dec 13, 2015
    #36
    lostdragon and ArkDG like this.
  17. Victor Sant

    Victor Sant Veteran Veteran

    Messages:
    1,694
    Likes Received:
    1,437
    Location:
    Brazil
    First Language:
    Portuguese
    #37
    Nekoyoubi and lostdragon like this.
  18. orlando

    orlando Veteran Veteran

    Messages:
    177
    Likes Received:
    84
    pixi.js in the version shipped with RPG Maker MV has a bug which results in additive pictures rendering in WebGL with a much too low alpha value, which potentially breaks parallax/lighting effects put in by people.


    This snippet, which should probably be integrated into the RPG Maker core with an upcoming official patch, fixes it:


    (function() {
    PIXI.WebGLRenderer.prototype._preAdditiveFix_mapBlendModes = PIXI.WebGLRenderer.prototype.mapBlendModes;
    PIXI.WebGLRenderer.prototype.mapBlendModes = function() {
    var fixAdditive = false;
    if (!PIXI.blendModesWebGL) fixAdditive = true;
    var returnValue = this._preAdditiveFix_mapBlendModes();
    if (fixAdditive) {
    var gl = this.gl;
    PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.ONE, gl.ONE];
    }
    return returnValue;
    };

    })();


    (it changes the blend mode for additive for WebGL so it renders correctly)


    See this thread for a visual example of how this glitch looks like in practice: http://forums.rpgmakerweb.com/index.php?/topic/53817-show-picture-in-additive-mode-renders-notably-different-incorrectly-in-webgl-mode/


    See github issue link for details: https://github.com/pixijs/pixi.js/issues/2248
     
    Last edited by a moderator: Jan 27, 2016
    #38
    lostdragon, ArkDG and Victor Sant like this.
  19. lucia116

    lucia116 Villager Member

    Messages:
    15
    Likes Received:
    1
    First Language:
    japan
    Do I need to modify any file?
    Please tell us.
     
    #39
  20. HeroicJay

    HeroicJay Veteran Veteran

    Messages:
    315
    Likes Received:
    173
    First Language:
    English
    Primarily Uses:
    RMMV
    Actors acting randomly will ALWAYS target enemy/actor #1. Always always always. When enemy #1 is dead, they will always target enemy #2, and so on down the line. They will not actually hit random targets. Here's the fix:


    Game_Action.prototype.decideRandomTarget = function() {
    var target;
    if (this.isForDeadFriend()) {
    target = this.friendsUnit().randomDeadTarget();
    } else if (this.isForFriend()) {
    target = this.friendsUnit().randomTarget();
    } else {
    target = this.opponentsUnit().randomTarget();
    }
    if (target) {
    this._targetIndex = target.index();
    } else {
    this.clear();
    }
    };

    Code:
    Game_Action.prototype.evaluate = function() {
        var value = 0;
        this.itemTargetCandidates().forEach(function(target) {
            var targetValue = this.evaluateWithTarget(target);
            if (this.isForAll()) {
                value += targetValue;
            } else if (targetValue > value) {
                value = targetValue;
                this._targetIndex = target.index();
            }
        }, this);
        value *= this.numRepeats();
        if (value > 0) {
            value += Math.random();
        }
        return value;
    };

    The difference with the default functions? No () after "target.index". That's not a property; it's a function!
     
    Last edited by a moderator: Feb 19, 2016
    #40
    Yurii, Nekoyoubi and ArkDG like this.

Share This Page