I use a library to retrieve data from an Image (in unsigned char *), and I use it to allocate in an OpenGL Buffer.
Because the image can be large, OpenGL by default creates another thread to perform this activity. But I realize free of that image soon after in the main thread, because the data is no longer necessary. Then I get the access violation error in the address (Visual Studio).
- Does C ++ have any recourse to check if a memory is not being used by another Thread Implicit (ie I do not have access)?
Details:
- The function I use, which generates a new thread is glTexImage2D.
- The error occurs randomly, it depends a lot if the main thread runs free before Opengl allocates to the Buffer
Technical Details:
Exception generated at 0x07B8F54F (ig8icd32.dll) on ... [programname.exe]: 0xC0000005: access violation while reading location 0x13E1B000.
The address 0x13E1B000 is null. Excerpt of code as requested
int width, height, nrChannels;
unsigned char *dataImg = stbi_load(path, &width, &height, &nrChannels, 0);
GLenum format;
if (nrChannels == 1)
format = GL_RED;
else if (nrChannels == 3)
format = GL_RGB;
else if (nrChannels == 4)
format = GL_RGBA;
if (dataImg) {
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, dataImg);
glGenerateMipmap(GL_TEXTURE_2D);
} else {
log(StringBuilder::concat("STBI_LOAD::FAILED_TO_LOAD_IMAGE::", path));
}
stbi_image_free(dataImg);// <- ERRO AQUI