BUG: freads and feof would freeze the program

Started by JaViS, November 22, 2015, 11:41:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JaViS

when reaching the end of the file while reading a file stored inside the APK
Working on Anarkade. A couch multiplayer 2D shooter.

panreyes

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

josebita

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

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?

JaViS

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

Working on Anarkade. A couch multiplayer 2D shooter.

JaViS

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
Working on Anarkade. A couch multiplayer 2D shooter.

josebita

#6
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.

JaViS

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
Working on Anarkade. A couch multiplayer 2D shooter.

josebita

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.

josebita

I've just tested the example modified to read the text file from a subfolder and it appears to be working fine.

JaViS

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

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

I'm using the bennugd release distributed with Pixel's "Plantilla".
Working on Anarkade. A couch multiplayer 2D shooter.

josebita

Pixplantilla is fairly old... Any chance of trying your code in pixtudio?

JaViS

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.