Problem With My Function


JoanCZ

Still Fresh
Joined
Feb 15, 2011
Messages
16
Hello :)


so, here's my problem:


Code:
void ChargementData()
{

FILE *fichier;
char chaine[200];
char *fin;
int i,j;
char temp[50];
float x,y,z;

int decalage=0;

fichier = fopen("donnees.txt","r");

do
{

fin=fgets(chaine,100,fichier);
if (!strncmp(chaine,"Vertex",6))
{
if (strncmp(chaine,"Vertex list",11))
{

i=0;

while(chaine[i]!='X') i++;
i+=2;
while(chaine[i]==' ') i++;
sscanf(chaine+i,"%f",&x);

while(chaine[i]!='Y') i++;
i+=2;
while(chaine[i]==' ') i++;
sscanf(chaine+i,"%f",&y);

while(chaine[i]!='Z') i++;
i+=2;
while(chaine[i]==' ') i++;
sscanf(chaine+i,"%f",&z);

Sommet[Nb_points].x=x;
Sommet[Nb_points].y=y;
Sommet[Nb_points].z=z;

Nb_points++;
}
}
else
{
if (!strncmp(chaine,"Face",4))
{
if (strncmp(chaine,"Face list",9))
{

i=j=0;
while(chaine[i]!='A') i++;
i+=2;
j=i;
while(chaine[j]!=' ') j++;
strncpy(temp,chaine+i,j-i);
temp[j-i]=0;
Facette[Nb_faces].a=atoi(temp)+decalage;

while(chaine[i]!='B') i++;
i+=2;
j=i;
while(chaine[j]!=' ') j++;
strncpy(temp,chaine+i,j-i);
temp[j-i]=0;
Facette[Nb_faces].b=atoi(temp)+decalage;

while(chaine[i]!='C') i++;
i+=2;
j=i;
while(chaine[j]!=' ') j++;
strncpy(temp,chaine+i,j-i);
temp[j-i]=0;
Facette[Nb_faces].c=atoi(temp)+decalage;


while(chaine[i]!='A') i++;

strncpy(temp,chaine+i+3,1);
temp[j-i]=0;
Facette[Nb_faces].ab=atoi(temp);

strncpy(temp,chaine+i+8,1);
temp[j-i]=0;
Facette[Nb_faces].bc=atoi(temp);

strncpy(temp,chaine+i+13,1);
temp[j-i]=0;
Facette[Nb_faces].ac=atoi(temp);

Nb_faces++;
}
}
else if (!strncmp(chaine,"Named object",12)) decalage=Nb_points;
}
} while(fin!=NULL);


fclose(fichier);
}

I can build it perfectly on PC or Caanoo version (i use CodeBlocks).
On my PC it run properly, but on Caanoo, it crash ( black screen and return to Caanoo menu...)
(the problem is this fonction, if i remove it, it work.... but i need this fonction :D )


Thank you :)


(excuse my bad language, i'm french ;) )
 
First I recommend you put the function in a code block so it is more readable. It is difficult enough it is in french :-o

To get more info on the problem on the caanoo try running the program through a terminal, usbnet, or log the output to a file by redirecting stdout and errout to a file. You do this in your start script (the gpe file). I think warehouse panic does this he you need an example.


Good luck
 
Hello :)

I've look for warehouse panic, and this game is reading .txt files for level mapping :)
But I don't know where i can find sourcecode...
 
You do not check if the file was successfully opened by checking if fichier is a NULL pointer after the fopen call.
 
i've check this with a "if (fichier==NULL)", and try to put/remove my "donnees.txt" file.
On PC the two condition run perfectly, but on Caanoo, it crash (with or without "donnees.txt")
i don't understand where is the problem...



thank you ;)
 
Hi JoanCZ,

i was on my phone previously, so it was difficult to type and i tried to keep it short. What i meant to say was that you can see what error you get back when the program fails. My Warehouse Panic .gpe file looks like this:

