1

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?

luckintt
  • 63
  • 6

2 Answers2

1

from an old project i found on my disk. i'm not used to C++ anymore, so i'am not sure if it has sth to do with your problem, but i think i am looking at c++ code?

  auto textureBuffer = stbi_load("graphics/texture.png", &width, &height, &bitppx, 4);

and i found something about corrupted .png files with stb

Some PNGs look enough like a JPEG that the JPEG file format test will break with the "no SOI" error instead of rejecting the image as a JPEG.

https://github.com/nothings/stb/issues/787

solutions:

  • check your if your filepath is correct

  • check if a different .png works

  • use auto textureBuffer instead of unsigned char pointer

Qsnok
  • 43
  • 5
  • 1
    bitppx is actually the number of channels, not the number of bits per pixel. – BDL Apr 29 '20 at 08:04
  • Yes, this is c++ project. And I use OpenGL4.0. The path is right. I reuse a jpg image and use auto instead of unsigned char pointer. Although the `no SOI` error solved, the data of image become error code and memory access conflicts arisen.It's confusing. – luckintt Apr 29 '20 at 08:12
  • I change the last parameter of `stbi_load` to 4, the data of image still is garbled code. – luckintt Apr 29 '20 at 09:11
  • from the stb_i.c doc on supportet filetypes: QUICK NOTES: Primarily of interest to game developers and other people who can avoid problematic images and only need the trivial interface JPEG baseline (no JPEG progressive) PNG 8-bit only – Qsnok Apr 29 '20 at 15:02
0

Try updating the library (current one is 2.27) seems it was fixed:

https://github.com/nothings/stb/issues/787

pedro_bb7
  • 1,601
  • 3
  • 12
  • 28