when reaching the end of the file while reading a file stored inside the APK
Known. I solve it by using "file()" and working in RAM directly.
Here's the worst and funniest workaround ever:
Global
string caca_fopen_string;
int caca_fopen_pos;
End
function _fopen(string archivo,int modo);
begin
caca_fopen_string=file(archivo);
caca_fopen_pos=0;
return 1;
end
function string _fgets(JANDEL);
begin
y=caca_fopen_pos;
x=find(caca_fopen_string,chr(13),y);
caca_fopen_pos=x+2;
if(x==-1)
return "";
else
return substr(caca_fopen_string,y,x-y);
end
end
function _feof(JANDEL);
begin
if(caca_fopen_pos==-1)
return true;
else
return false;
end
end
function _fclose(JANDEL);
begin
//JAJAJAJAJAJA
return true;
end
Thanks for the workaround, Pixel :)
I will, however, have a look at it. Thanks for reporting, Javis. I've created a bug report here:
https://bitbucket.org/josebagar/pixtudio/issues/6/freads-and-feof-would-freeze-pxtp-in
I have just tried the following code in the latest PixTudio commit and it seems to work:
import "mod_video"
import "mod_say"
import "mod_mouse"
import "mod_proc"
import "mod_file"
import "mod_say"
Process main()
Private
int fd;
string line;
Begin
fd = fopen("text.txt", O_READ);
while(! feof(fd))
line = fgets(fd);
say(line);
end;
say("Done");
while(! mouse.left)
FRAME;
end;
fclose(fd);
exit();
End
Can you please post the code that's failing so that I can try it?
Quote from: josebita on November 23, 2015, 10:10:13 AM
I have just tried the following code in the latest PixTudio commit and it seems to work:
import "mod_video"
import "mod_say"
import "mod_mouse"
import "mod_proc"
import "mod_file"
import "mod_say"
Process main()
Private
int fd;
string line;
Begin
fd = fopen("text.txt", O_READ);
while(! feof(fd))
line = fgets(fd);
say(line);
end;
say("Done");
while(! mouse.left)
FRAME;
end;
fclose(fd);
exit();
End
Can you please post the code that's failing so that I can try it?
Are you testing it with Android? With a file stored in the apk? If that's the case, it seems to be solved
Enviado desde mi Nexus 6 mediante Tapatalk
Quote from: PiXeL on November 23, 2015, 12:19:22 AM
Known. I solve it by using "file()" and working in RAM directly.
Here's the worst and funniest workaround ever:
Global
string caca_fopen_string;
int caca_fopen_pos;
End
function _fopen(string archivo,int modo);
begin
caca_fopen_string=file(archivo);
caca_fopen_pos=0;
return 1;
end
function string _fgets(JANDEL);
begin
y=caca_fopen_pos;
x=find(caca_fopen_string,chr(13),y);
caca_fopen_pos=x+2;
if(x==-1)
return "";
else
return substr(caca_fopen_string,y,x-y);
end
end
function _feof(JANDEL);
begin
if(caca_fopen_pos==-1)
return true;
else
return false;
end
end
function _fclose(JANDEL);
begin
//JAJAJAJAJAJA
return true;
end
Nice workaround :P
Quote from: JaViS on November 23, 2015, 11:01:27 AM
Quote from: josebita on November 23, 2015, 10:10:13 AM
I have just tried the following code in the latest PixTudio commit and it seems to work:
import "mod_video"
import "mod_say"
import "mod_mouse"
import "mod_proc"
import "mod_file"
import "mod_say"
Process main()
Private
int fd;
string line;
Begin
fd = fopen("text.txt", O_READ);
while(! feof(fd))
line = fgets(fd);
say(line);
end;
say("Done");
while(! mouse.left)
FRAME;
end;
fclose(fd);
exit();
End
Can you please post the code that's failing so that I can try it?
Are you testing it with Android? With a file stored in the apk? If that's the case, it seems to be solved
Enviado desde mi Nexus 6 mediante Tapatalk
Yes, sorry, I didn't mention.
The code I posted is the latest available code in the git repo, tested in Android while reading from within the APK.
[Edit] Here's the link to the APK. It'll expire on the 30th:
https://josebagar.com/owncloud/index.php/s/UNxepDJ7crwiGdO
You, however, need to read the output in the ADB logcat.
Quote from: josebita on November 23, 2015, 11:24:00 AM
Quote from: JaViS on November 23, 2015, 11:01:27 AM
Quote from: josebita on November 23, 2015, 10:10:13 AM
I have just tried the following code in the latest PixTudio commit and it seems to work:
import "mod_video"
import "mod_say"
import "mod_mouse"
import "mod_proc"
import "mod_file"
import "mod_say"
Process main()
Private
int fd;
string line;
Begin
fd = fopen("text.txt", O_READ);
while(! feof(fd))
line = fgets(fd);
say(line);
end;
say("Done");
while(! mouse.left)
FRAME;
end;
fclose(fd);
exit();
End
Can you please post the code that's failing so that I can try it?
Are you testing it with Android? With a file stored in the apk? If that's the case, it seems to be solved
Enviado desde mi Nexus 6 mediante Tapatalk
Yes, sorry, I didn't mention.
The code I posted is the latest available code in the git repo, tested in Android while reading from within the APK.
[Edit] Here's the link to the APK. It'll expire on the 30th:
https://josebagar.com/owncloud/index.php/s/UNxepDJ7crwiGdO
You, however, need to read the output in the ADB logcat.
The only difference in my code is that my file path contains some subfolders
Quote from: JaViS on November 23, 2015, 11:28:31 AM
The only difference in my code is that my file path contains some subfolders
Will test subfolders later.
I've just tested the example modified to read the text file from a subfolder and it appears to be working fine.
Ok, I'm currently using BennuGD port on Android, maybe that's the problem. If you have the opportunity plz test the same example so we can confirm the bug exists.
this was my workaround to detect the end of the file:
<code>
if ( ftell (_filehandle ) == flength (_filehandle))
return "";
end
</code>
Reviewing the file reading history, I can see that I did work on this in February:
https://bitbucket.org/josebagar/pixtudio/diff/core/common/files.c?diff1=0e98a0001266&diff2=671ec6ca0be4b9138791e1f670331724d8af5568&at=bigmap (https://bitbucket.org/josebagar/pixtudio/diff/core/common/files.c?diff1=0e98a0001266&diff2=671ec6ca0be4b9138791e1f670331724d8af5568&at=bigmap)
The commits are labeled "Fixed file reading not checking for end of file with SDL_RWOPS" and "Handle read errors, and not only eof" so I probably fixed this long ago, yeah...
[Edit] Javis, can you point me to the BennuGD release you're using?
I'm using the bennugd release distributed with Pixel's "Plantilla".
Pixplantilla is fairly old... Any chance of trying your code in pixtudio?
I could create another branch to adapt my code to Pixstudio, but I don't know how to generate the APK.
Is replacing the Android Bennu forlder in Pixel's Plantilla enough?
That should work, I gues...
Pixel posted an updated "PixPlantilla". Have you been able to test the problem there?
Quote from: josebita on December 10, 2015, 11:30:43 AM
Pixel posted an updated "PixPlantilla". Have you been able to test the problem there?
Nope, I haven't. My code got bigger by now, and I have much work to do to make it compatible with pixstudio.
I'm pretty close to be able to show something from the game, so I've decided to wait until that.
Enviado desde mi Nexus 6 mediante Tapatalk
Ok, I've closed the bug in bitbucket since the behaviour is corrected in my tests, but let me know if you test it.
I'm hoping to see your next project soon!
Quote from: JaViS on December 10, 2015, 12:40:13 PM
Quote from: josebita on December 10, 2015, 11:30:43 AM
Pixel posted an updated "PixPlantilla". Have you been able to test the problem there?
Nope, I haven't. My code got bigger by now, and I have much work to do to make it compatible with pixstudio.
I'm pretty close to be able to show something from the game, so I've decided to wait until that.
By the way, the error I had was this one:
fp = fopen("file.txt",O_READ);
if(fp[b]>[/b]0)
while(!feof(fp))
line=fgets(fp);
end
end
fclose(fp);
fopen may return a negative int in Android, so if you're checking if the int is below 0, it won't work.
You need to check if it's not zero.
Ps: I can't explain myself in english easily, see you in the spanish forum next time xD