I discovered that I was getting the same error on my iOS device (crash when delete a particular image). Discovered with the help of my
TADebugConsole class.
So I went back to trying to figure it out. I tried all combinations of changing the order of when the images (it was a set of four that appeared to be doing it), creating new images from scratch of the same size, using another image that was big enough for the animation (even though it did not have the frames) and that had deleted cleanly, and others.
It came down to whatever images were loaded in
that class initialisation (there really should NOT be a 'z' in that word!) would cause a crash when the cleanup came.
So I tried to figure out what was different.
It came down to the class dynamically creating an array of integers and storing the image id in that array (something only done in this class, and now I cannot figure out why I even had the array for that storage). As soon as I deleted all the lines associated with it, the bug went away. Still makes no sense, but the problem disappeared.
The array was declared as a class static member like this inside the class definition in the header file:
static TA_UINT* gold_img_ids;
In the code file it was used like this:
// static attributes
TA_UINT* game_obj_gold::gold_img_ids = NULL;
// the initialisation method
bool game_obj_gold::init_object(const char* goldsnd,const char* base_image,TA_USHORT gold_count,TA_UINT gold_img_base,
float col_dist,int framwid,int framhih,int framcnt,int dsp_lst,float dsp_fps,float col_fps)
{
// local variables
char file_name[90];
TA_USHORT i;
TA_UINT i_mid;
// load the sound
if (game_obj_base::add_loaded_sound(goldsnd,kaching_sound)) return true;
// store number of types of gold and the image base (assume first image will add one)
max_gold_cnt = gold_count;
gold_base_id = gold_img_base;
// store collect distance
collect_distance = col_dist;
// store animation data
anim_wid = framwid;
anim_hih = framhih;
anim_cnt = framcnt;
disp_fps = dsp_fps;
coll_fps = col_fps;
// figure out the display/collect frames
disp_fst = 1;
disp_lst = dsp_lst;
coll_fst = disp_lst + 1;
coll_lst = anim_cnt;
// create array to hold image ids
gold_img_ids = new TA_UINT[max_gold_cnt];
// work on loading the images
for (i=1;i<=max_gold_cnt;i++)
{
// build the file name
sprintf(file_name,"%s%u.png",base_image,i);
// try to load the image
if (TADisplay::add_loaded_image(file_name,i_mid,0.5,0.5,false,true,anim_wid,anim_hih,anim_cnt))
{
// delete array
delete[] gold_img_ids;
// return error
return true;
}
// save the id
gold_img_ids[i] = i_mid;
// add to id collect
TADisplay::add_id_to_auto(gold_img_ids[i],gold_img_base+i);
}
// all is good
return false;
}
The 'add_loaded_image' function sets the value of i_mid to the loaded image and returns true on failure.
static bool add_loaded_image(const char* filnam, TA_UINT& i_mid,float xoff, float yoff,bool no_trans=false,bool is_anim=false,int framwid=0,int framhih=0,int framcnt=0);
The code even crashed when I substituted 'i_mid' for 'gold_img_ids\[i\]' in the call to 'TADisplay::add_id_to_auto'. Which was wierd.
As far as I can tell, there is nothing wrong with the array I created or how I used it. And it really doesn't look like it should have influenced anything.
But removing all the code associated with it made the problem go away.
Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master