* Fix null ptr bug in automasking code
This commit is contained in:
parent
82f5e0200c
commit
9fab16f0f3
|
@ -93,6 +93,19 @@ BLI_mempool_iter *BLI_mempool_iter_threadsafe_create(BLI_mempool *pool,
|
|||
ATTR_NONNULL();
|
||||
void BLI_mempool_iter_threadsafe_free(BLI_mempool_iter *iter_arr) ATTR_NONNULL();
|
||||
|
||||
|
||||
/*
|
||||
This preallocates a mempool suitable for threading. totelem elements are preallocated
|
||||
in chunks of size pchunk, and returned in r_chunks.
|
||||
*/
|
||||
|
||||
BLI_mempool *BLI_mempool_create_for_tasks(const unsigned int esize,
|
||||
unsigned int totelem,
|
||||
const unsigned int pchunk,
|
||||
void ***r_chunks,
|
||||
unsigned int *r_totchunk,
|
||||
unsigned int flag);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -250,6 +250,82 @@ static BLI_freenode *mempool_chunk_add(BLI_mempool *pool,
|
|||
return curnode;
|
||||
}
|
||||
|
||||
/*
|
||||
This preallocates a mempool suitable for threading. totelem elements are preallocated
|
||||
in chunks of size pchunk, and returned in r_chunks. The idea is to pass these
|
||||
to tasks.
|
||||
*/
|
||||
|
||||
BLI_mempool *BLI_mempool_create_for_tasks(const unsigned int esize,
|
||||
unsigned int totelem,
|
||||
const unsigned int pchunk,
|
||||
void ***r_chunks,
|
||||
unsigned int *r_totchunk,
|
||||
unsigned int flag)
|
||||
{
|
||||
BLI_mempool *pool = BLI_mempool_create(esize, totelem, pchunk, flag);
|
||||
|
||||
BLI_mempool_chunk **chunks = MEM_callocN(sizeof(void *) * pool->maxchunks,
|
||||
"BLI_mempool_create_for_tasks r_chunks");
|
||||
|
||||
int totalloc = 0;
|
||||
*r_totchunk = 0;
|
||||
|
||||
BLI_mempool_chunk *chunk = pool->chunks, *lastchunk = NULL;
|
||||
|
||||
while (chunk) {
|
||||
chunk = chunk->next;
|
||||
totalloc += pool->pchunk;
|
||||
lastchunk = chunk;
|
||||
}
|
||||
|
||||
pool->totused = totalloc;
|
||||
pool->free = NULL;
|
||||
|
||||
int i = pool->pchunk - 1;
|
||||
|
||||
while (lastchunk && totalloc > totelem) {
|
||||
if (i < 0) {
|
||||
BLI_mempool_chunk *lastchunk2 = NULL;
|
||||
|
||||
for (chunk = pool->chunks; chunk; chunk = chunk->next) {
|
||||
if (chunk == lastchunk) {
|
||||
lastchunk = lastchunk2;
|
||||
}
|
||||
}
|
||||
|
||||
if (!lastchunk) {
|
||||
break;
|
||||
}
|
||||
|
||||
i = pool->pchunk - 1;
|
||||
}
|
||||
|
||||
char *elem = CHUNK_DATA(lastchunk);
|
||||
elem += pool->esize * (unsigned int)i;
|
||||
|
||||
BLI_mempool_free(pool, elem);
|
||||
|
||||
totalloc--;
|
||||
}
|
||||
|
||||
unsigned int ci = 0;
|
||||
|
||||
chunk = pool->chunks;
|
||||
while (chunk && chunk != lastchunk) {
|
||||
chunks[ci++] = CHUNK_DATA(chunk);
|
||||
chunk = chunk->next;
|
||||
}
|
||||
|
||||
if (lastchunk && i >= 0) {
|
||||
chunks[ci++] = CHUNK_DATA(lastchunk);
|
||||
}
|
||||
|
||||
*r_totchunk = ci;
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
static void mempool_chunk_free(BLI_mempool_chunk *mpchunk)
|
||||
{
|
||||
MEM_freeN(mpchunk);
|
||||
|
|
|
@ -99,6 +99,7 @@ set(SRC
|
|||
intern/bmesh_mesh.c
|
||||
intern/bmesh_mesh.h
|
||||
intern/bmesh_mesh_convert.c
|
||||
intern/bmesh_mesh_convert_threaded.c
|
||||
intern/bmesh_mesh_convert.h
|
||||
intern/bmesh_mesh_duplicate.c
|
||||
intern/bmesh_mesh_duplicate.h
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -145,7 +145,7 @@ float SCULPT_automasking_factor_get(AutomaskingCache *automasking,
|
|||
return mask;
|
||||
}
|
||||
|
||||
do_concave = ss->cache->brush->concave_mask_factor > 0.0f &&
|
||||
do_concave = ss->cache && ss->cache->brush && ss->cache->brush->concave_mask_factor > 0.0f &&
|
||||
(automasking->settings.flags & BRUSH_AUTOMASKING_CONCAVITY);
|
||||
|
||||
/* If the cache is initialized with valid info, use the cache. This is used when the
|
||||
|
@ -374,7 +374,7 @@ static void SCULPT_automasking_cache_settings_update(AutomaskingCache *automaski
|
|||
automasking->settings.flags = sculpt_automasking_mode_effective_bits(sd, brush);
|
||||
|
||||
automasking->settings.initial_face_set = SCULPT_active_face_set_get(ss);
|
||||
automasking->settings.concave_factor = brush->concave_mask_factor;
|
||||
automasking->settings.concave_factor = brush ? brush->concave_mask_factor : 0.0f;
|
||||
}
|
||||
|
||||
float SCULPT_calc_concavity(SculptSession *ss, SculptVertRef vref)
|
||||
|
|
Loading…
Reference in New Issue