Can anyone tell me what this error is? How can I fix this? I'm doing a lot of research to understand why my game is having poor performance on other computers like laptops, for example. I suspect that one of the reasons could be this error, but I don't understand what it is or how to complain about it.
Erro Canvas2d: Multiple readback operations using getImageData???
RPG Maker MV SupportIt only happens when you change a text color. So it is very unlikely it is the cause.
Unless you have text update every frame.
So maybe you an check plugins that display texts on screen or something like that.
Unless you have text update every frame.
So maybe you an check plugins that display texts on screen or something like that.
As for the console messages: they are just "warnings", notifications that something might be wrong, or (as in this case) could be done better.
[Edit: sorry, I somehow missed the line numbers, e.g.
In theory a plugin could be written to force the
Why is it happening? I assume you've updated your NWJS runtime. Newer versions of the HTML spec (supported in newer versions of browser, i.e. Chromium in this case) introduce new features. The
developer.mozilla.org
As you can see from the support table at the bottom of that page, it seems support for this attribute was only added to Chrome in 2022 (v99). MV's core scripts have not functionally changed since v1.6.1 in 2018, shipping with NWJS version v0.29.4 built on Chromium v65. (Version numbers found via playtest console
rpg_core.js reads the windowskin for blitting window elements; colours are sourced via rpg_windows.js, which does not appear in your screenshot. [Edit: but that's irrelevant because they call the getPixel method from rpg_core.js regardless! 😴] So I would guess it's related to some window(s) being redrawn.[Edit: sorry, I somehow missed the line numbers, e.g.
rpg_core.js:2423. Those indicate:2423=> boot test of canvas blend modes.1197=>getPixel(RGB), used by the core scripts for sourcing colours from the windowskin.1214=>getAlphaPixel(A), not used by the core scripts.
In theory a plugin could be written to force the
willReadFrequently attribute onto the canvas of specific bitmaps when they are initialised. I don't know whether that would produce any notable effect in-game.Why is it happening? I assume you've updated your NWJS runtime. Newer versions of the HTML spec (supported in newer versions of browser, i.e. Chromium in this case) introduce new features. The
willReadFrequently canvas attribute is one of these new features:HTMLCanvasElement: getContext() method - Web APIs | MDN
The HTMLCanvasElement.getContext() method returns a drawing context on the canvas, or null if the context identifier is not supported, or the canvas has already been set to a different context mode.
process.versions.etc.)Despite what the MDN mentioned, my test result is just the opposite of what the warning describes.
This is what I did to let the bitmap read from a copy of the original canvas, the contex is created using willReadFrequently option(when the first time getPixel is called).
I called the method 1000 times in nw 0.94, it took roughly 1.3 second on my current pc. I also run the test multiple times, every time it costed more than 1 second.
But the original method took only 5 ms to complete. So 200 times faster.
I also tried on edge browser, it is 130 ms versus 1 ms.
JavaScript:
Bitmap.prototype.getPixel = function(x, y) {
if(!this._tempCavnas){
this._tempCanvas = document.createElement('canvas');
this._tempCanvas.width = this.width;
this._tempCanvas.height = this.height;
this._tempContext = this._tempCanvas.getContext('2d',{willReadFrequently:true});
this._tempContext.drawImage(this._canvas,0,0);
}
var data = this._tempContext.getImageData(x, y, 1, 1).data;
var result = '#';
for (var i = 0; i < 3; i++) {
result += data[i].toString(16).padZero(2);
}
return result;
};
This is what I did to let the bitmap read from a copy of the original canvas, the contex is created using willReadFrequently option(when the first time getPixel is called).
I called the method 1000 times in nw 0.94, it took roughly 1.3 second on my current pc. I also run the test multiple times, every time it costed more than 1 second.
But the original method took only 5 ms to complete. So 200 times faster.
I also tried on edge browser, it is 130 ms versus 1 ms.
Typo spotted! ("vn" <-> "nv".)
I removed all the plugins and nothing changed ;(
I feel very new now, because I don't quite understand what I can do to adjust it or how you did it. Did you save it in a script? Did you save it in a .JS file? Is it a command that I use in the game? I didn't quite understand. Sorry. I don't understand much. Much more about HTML programming, I was a little lost. But thanks in advance.
Good catch.
Yeah, so I fixed the typo. Now it is 400 ms, still very slow.
JavaScript:
Bitmap.prototype.getPixel = function(x, y) {
if(!this._tempCanvas){
this._tempCanvas = document.createElement('canvas');
this._tempCanvas.width = this.width;
this._tempCanvas.height = this.height;
this._tempContext = this._tempCanvas.getContext('2d',{willReadFrequently:true});
this._tempContext.drawImage(this._canvas,0,0);
}
var data = this._tempContext.getImageData(x, y, 1, 1).data;
var result = '#';
for (var i = 0; i < 3; i++) {
result += data[i].toString(16).padZero(2);
}
return result;
};
@Edilsonsoares You can save it as a plugin. But like I mentioned, this 'fix' is even slower than original. So it removes most warnings, but pointless. lol
Thank you very much, this is not what is causing the possible slowdown in my game, or on other computers, as you yourselves said, but thank you very much anyway. I will continue this search to find this problem.
Original thread: https://forums.rpgmakerweb.com/threads/erro-canvas2d-multiple-readback-operations-using-getimagedata.176146/