Question

I have this piece of code working on Linux with g++:

GLuint Shader::initShader_(GLenum shaderType, const std::string& shaderFilename)
{
    std::ifstream inputFile(shaderFilename.c_str());
    if (inputFile.is_open() == false)
    {
        std::ostringstream oss;
        oss << "Shader " << shaderFilename << " doesn't exist!";
        print(LOG_LEVEL::ERROR, oss.str());
    }
    ...
}

where the three dots represent some code. On both g++ and Visual Studio (2012) the code compiles. But with Visual Studio, the first line throws an access violation exception. This actually happens when opening the file, and the debugger redirects me to do_always_noconv but I do not understand the problem.

The string containing the filename is valid and the file the program is trying to open is in the good directory, and the debugger works in this directory. I guess the problem does not come from the file itself, because if the stream cannot open it then I could still enter the next line without an access violation.

Does anyone already encountered this problem or has an idea? Again it worked without any problem on Linux with g++.

Thanks for your help.

Was it helpful?

Solution

An access violation exception doesn't indicate a problem with the file, but with the in-memory representation of the ifstream object or the string. Start looking for memory corruption.

Be sure you're referencing the correct GLSDK libraries for your build type. e.g. debug builds should reference debug libraries and release builds should reference release libraries.

OTHER TIPS

As PaulH suggested above, I checked some array code that I wrote recently and the error came from some wrong indices and pointers. However I still do not understand why the errors in the array code have something to do with the ifstream. Thanks to PaulH!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top