Code:
#!/bin/sh
#export LD_LIBRARY_PATH=.;$LD_LIBRARY_PATH
./warehouse_panic.caanoo > ./log.txt 2>&1
sync
cd /usr/gp2x
exec /usr/gp2x/gp2xmenu

The executable is actually warehouse_panic.caanoo. So when i execute it, i redirect the output to log.txt. Then i can have a look in log.txt to see what linux said the problem was. For example, it could be that you are missing an .so file on the caanoo, which is available on your computer (i've had that problem myself).

Good luck

/Uni
 
Hello :)

I think i've found my error...
fopen cannot find "donnees.txt" so the fonction fclose() crashe the caanoo (i've tried to remove fclose(fichier) and there is no crashes without it)

so why fopen() doesn't find my file ? it is in the same directorie of my .gpe ? ... i don't understand...


u9i> Hello,
could you telle me more about your method ? (where i can write this lines you've wrote ? ( Iam not a linux user ;)))
and thank you for your help :):):)
 
Put that code into a text file, call it something that ends with .gpe (because caanoo runs .gpe files), and of course replace "warehouse_panic.caanoo" with the name of your own executable. Then to start your program you run this script instead of your executable directly. And you don't need to start the gp2xmenu from within your program anymore because it is taken care of in my script.

Did you understand?

Now, every time you run this script it will write the result of your executable to the file log.txt and you can look at this file from windows.

/Uni
 
hello,

i've tried your method, so i have on my sdcard:

-Game/programme.gpe
-Game/programme.caanoo
-Game/programme.png
-Game/programme_title.png
-Game/donnees.txt


"programme.gpe" contains
#!/bin/sh
#export LD_LIBRARY_PATH=.;$LD_LIBRARY_PATH
./programme.caanoo > ./log.txt 2>&1
sync
cd /usr/gp2x
exec /usr/gp2x/gp2xmenu

and "programme.caanoo" is a rename of my original .gpe file in .caanoo :)

so, when i try to launch "programme.gpe, my caanoo display the "loading screen" and that's all (i think it's crashing at this screen... :( )


Is there something i do wrong ???

thank you ;)
 
if you have edited your file on windows, then you possibly have windows line endings. you need to convert the .gpe to have unix style line endings.
 
ok, i've converted the "programme.gpe" with dos2unix, and now it works.

so, here is my error:

Impossible d'ouvrir le fichier en lecture: No such file or directory
SERIAL NUM: [9] [6] [7] [8] [2] [2] [F] [F] [2] [4] [E] [D] [1] [3] [1] [C] [C] [D] [7] [3] [8] [8] [7] [2] [E] [F] [6] [E] [D] [5]
FOPEN Error in NED_FILE_READ [/var/tmp/NED_LIC.SYS]
FOPEN Error in NED_FILE_READ [/var/tmp/NED_SID.SYS]
NED_Initialize END


for information, "Impossible d'ouvrir le fichier en lecture" means that is impossible to open my file (in french ;) )
My file is in the same directory than my .gpe... so where is the problem ????



(and thank you for helped me ;) )
 
hm take care of the filename's cases ... it must be all lower case ...
 
excuse me, i didn't understand what you've wrote :D
what is a "case" ? (sorry for my stupid question... i'm french:D)
 
JoanCZ said:
excuse me, i didn't understand what you've wrote :D
what is a "case" ? (sorry for my stupid question... i'm french:D)

your file must be named "donnees.txt" on your sd card, not "donnees.TXT" or somethink like that. unix is case-sensitive (sorry, there's no other word i know for that :) )
 
Last edited by a moderator:
hello u9i ;)



thank for all :D the problem was it.
so now it work perfectly :) (and I have learn a lot of thing with that topic :D )

just a screen ;)
b9dd94374dfe405c5176f5496d663e39.png


The result is a little lara croft in 3d.
 
Back
Top