mardi 14 avril 2015

c++11 std::thread integer division by zero Open GL SOIL

I'm using VS 13 and the thread functionality of c++11 to load in a whole ton of textures to OpenGL using the SOIL library. If I dont use threads ie:



textures_[12] = SOIL_load_OGL_texture(chars[12], SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);


it works fine. chars[] is a list of the file names to be loaded in. It works fine in a for loop too ie:



for (int i = start; i < stop;i++)
textures_[i] = SOIL_load_OGL_texture(chars[i], SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);


but when I try to use threads to speed up the process it throws an integer division by zero exception ie:



for(int i=0;i<13;i++)
{
threads.push_back(std::thread(&Scene3D::threadfunc, this, i * 491, ((i * 491) + 491)));

}
for (int j = 0; j<13; j++)
{
threads[j].join();
}

void Scene3D::threadfunc(int start, int stop)
{
for (int i = start; i < stop;i++)
textures_[i] = SOIL_load_OGL_texture(chars[i], SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);

}


Any insight into why this is happening would be greatly appreciated, thanks.


Aucun commentaire:

Enregistrer un commentaire