[no]Bug in IFileSystem::createAndOpenFile || IReadFile

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.

[no]Bug in IFileSystem::createAndOpenFile || IReadFile

Postby Dreadstew » Mon Mar 12, 2018 9:21 pm

Hi, I load a file two different ways. Irrlicht has exponents tacked onto the end. Must have happened in openFile or ReadFile. Not sure. But it makes the irrlicht file loader unusable for me.

cpp Code: Select all
io::IReadFile* ini = filesystem->createAndOpenFile(io::path("C:/Users/cool_/Documents/VisualStudio2017Projects/GoldenAgeClient/x64/Assets/ini.txt"));
char* buffer = (char*) malloc(ini->getSize());
ini->read(buffer, ini->getSize());
stringstream ss;
ss << buffer;
cout << ss.str() << endl;
 
ifstream t("C:/Users/cool_/Documents/VisualStudio2017Projects/GoldenAgeClient/x64/Assets/ini.txt");
stringstream buf;
buf << t.rdbuf();
cout << buf.str() << endl;


The log:
#This should be set to your "Assets" folder
WorkingDirectory = C:/Users/cool_/Documents/VisualStudio2017Projects/GoldenAgeClient/x64/Assets²²²²
#This should be set to your "Assets" folder
WorkingDirectory = C:/Users/cool_/Documents/VisualStudio2017Projects/GoldenAgeClient/x64/Assets
Dreadstew
 
Posts: 11
Joined: Wed Apr 01, 2015 5:18 pm

Re: Bug in IFileSystem::createAndOpenFile || IReadFile

Postby CuteAlien » Mon Mar 12, 2018 11:52 pm

It's not Irrlicht adding stuff, you simply have that stuff randomly in your memory. The problem you are having is that you print a string which is not null-terminated. That's unless your file accidentally ends with 0 - which is usually not the case, especially not for text-files. So it prints the string until you have some random 0 somewhere in memory. This is not an Irrlicht thing but something you have in general when reading files into a string-buffer (so the exact same with fopen for example). What you need to do is to allocate a buffer with 1 byte more than file-size. And then terminate the buffer yourself with buffer[ini->getSize()] = 0;
IRC: #irrlicht on irc.freenode.net
Code snippets, patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Free racer created with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
User avatar
CuteAlien
Admin
 
Posts: 8513
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: [no]Bug in IFileSystem::createAndOpenFile || IReadFile

Postby Dreadstew » Tue Mar 13, 2018 10:32 pm

Oh I should have known! So I don't get this problem with ifstream because I don't use ios::binary (or something like that). Maybe provide a text file version of createAndOpenFile?
Dreadstew
 
Posts: 11
Joined: Wed Apr 01, 2015 5:18 pm

Re: [no]Bug in IFileSystem::createAndOpenFile || IReadFile

Postby CuteAlien » Wed Mar 14, 2018 2:57 am

It's not a stream class but the equivalent of fopen (which is even used in this case). So it's a little bit hard to compare exactly. fopen also has a text-mode but that wouldn't do the same. Actually it's not even defined _what_ that text-mode does, that's up to the implementation and different system would do different things. It might do some endline conversions which will change the amount of bytes even more (fopen has a rather unfortunate default and generally you want to use fopen with "b" flag in nearly every case and forgetting it will drive you crazy in debugging until you see it).

ifstream is a little bit nicer - and I actually recommend using the c++ stream classes when you can. You can mix STL and Irrlicht code - I do that all the time.
IRC: #irrlicht on irc.freenode.net
Code snippets, patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Free racer created with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
User avatar
CuteAlien
Admin
 
Posts: 8513
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany


Return to Bug reports

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron