Icon shows up as blank when first loaded

Poppie360

chocobo wrangler
Veteran
Joined
Feb 28, 2018
Messages
175
Reaction score
52
First Language
English
Primarily Uses
RMMV
Okay, so the following code:

Cuased this to happen:



how do i make this not happen? (Also the code Does do what it's intended to do...it just also messes everything else up too)

(Edit: yes i did see the second draw icon line, however, it still does the same thing when removed so...that's not the issue)

Hmmmmmmmmm, let me try something actually!

okay so that didn't fix it, sorry about all the edits, but, here is the updated code, all "system" graphics get set to the icon set image after running the function instead of just the single icon.
(explination to above; i had the origonal problem but litterally figured out the issue five minuets after but a new one happened, so i didnt want to make a thread right after i had already made this one.)



So when running this code, the icon ends up blank at first, and when you exit out of the menu and go back in it returns to normal, how do you make it so it doesnt show up as blank the first time around?
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,792
Reaction score
12,219
First Language
English
Primarily Uses
RMMV
It's because of the asynchronous loading in MV.

If you search through rpg_scenes.js for iconset you will see that everything in the img/system folder is preloaded to avoid this.
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
2,601
Reaction score
3,785
First Language
English
Primarily Uses
RMMV
So it's all fixed?

Also, the general rule is that if something doesn't load up the first time but appears the second time, it's a caching issue (the game imports the asset into memory the first time, but isn't finished before drawing it on the screen. The second time, the asset is already in memory so it draws it without any problem). But if it's all distorted like in your images, I'm not sure it's a memory caching issue.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,792
Reaction score
12,219
First Language
English
Primarily Uses
RMMV
So it's all fixed?
no, the "fixed" problem was when the OP first wrote that code, and had issues with it corrupting the whole screen. They sorted that out, but now the issue is that the icon only shows up the SECOND time you enter the menu - first time, it's blank. That spoiler is a bit misleading - I thought the same thing when I first read it.
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
2,601
Reaction score
3,785
First Language
English
Primarily Uses
RMMV
no, the "fixed" problem was when the OP first wrote that code, and had issues with it corrupting the whole screen. They sorted that out, but now the issue is that the icon only shows up the SECOND time you enter the menu - first time, it's blank. That spoiler is a bit misleading - I thought the same thing when I first read it.
Ohh I see. Yeah, it's a bit confusing, perhaps @Poppie360 should edit the post so not to confuse future visitors? As for the issue itself, like you said Shaz the iconset asset should already be preloaded.

Couple of possibilities come to mind:
  1. You modified Scene_Boot 's preloading method, or a plugin modifies it.
  2. You changed the iconset's file name without changing it in the preloading.
  3. You're using an earlier version of MV (not sure about this one, but I think at one point there was no reserveGraphics method for loading images).
That's all I can think of for now. Any of these ring a bell, OP?
 

Poppie360

chocobo wrangler
Veteran
Joined
Feb 28, 2018
Messages
175
Reaction score
52
First Language
English
Primarily Uses
RMMV
Ohh I see. Yeah, it's a bit confusing, perhaps @Poppie360 should edit the post so not to confuse future visitors? As for the issue itself, like you said Shaz the iconset asset should already be preloaded.

Couple of possibilities come to mind:
  1. You modified Scene_Boot 's preloading method, or a plugin modifies it.
  2. You changed the iconset's file name without changing it in the preloading.
  3. You're using an earlier version of MV (not sure about this one, but I think at one point there was no reserveGraphics method for loading images).
That's all I can think of for now. Any of these ring a bell, OP?
no, the "fixed" problem was when the OP first wrote that code, and had issues with it corrupting the whole screen. They sorted that out, but now the issue is that the icon only shows up the SECOND time you enter the menu - first time, it's blank. That spoiler is a bit misleading - I thought the same thing when I first read it.
Sorry yeah i had the origonal problem but litterally figured out the issue five minuets after but a new one happened, so i didnt want to make a thread right after i had already made this one.

Would refreshing the window work? I have no idea how to do that though

Looking over your post more, i intend on making it so it doesnt preload the graphic, i am making a modding system and the icon needs to be drawn from a specfied graphic
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,792
Reaction score
12,219
First Language
English
Primarily Uses
RMMV
Yeah, so this is similar to the message window, showing faces, and probably to showing faces in the regular menu.

First it does a call to ImageManager.reserveFace to kick off the loading process. Then it spins its wheels while the face is being loaded. After it's been loaded, it draws the face and calls ImageManager.releaseReservervation. That way, the message shows with the face, the first time.

Check out the Window_Message class in rpg_windows.js to see how it does it.
 

Poppie360

chocobo wrangler
Veteran
Joined
Feb 28, 2018
Messages
175
Reaction score
52
First Language
English
Primarily Uses
RMMV
Yeah, so this is similar to the message window, showing faces, and probably to showing faces in the regular menu.

First it does a call to ImageManager.reserveFace to kick off the loading process. Then it spins its wheels while the face is being loaded. After it's been loaded, it draws the face and calls ImageManager.releaseReservervation. That way, the message shows with the face, the first time.

Check out the Window_Message class in rpg_windows.js to see how it does it.
I am not compitent with how this engine works code wise, but also could you explain why this doesnt work like intended?


JavaScript:
    //New graphic loader
    ImageManager.loadImageThing = function(Path, filename, hue) {
        //insert IF regarding flag
        return this.loadBitmap(Path, filename, hue, true);
    };

    //Overwrite old functions
    ImageManager.loadSystem = function(filename, hue) {
        if ($gameVariables.value(2) != 0) {
            return this.loadImageThing($gameVariables.value(3), $gameVariables.value(4), hue, false);
        } else {
            return this.loadBitmap('img/system/', filename, hue, false);
        }
    };

    Window_Base.prototype.drawItemName = function(item, x, y, width) {
        width = width || 312;
        if (item) {
            var iconBoxWidth = Window_Base._iconWidth + 4;
            this.resetTextColor();
            //Set icon information (how to do stuff "$gameVariables.setValue(ID, VALUE);" "$dataItems[i].meta.UsesCustomGraphic")
            if (item.meta.UsesCustomGraphic != "false"){
                $gameVariables.setValue(2, 1);
                $gameVariables.setValue(3, ("Mods/Mod Data/" + item.meta.ModID + item.meta.GraphicPath));
                $gameVariables.setValue(4, item.meta.GraphicName);
                this.drawIcon(Number(item.meta.GraphicCalcVariable), x + 2, y + 2);
                $gameVariables.setValue(2, 0);
            } else {
                this.drawIcon(item.iconIndex, x + 2, y + 2);
                $gameVariables.setValue(2, 0);
            }

            //Old method of icon drawing "this.drawIcon(item.iconIndex, x + 2, y + 2);"
            this.drawText(item.name, x + iconBoxWidth, y, width - iconBoxWidth);
        }
    };
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,792
Reaction score
12,219
First Language
English
Primarily Uses
RMMV
As I said, the img/system/ files are preloaded when the game is launched. So by the time an item is drawn, the images are already cached.

By adding loadImageThing where the image is not preloaded, you are drawing something that hasn't been loaded into cache yet, so all you're going to get is an empty bitmap.

ImageManager.loadBitmap triggers the loading of the image and returns an empty bitmap as a placeholder. You go on to display stuff, but ImageManager is still loading. It waits until the loading is finished, and then replaces the empty bitmap in cache with the loaded image. But because you didn't wait, and didn't check if it had been loaded, your drawing has already happened.

If you want to be able to display images without preloading, then you have to cater for that small period after requesting the image, before it's actually available in memory to use. I gave you an example from the message system that shows exactly how that's done there. You need to look at it, understand how it works, and then do the same thing in your code.

If you are writing this and posting in Javascript Support, I am assuming you just want a push in the right direction so you can do it yourself. If you want someone to write it for you, they probably would go about it in a completely different way.
 

Poppie360

chocobo wrangler
Veteran
Joined
Feb 28, 2018
Messages
175
Reaction score
52
First Language
English
Primarily Uses
RMMV
As I said, the img/system/ files are preloaded when the game is launched. So by the time an item is drawn, the images are already cached.

By adding loadImageThing where the image is not preloaded, you are drawing something that hasn't been loaded into cache yet, so all you're going to get is an empty bitmap.

ImageManager.loadBitmap triggers the loading of the image and returns an empty bitmap as a placeholder. You go on to display stuff, but ImageManager is still loading. It waits until the loading is finished, and then replaces the empty bitmap in cache with the loaded image. But because you didn't wait, and didn't check if it had been loaded, your drawing has already happened.

If you want to be able to display images without preloading, then you have to cater for that small period after requesting the image, before it's actually available in memory to use. I gave you an example from the message system that shows exactly how that's done there. You need to look at it, understand how it works, and then do the same thing in your code.

If you are writing this and posting in Javascript Support, I am assuming you just want a push in the right direction so you can do it yourself. If you want someone to write it for you, they probably would go about it in a completely different way.
Well i am curirous as to two things;
1. will this refresh thing in the code i have seen but havent been able to figure how to use fix that?
2. could i just stick an "await" when loading the fucntion?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,792
Reaction score
12,219
First Language
English
Primarily Uses
RMMV
Neither method will work, and both will cause other issues.

You also don't know how long it's going to take to load (if you put it online, it depends on the connection speed of the player; if you just distribute it to run standalone, it depends on the processing speed of the player's computer, and what other things they have running at the time).
 

Poppie360

chocobo wrangler
Veteran
Joined
Feb 28, 2018
Messages
175
Reaction score
52
First Language
English
Primarily Uses
RMMV
Neither method will work, and both will cause other issues.

You also don't know how long it's going to take to load (if you put it online, it depends on the connection speed of the player; if you just distribute it to run standalone, it depends on the processing speed of the player's computer, and what other things they have running at the time).
Given by things the game does; Look through folder locations, create files, and a decent amount of other things I highly doubt it will ever work online, i intend for it to just be something that works on computers. and i'll show you this;


Create database runs before the game starts, every time you run the game, i've tested it, and with 10ish mods it only takes a minuet at worse. and i am running it on a really bad laptop specs wise.

I am sure that grabbing a single image wouldn't take that long, in fact the image is retrieved;




But as you can see only after you reload the menu. the icon that "stimulant" uses doesn't exist inside of the img folder.
I dont see why just reloading the menu after loading in the image, or waiting until the image is fully loaded wouldnt work

Edit: Okay so i solved the problem, just loading the graphic before entering the menu (IE; when giving the item to the player) also works, it solves the issue with the item not showing up...but i feel like that would cuase a memory issue, are images automatically unloaded? or do you have to manually unload the loaded bitmaps?
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,792
Reaction score
12,219
First Language
English
Primarily Uses
RMMV
Try this ... play the game, give the item to the player, check the menu - icon should be there. Now save your game and close it completely. Now play again and continue your saved game. Go to the menu. Is the icon there?

I keep telling you to look at those scripts and do it that way, because it works.
 

Poppie360

chocobo wrangler
Veteran
Joined
Feb 28, 2018
Messages
175
Reaction score
52
First Language
English
Primarily Uses
RMMV
Try this ... play the game, give the item to the player, check the menu - icon should be there. Now save your game and close it completely. Now play again and continue your saved game. Go to the menu. Is the icon there?

I keep telling you to look at those scripts and do it that way, because it works.
Oh no i realized that was an issue, basically i found a way around it by just going through the player inventory during a check if it wasn't recorded that on the current session before the player really do anything that the graphics are loaded it would just load the graphics.

But, uhhhh, Do you know how to fix this issue i found with it granting x0 of an item that you cant use when you try to use "gainitem"?

the only other post didnt have anything i could use really, funnily enough you are a commenter on it!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,792
Reaction score
12,219
First Language
English
Primarily Uses
RMMV
that is a different issue and should be asked in a different thread. If you are happy that you've solved the issue in this thread, please report your first post and ask the mods to close it.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Gave my avatar an update, stay safe, people!
I'm currently available for hire for scripting (and perhaps other things).
Also, don't worry, the Advanced Minimap plugin is a work in progress.
Hallelujah! Work is getting stricter on humans in the store.
Day 3 of mapping... at least the whole game its just one location :3 (Still taking forever...)


Almost 5 am.. and I decide to put up a Youtube video instead of sleeping. It's strangely addicting! :kaoswt:

Forum statistics

Threads
95,621
Messages
930,492
Members
125,929
Latest member
RitBro
Top