We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2552

Summary: problem to read file
Product: SDL Reporter: lctmp2
Component: fileAssignee: Sylvain <sylvain.becker>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: gabomdq, philipp.wiesemann
Version: 2.0.3   
Hardware: ARM   
OS: Android (All)   
Attachments: resource file
resource file

Description lctmp2 2014-05-19 07:29:30 UTC
Created attachment 1651 [details]
resource file

Hello,

I try to port my game to android.
It works fine on linux and Windows but I have problem to open my resource file with the sdl api.
The api seems to read only 6 Bytes.
Here is the simple test code I use:
SDL_RWops* res = SDL_RWFromFile(path, "rb");
    SDL_RWseek(res,0,RW_SEEK_END);
    int fileSize = SDL_RWtell(res);
#ifdef ANDRO
    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "fileSize %d \n", (int)fileSize);
#endif
    printf("fileSize %d \n", (int)fileSize);

You can try with the file attached.
Thanks.
Comment 1 lctmp2 2014-05-19 08:08:12 UTC
Created attachment 1653 [details]
resource file
Comment 2 Gabriel Jacobo 2014-05-19 13:36:26 UTC
What path are you using?
Comment 3 lctmp2 2014-05-19 14:20:03 UTC
I simply use «res.bin» because my file is in the assets directory.
Comment 4 Gabriel Jacobo 2014-05-19 14:28:55 UTC
Did you extract the APK and verified the file is in there and it's contents look ok? Which device are you having problems with?
Comment 5 lctmp2 2014-05-19 15:23:16 UTC
Yes, I have opened the .apk to verify the size of the file. I use an Acer  liquid e2 v370 with android 4.2.2.
Comment 6 Philipp Wiesemann 2015-06-09 20:28:02 UTC
SDL_RWseek() returns -1 if it failed. This could also be checked.

Or SDL_RWsize() could be used.
Comment 7 Sam Lantinga 2017-08-14 13:08:02 UTC
Sylvain, can you confirm that you can just drop a file in the apk and read it without specifying the path?
Comment 8 Sylvain 2017-08-14 13:37:33 UTC
This is working.
make sure your asset file is in ./assets/


       const char *path = "background.jpg";
       SDL_RWops* res = SDL_RWFromFile(path, "rb");
       int r = SDL_RWseek(res,0,RW_SEEK_END);
       int fileSize = SDL_RWtell(res);
       some printf("tell %d filesize", fileSize);
Comment 9 Sam Lantinga 2017-08-14 14:13:35 UTC
I'm closing this for now. Please reopen it if you have a file in the assets directory that you can't open using the SDL API.

Thanks!