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 1696

Summary: New FileDescriptor based RWops system is broken
Product: SDL Reporter: paul
Component: fileAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: gabomdq, philipp.wiesemann
Version: HG 2.0   
Hardware: ARM   
OS: Android (All)   
Attachments: Patch to fix the issue.
Patch for not deleted global reference on Android.

Description paul 2013-01-14 02:16:17 UTC
Created attachment 1023 [details]
Patch to fix the issue.

The newly added Android RWops system for directly accessing the native filehandle
does not seek to the correct offset in the file. 

So if you don't do a seek before reading data, you won't get what you expect.

I have attached a patch that fixes the issue for me.
Comment 1 Gabriel Jacobo 2013-01-14 15:21:29 UTC
Thanks! http://hg.libsdl.org/SDL/rev/b3d3ef1e15b5
Comment 2 Philipp Wiesemann 2013-01-16 12:37:31 UTC
There is maybe another problem: The GlobalRef stored in assetFileDescriptorRef is not deleted if the control flow does "goto fallback".  It is only deleted if it does "goto failure". This may be fixed if the GlobalRef is created later (after gotos).
Comment 3 Philipp Wiesemann 2013-01-27 05:46:56 UTC
Created attachment 1029 [details]
Patch for not deleted global reference on Android.

I attached a patch for the problem I tried to describe above (global reference not deleted on error).

I do not know how often exception might happen at "getStartOffset" and "getDeclaredLength" but I think there was a reason the checks were added. Without the described change this part of the source will not be "exception safe" because it leaks.

On the other hand if no exceptions might happen there at all the checks and gotos might be removed to make the source more clear. The the creation of the global reference does not need to be changed.
Comment 4 Gabriel Jacobo 2013-01-27 16:44:08 UTC
http://hg.libsdl.org/SDL/rev/ac7f004fb63c Thanks!