1 hour ago, Hodgman said:
If you get a crash inside a dll with a name like "nv something gl something dll" or "amd something gl something dll", then yeah, that's inside your GL driver.
99% of the time, it's your bug that's caused the crash, not theirs. For example, if you've passed a pointer to a buffer into the driver (e.g. to tell it to copy some pixel data out of that buffer), but the pointer isn't actually valid to read from, then the driver will crash when it tries to read from it. The crash occurs in the driver, but the bug is in your code (passing invalid pointers to the driver).
Seeing this is to do with texture loading, I would guess that you've somehow asked the driver to read more pixel than actually exist within your memory allocation.
Texture::Texture(std::string path, bool trans, int unit)
{
//Reverse the pixels.
stbi_set_flip_vertically_on_load(1);
//Try to load the image.
unsigned char *data = stbi_load(path.c_str(), &m_width, &m_height, &m_channels, 0);
//Image loaded successfully.
if (data)
{
//Generate the texture and bind it.
GLCall(glGenTextures(1, &m_id));
GLCall(glActiveTexture(GL_TEXTURE0 + unit));
GLCall(glBindTexture(GL_TEXTURE_2D, m_id));
//Not Transparent texture.
if (!trans)
{
GLCall(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_width, m_height, 0, GL_RGB, GL_UNSIGNED_BYTE, data));
}
//Transparent texture.
else
{
GLCall(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data));
}
//Texture Filters.
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT));
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT));
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST));
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
//Generate mipmaps.
GLCall(glGenerateMipmap(GL_TEXTURE_2D));
}
//Loading Failed.
else
throw VampEngine::EngineError("The was an error loading image: " + path);
//Unbind the texture.
GLCall(glBindTexture(GL_TEXTURE_2D, 0));
//Free the image data.
stbi_image_free(data);
}
The thing is that never happened before using the above code. Can it be the fault of the image file? Maybe some corrupted bytes?
Quote
Seeing this is to do with texture loading, I would guess that you've somehow asked the driver to read more pixel than actually exist within your memory allocation.
Now that you mentioned that, GlTexImage2D() takes the data pointer, the width and the height of the image. How does this function know how many bytes to read from the data buffer? Can it calculate it using the width and the height?
GlTexImage2D Doc