The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_RWop::read() file size limit?
loadRunner


Joined: 28 May 2014
Posts: 2
Platform: Android

I am trying to read a simple text file with SDL_RWops::read() file that is 1.7 megs in size. I have successfully read loads of text files already smaller than 500 kb, but my program crashes at that function call with larger files. Is there a file size limit to the function? Is there a work around?

I am on my phone, so can't properly format the code here, but here is roughly the essential parts:

SDL_RWops *io = NULL;
io =SDL_RWFromFile(fileName.c_str(), "r");

char name[18000000];

if (io != NULL)
{
Sint64 seek_ = SDL_REdeem(io, 0, RW_SEEK_END);
Sint64 sizeOfFileInBytes = SDL_RWtell(io);
seek_ = SDL_RWseek(io, 0, RW_SEEK_SET);

if (io->read(io, name, sizeOfFileInBytes, 1) > 0)
{
SDL_Log("Failed to Load");
}
io->close(io);
}
loadRunner


Joined: 28 May 2014
Posts: 2
Sorry about the auto correct, here is the correct code:

SDL_RWops *io = NULL;
io =SDL_RWFromFile(fileName.c_str(), "r");

char name[1800000];

if (io != NULL)
{
Sint64 seek_ = SDL_RWseek(io, 0, RW_SEEK_END);
Sint64 sizeOfFileInBytes = SDL_RWtell(io);
seek_ = SDL_RWseek(io, 0, RW_SEEK_SET);

if (io->read(io, name, sizeOfFileInBytes, 1) > 0)
{
SDL_Log("Failed to Load");
}
io->close(io);
}
SDL_RWop::read() file size limit?
M. Gerhardy
Guest

Hi,


no, there is no limit, you just didn't use it correctly. See my code at https://github.com/mgerhardy/caveexpress/blob/master/src/engine/common/File.cpp#L111 for an example how to use it properly. The important part is the return value - read does not have to return all the requested bytes, but only parts of it.



Regards
Martin


On Fri, Dec 19, 2014 at 1:15 AM, loadRunner wrote:
Quote:
Platform: Android

I am trying to read a simple text file with SDL_RWops::read() file that is 1.7 megs in size. I have successfully read loads of text files already smaller than 500 kb, but my program crashes at that function call with larger files. Is there a file size limit to the function? Is there a work around?

I am on my phone, so can't properly format the code here, but here is roughly the essential parts:

SDL_RWops *io = NULL;
io =SDL_RWFromFile(fileName.c_str(), "r");

char name[18000000];

if (io != NULL)
{
Sint64 seek_ = SDL_REdeem(io, 0, RW_SEEK_END);
Sint64 sizeOfFileInBytes = SDL_RWtell(io);
seek_ = SDL_RWseek(io, 0, RW_SEEK_SET);

if (io->read(io, name, sizeOfFileInBytes, 1) > 0)
{
SDL_Log("Failed to Load");
}
io->close(io);
}


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




--
http://ufoai.sf.net
http://sf.net/projects/ufoai