#84 textureRegisterBlock Multi-threaded Crash

open
nobody
None
5
2008-03-18
2008-03-18
Aasimon
No

More likely to happen with a more threads and processors.

texture.cpp textureRegisterBlock(...) adds the cEntry to the CRender::textureUsedBlocks list. It then fills in the contents. Doing this courses texture.cpp textureMemFlush( .. ) to crash with a 0xCCCCCCCC threads pointer as the cEntry is on the list but not setup yet.

Moving the cEntry initialise code to the from of the routine helps stop this.

static inline void textureRegisterBlock(CTextureBlock *cEntry,int size) {

// Fully construct the cEntry before placing it on the list
cEntry->data = NULL;
cEntry->refCount = 0;
cEntry->threadData = new CTexBlockThreadData[CRenderer::numThreads];
cEntry->size = size;

#ifdef TEXTURE_PERBLOCK_LOCK
osCreateMutex(cEntry->mutex);
#endif
for (int i=0;i<CRenderer::numThreads;++i) {
cEntry->threadData[i].data = NULL;
cEntry->threadData[i].lastRefNumber = 0; // FIXME: is this right?
// should be CRenderer::textureRefNumber ???
}

// Place cEntry on list
cEntry->prev = NULL;
cEntry->next = CRenderer::textureUsedBlocks;
if (CRenderer::textureUsedBlocks != NULL)
CRenderer::textureUsedBlocks->prev = cEntry;
CRenderer::textureUsedBlocks = cEntry;
}

Side note: Adding the cEntry to the list is not thread safe.

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks