Solved Question About Loadsprite Function

Question that is answered or resolved.

Bruce

Active member
Hello guys,

I am trying to code the Assist Select Screen on top of Char Select Screen.
Right now I only have 3 pictures that I need to show during the Assist Selection Menu.

Something in the OpenBor log has bothered me, so I need to make sure I am understanding abut the
loadsprite function properly.

I only loaded 3 pictures, but the log says I loaded 81 times.
Is this meant 81 or 3 of these from the 3 pictures would stay in the memory?

I remember reading somewhere on this forum that it does not matter how many times the pictures being loaded,
The engine would keep track of the path and would get rid of the duplicated ones.

I know I can free them with the free() function, but it is tricky, especially on the char selection screen.
The pictures are small in size, so it is not bigger deal, unless the engine actually keep all of the these 81+ in the memory!

Can someone please give me some advice on this?
Thank you very much

Code:
Warning: 81 script variants are not freed, dumping...
openbor_loadsprite
openbor_loadsprite
openbor_loadsprite
openbor_loadsprite
openbor_loadsprite
openbor_loadsprite
openbor_loadsprite
...............
...............
 
Solution
Is this meant 81 or 3 of these from the 3 pictures would stay in the memory?
Unlike "loadsample", the "loadsprite" function does not check for duplicated entries.
My first recomendation is to always conditioning it to a variable check. I mean, check if the variable is NULL() before loading a sprite.

Code:
if(getglobalvar("sprite_name") == NULL())
{
    setglobalvar("sprite_name", loadsprite("data/sprites/sprite_name.png"));
}

Second, make sure you freed them before clearing the variables.

Code:
if(getglobalvar("sprite_name") != NULL())
{
    free(getglobalvar("sprite_name"));
    setglobalvar("sprite_name", NULL());
}
Is this meant 81 or 3 of these from the 3 pictures would stay in the memory?
Unlike "loadsample", the "loadsprite" function does not check for duplicated entries.
My first recomendation is to always conditioning it to a variable check. I mean, check if the variable is NULL() before loading a sprite.

Code:
if(getglobalvar("sprite_name") == NULL())
{
    setglobalvar("sprite_name", loadsprite("data/sprites/sprite_name.png"));
}

Second, make sure you freed them before clearing the variables.

Code:
if(getglobalvar("sprite_name") != NULL())
{
    free(getglobalvar("sprite_name"));
    setglobalvar("sprite_name", NULL());
}
 
Solution
Unlike "loadsample", the "loadsprite" function does not check for duplicated entries.
My first recomendation is to always conditioning it to a variable check. I mean, check if the variable is NULL() before loading a sprite.

Code:
if(getglobalvar("sprite_name") == NULL())
{
    setglobalvar("sprite_name", loadsprite("data/sprites/sprite_name.png"));
}

Second, make sure you freed them before clearing the variables.

Code:
if(getglobalvar("sprite_name") != NULL())
{
    free(getglobalvar("sprite_name"));
    setglobalvar("sprite_name", NULL());
}
Thank you so much for your informative information which will help me avoid memory leak!
I've already figured I would have to free it before loading a new sprite with this:

Code:
void ExistedSprite = getglobalvar("AssistSprite" + P_Index);
if(ExistedSprite != NULL())
{
  free(ExistedSprite);
}

void SpritePath = loadsprite("data/chars/Assists/Palettes/" + AssistName + ".png");
setglobalvar("AssistSprite" + P_Index, SpritePath);

Almost done with Assist Select Screen. I am having a little problem how to setup for 2nd, 3rd, and 4th player.
I will figure it out eventually.
Havent said that, I will also have to fix the character color selection menu too!

Thank you so much buddy
 
Back
Top Bottom