multithreading - C++ Thread works fine long time but then I'm getting abort error -


i have built procedural terrain creator using voxels. terrain divived in chunks, chunks created in seperate, detached thread. since did this, there no lag anymore because built in background. works fine 2000 chunks (32*32*64), "abort() has been called" error. debug information looks fine.

enough words, here code:

in manager-constructor thread initialized:

try{         m_creatorthread1 = std::thread(&chunkmanager::createchunk, this);         m_creatorthread1.detach();     }     catch (...){         m_work = false;         m_creatorthread1.join();         throw;     } 

this function thread executes:

void chunkmanager::createchunk(){     while (m_work){          if (!m_buildq.empty()){             position tmp = m_buildq.back();             m_buildq.pop_back();             chunk* ctmp = new chunk(this->m_terrain, tmp);             m_mutex.lock();             m_chunks.push_back(ctmp);             m_mutex.unlock();         }     } } 

the function feeds m_buildq:

void chunkmanager::generatechunks(position position){         (int = position.x - chunk_prld_x; < position.x + chunk_prld_x; i++){             (int j = position.z - chunk_prld_z; j < position.z + chunk_prld_z; j++){                 position chunkpos;                 chunkpos.x = *chunk_size; chunkpos.z = j *chunk_size;                      if (!isused(chunkpos)){                     m_used.push_back(chunkpos);                     m_buildq.push_back(chunkpos);                 }             }         } } 

and function renders chunks:

void chunkmanager::render(){     m_mutex.lock();     (vector<chunk*>::iterator = m_chunks.begin(); != m_chunks.end(); ++it){         if (m_frustum->checksphere((*it)->getposition().x +chunk_size/2, chunk_height / 2, (*it)->getposition().z + chunk_size/2, chunk_size*1.3f)){             if ((*it)->hasgraphics())                 (*it)->render();             else{                 (*it)->initializegraphics(opengl);             }         }     }     m_mutex.unlock(); } 

in short: every frame there check if new chunks need loaded, if so, generatechunks feeds m_buildq vector positions of chunks got loaded. thread runs in background , creates new chunks if in buildq. because of opengl-reasons, vao , vbo dont initialized in thread in renderer if needed.

as said, works fine until i've spent time in application , thousands of chunks created. can find mistake?

here things of debug:

m_chunks: size= 1392 it-ptr: points on valid chunk thread: hnd:0x00000264 id: 0 

if needs more debug information tell me.


Comments