I added code to read a text file, it works perfectly file in Debug, but when I test under Release it crashes with:
Unhandled exception at 0x10138783 in Irrlicht Project.exe:
0xC0000005: Access violation reading location 0x00000005.
I stress that this does not happen under the Debugging environment.
My code is all in a main with this behavior:
createDevice()
getVideoDriver()
readMap() <- New Code that causes this problem
loadTextures() <- Section that Visual Studio breaks to
gameLoop()
My load map code is:
- cpp Code: Select all
io::IReadFile *textfile = device->getFileSystem()->createAndOpenFile("map/test.txt");
char ch[64] = {0};
for (int z = 0; z < 64; z++)
{
for (int x = 0; x <= 64; x++)
{
textfile->read(ch, 1);
if (ch[0] != '\n')
{
worldMap[64 - x][z] = atoi(ch);
}
else
{
textfile->read(ch, 1);
worldMap[64 - x][z] = atoi(ch);
}
}
}
And it breaks at the first loaded texture of three:
- cpp Code: Select all
device->getCursorControl()->setVisible(false);
redbrick = driver->getTexture("pics/redbrick.png"); // Breaks here
greystone = driver->getTexture("pics/wood.png");
pillar = driver->getTexture("pics/greenlight2.png");
This is the next use of the file system after the map read.
If I move the map read to after the texture load, it breaks at the moment it meets my main loop:
- cpp Code: Select all
while (device->run() && quit == false) // Breaks here at device->run() as soon as it hits (Doesn't even loop once)
{
// Game code that works fine
}
Again: It works under debug, not under release.
The map file I used and it's folder is in the working directory, the debug and the release folder, I have checked the working directory and it is normal and the same in both debug and release.
Oh yes, I get this on multiple machines and it is reproducible.
These are my includes:
- cpp Code: Select all
#include <irrlicht.h>
#include <time.h>
using namespace irr;
using namespace scene;
EDIT: Changing the read length from 1 to 8 changes the error from 0x00000005 to 0x3131313d, so is this the issue?
EDIT 2: SOLVED!
The problem was that I was writing to my worldMap array a line break character (The test for the != '\n' when it returned false), the debugger must have shrugged this off but the release environment kept it strict and threw it back at me.
I've been scratching my head on this all day!
Simply removing the second worldMap[][] line from the map load fixed it.
