Autor Tema: BUG: freads and feof would freeze the program  (Leído 3414 veces)

JaViS

  • Global Moderator
  • *****
  • Mensajes: 1252
  • Karma: 26
    • Anarkade
BUG: freads and feof would freeze the program
« en: Noviembre 22, 2015, 11:41:20 pm »
when reaching the end of the file while reading a file stored inside the APK
Working on Anarkade. A couch multiplayer 2D shooter.

panreyes

  • Administrator
  • *****
  • Mensajes: 2154
  • Karma: 74
    • panreyes.com
Re:BUG: freads and feof would freeze the program
« Respuesta #1 en: Noviembre 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:
Código: [Seleccionar]
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

josebita

  • Administrator
  • *****
  • Mensajes: 4039
  • Karma: 257
    • BennuGD Mobile Worklog
Re:BUG: freads and feof would freeze the program
« Respuesta #2 en: Noviembre 23, 2015, 09:38:39 am »
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

josebita

  • Administrator
  • *****
  • Mensajes: 4039
  • Karma: 257
    • BennuGD Mobile Worklog
Re:BUG: freads and feof would freeze the program
« Respuesta #3 en: Noviembre 23, 2015, 10:10:13 am »
I have just tried the following code in the latest PixTudio commit and it seems to work:
Código: [Seleccionar]
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?

JaViS

  • Global Moderator
  • *****
  • Mensajes: 1252
  • Karma: 26
    • Anarkade
Re:BUG: freads and feof would freeze the program
« Respuesta #4 en: Noviembre 23, 2015, 11:01:27 am »
I have just tried the following code in the latest PixTudio commit and it seems to work:
Código: [Seleccionar]
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

Working on Anarkade. A couch multiplayer 2D shooter.

JaViS

  • Global Moderator
  • *****
  • Mensajes: 1252
  • Karma: 26
    • Anarkade
Re:BUG: freads and feof would freeze the program
« Respuesta #5 en: Noviembre 23, 2015, 11:01:59 am »
Known. I solve it by using "file()" and working in RAM directly.

Here's the worst and funniest workaround ever:
Código: [Seleccionar]
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
Working on Anarkade. A couch multiplayer 2D shooter.

josebita

  • Administrator
  • *****
  • Mensajes: 4039
  • Karma: 257
    • BennuGD Mobile Worklog
Re:BUG: freads and feof would freeze the program
« Respuesta #6 en: Noviembre 23, 2015, 11:24:00 am »
I have just tried the following code in the latest PixTudio commit and it seems to work:
Código: [Seleccionar]
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.
« última modificación: Noviembre 23, 2015, 11:26:24 am por josebita »

JaViS

  • Global Moderator
  • *****
  • Mensajes: 1252
  • Karma: 26
    • Anarkade
Re:BUG: freads and feof would freeze the program
« Respuesta #7 en: Noviembre 23, 2015, 11:28:31 am »
I have just tried the following code in the latest PixTudio commit and it seems to work:
Código: [Seleccionar]
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
Working on Anarkade. A couch multiplayer 2D shooter.

josebita

  • Administrator
  • *****
  • Mensajes: 4039
  • Karma: 257
    • BennuGD Mobile Worklog
Re:BUG: freads and feof would freeze the program
« Respuesta #8 en: Noviembre 23, 2015, 11:33:22 am »
The only difference in my code is that my file path contains some subfolders
Will test subfolders later.

josebita

  • Administrator
  • *****
  • Mensajes: 4039
  • Karma: 257
    • BennuGD Mobile Worklog
Re:BUG: freads and feof would freeze the program
« Respuesta #9 en: Noviembre 23, 2015, 12:07:54 pm »
I've just tested the example modified to read the text file from a subfolder and it appears to be working fine.

JaViS

  • Global Moderator
  • *****
  • Mensajes: 1252
  • Karma: 26
    • Anarkade
Re:BUG: freads and feof would freeze the program
« Respuesta #10 en: Noviembre 23, 2015, 03:21:29 pm »
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>
Working on Anarkade. A couch multiplayer 2D shooter.

josebita

  • Administrator
  • *****
  • Mensajes: 4039
  • Karma: 257
    • BennuGD Mobile Worklog
Re:BUG: freads and feof would freeze the program
« Respuesta #11 en: Noviembre 23, 2015, 03:35:00 pm »
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
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?

JaViS

  • Global Moderator
  • *****
  • Mensajes: 1252
  • Karma: 26
    • Anarkade
Re:BUG: freads and feof would freeze the program
« Respuesta #12 en: Noviembre 23, 2015, 04:32:09 pm »
I'm using the bennugd release distributed with Pixel's "Plantilla".
Working on Anarkade. A couch multiplayer 2D shooter.

josebita

  • Administrator
  • *****
  • Mensajes: 4039
  • Karma: 257
    • BennuGD Mobile Worklog
Re:BUG: freads and feof would freeze the program
« Respuesta #13 en: Noviembre 23, 2015, 10:42:58 pm »
Pixplantilla is fairly old... Any chance of trying your code in pixtudio?

JaViS

  • Global Moderator
  • *****
  • Mensajes: 1252
  • Karma: 26
    • Anarkade
Re:BUG: freads and feof would freeze the program
« Respuesta #14 en: Noviembre 24, 2015, 05:06:02 pm »
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?
Working on Anarkade. A couch multiplayer 2D shooter.