How to solve stbi_load error of “no SOI”?

I’m loading a picuture by stbi_load, but there was an error of no SOI. I had used the picture in another project and it was loaded successfully. So I think the path of picture and the picuture is valid. But I don’t know why the error occured? Here are some of the main code:

// Texture2D is a class of textures 
Texture2D ResourceManager::loadTextureFromFile(const GLchar *file, GLboolean alpha){
    // create texture object
    Texture2D texture;
    if (alpha){
        texture.Internal_Format = GL_RGBA;
        texture.Image_Format = GL_RGBA;
    }
    // load picture
    int width, height, nrChannels;
    unsigned char *image = stbi_load(file, &width, &height, &nrChannels, 0);
    if (stbi_failure_reason())
        std::cout << stbi_failure_reason() << std::endl;
    // generate texture
    texture.Generate(width, height, image);
    // free image
    stbi_image_free(image);
    return texture;
}

I use loadTextureFromFile("./Data/awesomeface.png", GL_TRUE); to get the texture. And stbi_failure_reason() returns no SOI. When I debug the project in VS2013, the memory of image is valid but display characters in a string are invalid. Anyone help?

Leave a Comment