Fenix Crashes On Saving Two Dimensional Structs


sam fisher

Well-Known Member
Joined
Apr 11, 2004
Messages
9,452
Location
Bristol, UK
Website
blog.peter-r.co.uk
Fenix seems to crash when saving two dimensional structs, which is going to force me to rewrite my games score handling in a very bad way. If there is no already existing file, fenix will crash but save the struct as requested. However if there is already an existing file fenix will crash and not save the new struct over the top.

This is very annoying and seems to occur identically on both the GP2x and PC versions of fenix. Has anyone else noticed this before?
 
Are you saving strings, cause I think I've heard something about that... otherwise I've never tried fenix :p
 
If you are trying to do
CODE

struct strrr[1][2]


you can easily change that to
CODE

struct strr[1]
struct r[2]


which would probably work just fine.
 
Hi Sam. I've had no such problem. Just did a quick test and saving of 2 dimensional structs works fine. My guess is that something else is to blame in your code or as someone else said you have attempted to save a struct containing strings (though I thought that was just a bug in the gp2x version of Fenix).

The code I used is pasted below for you to test on your own machine. It simply creates a struct, fills it with some data for the hell of it and saves the struct to a file. It then loops and displays the value of timer[0] just to be sure it hasn't frozen or anything.

[codebox]
program struct_test;

global

struct test[10][10];
a;
b;
c[10];
end

begin

for(y=0;y<10;y++)
for(x=0;x<10;x++)
test[x][y].a=x;
test[x][y].b=x;
test[x][y].c[x]=x;
end
end


save("struct",test);

write_int(0,10,10,0,offset timer[0]);



loop

frame;

end

end
[/codebox]
 
It's not my code. I've tested it and profiled it for hours. Saving a struct full of data causes a crash.

As you know I already don't use strings in my game anyway, I use integer arrays to avoid that string saving bug.

BTW, is the string saving bug just when declaring a "string" or also present with saving character arrays, as I handle strings in a char array format.

Edit: To elaborate it saves an empty struct just fine, but a full struct fails.
 
I'll post all the related code here.

This is the struct:

CODE
struct scores[2][11]
int score;
int name[3];
end


As you can see there are no strings involved.

This bit fills the struct upon it's inital creation:

CODE
if(file_exists("scores.dat"))
load("scores.dat", scores);
else
for(k=0; k<2; k++)
for(i=0; i<10; i++)
for(j=0; j<3; j++)
scores[k].name[j] = rand(__A,__Z);
end
scores[k].score = rand(223,250);
end
end
sort_scores();
end


and this is the sort scores process that also happens to be where the crash takes place:

CODE
process sort_scores()

private
int i, j, k, l, temp;
begin
for(l = 0; l<2; l++)
for(k = 10; k>0; k--)
for(i=0; i < k; i++)
if(scores[k].score < scores[k][i+1].score)
temp = scores[k].score;
scores[k].score = scores[k][i+1].score;
scores[k][i+1].score = temp;
for(j=0; j < 3; j++)
temp = scores[k].name[j];
scores[k].name[j] = scores[k][i+1].name[j];
scores[k][i+1].name[j] = temp;
end
end
end
end
scores[l][10].score = 0;
end
save("scores.dat", scores);
end


This all worked fine before making the struct multi dimensional.
 
Ok, It's my fault. I made a stupid mistake of using the "k" variable as I did in another process when in this process the temp variable i should be using is "l". Hence the program was going way out of bounds and I gather causing this crash that no longer seems to occur.

It was only upon going to convert to moogles structure when I noticed that the sorting process made very little sense in its current form. What I can't understand is what it was the actual saving of the structure that caused a crash :S.
 
Quiest said:
ruckage said:
something else is to blame in your code

sam fisher said:
It's not my code.

sam fisher said:
Ok, It's my fault. I made a stupid mistake...
Quoting just for the amusement of myself :D srysam

Lol, I was happy i found what was wrong but angry I was so stupid lol. The crash didn't occur until the save took place though heh.
 
Last edited by a moderator:
Back
Top