Problems with ImageManager.loadbitmap

First of all this is a rough draft of what i need to have my plugin working:

Testing = {}_isDatabaseLoadedtest = DataManager.isDatabaseLoaded;DataManager.isDatabaseLoaded = function() { if (!_isDatabaseLoadedtest.call(this)) return false; // loading a parallax because it's big Testing.bitmap = ImageManager.loadParallax('BlueSky')        console.log('here is the sooner i can load the bitmap') Testing.bitmap.addLoadListener( function() { console.log('this is when the getPixel is called') Testing.firstPixel = Testing.bitmap.getPixel(0, 0); }.bind(this) ) return true;};Window_Base.prototype.createContents = function() { this.contents = new Bitmap(this.contentsWidth(), this.contentsHeight()); this.resetFontSettings(); console.log('i need the pixel here') console.log(Testing.firstPixel);};Basically i need to make some checks on the bitmap (wich includes getting some of it's pixels and other things)

But the issue is that the image is loaded after the 'createContents' is called.

XOEzF5S.png


Sometimes it works (it loads the bitmap fast) but it's not the norm.
It's normal, You must to put a check of loading the image in your loop, into Window_Base.update, with .isReady() bitmap function
Because you are not waiting, until the bitmap has been loaded. The correct way to do it is this:

var Testing = {}var alias_create = Scene_Boot.prototype.create;Scene_Boot.prototype.create = function() { alias_create.call(this); Testing.bitmap = ImageManager.loadParallax('BlueSky');};var alias_start = Scene_Boot.prototype.start;Scene_Boot.prototype.start = function() { Testing.firstPixel = Testing.bitmap.getPixel(0, 0); alias_start.call(this);};No need to alias "isReady", because it will automatically wait, until the ImageManager has loaded all images.You might replace Scene_Boot with every other scene.

If you need to fetch the image dynamically, while a scene is running, put everything you want to do with it inside the load listener.
Because you are not waiting, until the bitmap has been loaded. The correct way to do it is this:

var Testing = {} var alias_create = Scene_Boot.prototype.create;Scene_Boot.prototype.create = function() {    alias_create.call(this);    Testing.bitmap = ImageManager.loadParallax('BlueSky');}; var alias_start = Scene_Boot.prototype.start;Scene_Boot.prototype.start = function() {    Testing.firstPixel = Testing.bitmap.getPixel(0, 0);    alias_start.call(this);};

No need to alias "isReady", because it will automatically wait, until the ImageManager has loaded all images.

 

You might replace Scene_Boot with every other scene.

 

If you need to fetch the image dynamically, while a scene is running, put everything you want to do with it inside the load listener.
It works partially for me. I have two plugins with this issue and one needs the database to be loaded, and at Scene_Boot.create it is not yet. (this is why I placed it on the DataManager.isDatabaseLoaded, because it's the earliest point i'm sure the database is loaded). 

Anyway thanks, If I don't find a solution to that, i will drop the other plugin and use this solution.

It's normal, You must to put a check of loading the image in your loop, into Window_Base.update, with .isReady() bitmap function
I tried it at some spots, but it always frozen the screen. I need to get used with the update routines of MV, there are things that i still don't get how work (the damn ImageManager.isReady is one of them)
For what exactly do you need the database to be loaded?

1) Before loading the picture (because its name is given as a notetag, for example).

2) After loading the picture (because you need to set a value in a $data object, for example).

For 1) you could, for example, set a timeout, that continously checks, whether the needed file has already been loaded:

Code:
var flag = false;var alias_create = Scene_Boot.prototype.create;Scene_Boot.prototype.create = function() {    alias_create.call(this);    loadPicture();};var alias_isReady = Scene_Boot.prototype.isReady;Scene_Boot.prototype.isReady = function() {   return flag && alias_isReady.call(this);};var loadPicture = function() {    if(...) {                       // check, whether the data file has already been loaded.                                    // load your picture.        flag = true;    } else {        setTimeout(loadPicture, 5); // Check again later.    }};
For 2) you could do similar, but after loading the picture. So, you load the fixed picture and inside the load listener continously poll, until the data object you're waiting for has been loaded. Scene_Boot.prototype.isReady needs to return false, until your function has been completed.
It's the case 1, a notetag that defines wich image will be loaded.

I will try this solution.

Original thread: https://forums.rpgmakerweb.com/threads/problems-with-imagemanager-loadbitmap.53632/