Android Trying to draw non-existing sprite on android [solved]

S

sefi331

Guest
Hi all,
So my problem is that I am using asset_get_index to draw a sprite that saved in a global variable that loaded form an .ini file:

the load action in the .ini file:
global.sprite_player_p1 = ini_read_string("p1_player_pic","p1_pic","s_chal_t_avatar_p1");

the sprite - 's_chal_t_avatar_p1' exists off course, and I refer to it as a string because I notice that if I set sprite to variables it get mushed up and weird when I add new sprites and then the variables get a new index and object is drawing a wrong sprite.

the draw action (draw gui that contain a script):
draw_sprite_ext(asset_get_index(global.sprite_player_p1),0, x_draw, y_draw,
xScale* 0.3 * facing, yScale * 0.3 , 0, color, alpha);


Works perfectly when checking in windows, however, when I export a build and try it on android I get the error:

ERROR in
action number 1
of Draw Event
for object (the object that run the script in its draw gui event)

Trying to draw non-existing sprite.
at gml_Script_(the script that contain the above code)

stack frame is
gml_Script_(the script that contain the above code) (line -1)
gml_Object_(the object that run the script in its draw gui event)_Draw_64


What is the reason for that? I that a problem with asset_get_index on android?
When I checked a previous version apk I see that the draw_sprite_ext contain the global variable without asset_get_index and it works without error.

Thanks!
 

Kahrabaa

Member
Hello. asset_get_index works fine on android for me.

Have you made sure what the final sprite index value is?
Try to
show_message( asset_get_index(global.sprite_player_p1) ); or show_debug_message( asset_get_index(global.sprite_player_p1) );
Just before the draw call if the error is 100% repeatable.
 
S

sefi331

Guest
Ok so i checked it out with - show_message_async(asset_get_index(global.sprite_player_p1))
and on PC it shows 152 and on android it shows -1.
So it can't find the sprite?
Why it get unindexed on the android built?
 

Kahrabaa

Member
What I would do is try to trace back every step of handling the sprite to eliminate suspicions.
show_message_async( spritename ); //Check the sprite's name to make sure there is nothing wrong with the index at startup
show_message_async( global.sprite_player_p1 ); //Precisely after reading the string from the ini file, to make sure the string is loaded correctly
 
S

sefi331

Guest
show_message_async(asset_get_index(global.sprite_player_p1))

show_message_async(s_chal_t_avatar_p1);

show_message_async(global.sprite_player_p1);


On PC => 152 , 152 , s_chal_t_avatar_p1

On android => -1 , 152 , 159


So it got the resource tree index right, but its not loaded to the variable?
 
S

sefi331

Guest
Ok I think I got it. The problem is with the .ini files that are not loaded correctly.
On android it seems to use different files.

Thanks for the help Kahrabaa !
 
Top