Reputation: 81
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?
Upvotes: 1
Views: 2786
Reputation: 2091
Try updating the library (current one is 2.27) seems it was fixed:
https://github.com/nothings/stb/issues/787
Upvotes: 0
Reputation: 43
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
Upvotes: 1