[Bf-blender-cvs] [26762d25e8d] temp-trimesh-sculpt: fixed various crashes
Joseph Eagar
noreply at git.blender.org
Wed Oct 14 10:20:16 CEST 2020
Commit: 26762d25e8dbc6f458aa4d8a2c848a805fc04b39
Author: Joseph Eagar
Date: Wed Oct 14 01:20:07 2020 -0700
Branches: temp-trimesh-sculpt
https://developer.blender.org/rB26762d25e8dbc6f458aa4d8a2c848a805fc04b39
fixed various crashes
===================================================================
M source/blender/blenkernel/BKE_pbvh.h
M source/blender/blenkernel/intern/pbvh.c
M source/blender/blenkernel/intern/pbvh_trimesh.c
M source/blender/editors/sculpt_paint/sculpt_dyntopo.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 5188303adf0..3ee78f715e1 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -101,7 +101,7 @@ TMElemSet *TMElemSet_new();
void TMElemSet_free(TMElemSet *ts);
void TMElemSet_insert(TMElemSet *ts, void *elem);
bool TMElemSet_add(TMElemSet *ts, void *elem);
-void TMElemSet_remove(TMElemSet *ts, void *elem);
+void TMElemSet_remove(TMElemSet *ts, void *elem, bool ignoreExist);
bool TMElemSet_has(TMElemSet *ts, void *elem);
#define TMS_ITER(v, ts) \
@@ -503,7 +503,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
else if (vi.tm_vdata) { \
TMVert *tv = NULL;\
while (!tv) {\
- if (vi.ti >= vi.tm_cur_set->cur) {\
+ if (!vi.tm_cur_set->elems || vi.ti >= vi.tm_cur_set->cur) {\
if (vi.tm_cur_set != vi.tm_other_verts) {\
vi.tm_cur_set = vi.tm_other_verts;\
vi.ti = 0;\
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 245657fa595..7d43b6d1322 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -3082,6 +3082,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
}
if (pbvh->type == PBVH_TRIMESH) {
+ vi->ti = 0;
vi->tm_unique_verts = node->tm_unique_verts;
vi->tm_other_verts = node->tm_other_verts;
vi->tm_cur_set = vi->tm_unique_verts;
diff --git a/source/blender/blenkernel/intern/pbvh_trimesh.c b/source/blender/blenkernel/intern/pbvh_trimesh.c
index 90764af0f3e..edef0f29cb2 100644
--- a/source/blender/blenkernel/intern/pbvh_trimesh.c
+++ b/source/blender/blenkernel/intern/pbvh_trimesh.c
@@ -134,13 +134,15 @@ void TMElemSet_insert(TMElemSet *ts, void *elem) {
ts->length++;
}
-void TMElemSet_remove(TMElemSet *ts, void *elem) {
+void TMElemSet_remove(TMElemSet *ts, void *elem, bool ignoreExist) {
int idx = (int)BLI_ghash_lookup(ts->ptr_to_idx, elem);
BLI_ghash_remove(ts->ptr_to_idx, elem, NULL, NULL);
if (ts->elems[idx] != elem) {
- printf("eek! %p", elem);
+ if (!ignoreExist) {
+ printf("eek! %d %p %p\n", idx, elem, ts->elems[idx]);
+ }
return;
}
@@ -661,12 +663,12 @@ static void pbvh_trimesh_vert_ownership_transfer(PBVH *bvh, PBVHNode *new_owner,
BLI_assert(current_owner != new_owner);
/* Remove current ownership */
- TMElemSet_remove(current_owner->tm_unique_verts, v);
+ TMElemSet_remove(current_owner->tm_unique_verts, v, false);
/* Set new ownership */
TM_ELEM_CD_SET_INT(v, bvh->cd_vert_node_offset, (int)(new_owner - bvh->nodes));
TMElemSet_insert(new_owner->tm_unique_verts, v);
- TMElemSet_remove(new_owner->tm_other_verts, v);
+ TMElemSet_remove(new_owner->tm_other_verts, v, true);
BLI_assert(!TMElemSet_has(new_owner->tm_other_verts, v));
/* mark node for update */
@@ -679,7 +681,7 @@ static void pbvh_trimesh_vert_remove(PBVH *bvh, TMVert *v)
int f_node_index_prev = DYNTOPO_NODE_NONE;
PBVHNode *v_node = pbvh_trimesh_node_from_vert(bvh, v);
- TMElemSet_remove(v_node->tm_unique_verts, v);
+ TMElemSet_remove(v_node->tm_unique_verts, v, false);
TM_ELEM_CD_SET_INT(v, bvh->cd_vert_node_offset, DYNTOPO_NODE_NONE);
/* Have to check each neighboring face's node */
@@ -696,7 +698,7 @@ static void pbvh_trimesh_vert_remove(PBVH *bvh, TMVert *v)
f_node->flag |= PBVH_UpdateDrawBuffers | PBVH_UpdateBB;
/* Remove current ownership */
- TMElemSet_remove(f_node->tm_other_verts, v);
+ TMElemSet_remove(f_node->tm_other_verts, v, true);
BLI_assert(!TMElemSet_has(f_node->tm_unique_verts, v));
BLI_assert(!TMElemSet_has(f_node->tm_other_verts, v));
@@ -729,7 +731,7 @@ static void pbvh_trimesh_face_remove(PBVH *bvh, TMFace *f)
}
else {
/* Remove from other verts */
- TMElemSet_remove(f_node->tm_other_verts, v);
+ TMElemSet_remove(f_node->tm_other_verts, v, true);
}
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
index 955eece829d..5d8b0fe3355 100644
--- a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
@@ -263,6 +263,15 @@ static void SCULPT_dynamic_topology_disable_ex(
ss->bm_log = NULL;
}
+ if (ss->tm) {
+ TMesh_free(ss->tm);
+ ss->tm = NULL;
+ }
+ if (ss->tm_log) {
+ TM_log_free(ss->tm_log);
+ ss->tm_log = NULL;
+ }
+
BKE_particlesystem_reset_all(ob);
BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_OUTDATED);
@@ -287,7 +296,7 @@ void sculpt_dynamic_topology_disable_with_undo(Main *bmain,
Object *ob)
{
SculptSession *ss = ob->sculpt;
- if (ss->bm != NULL) {
+ if (ss->tm != NULL) {
/* May be false in background mode. */
const bool use_undo = G.background ? (ED_undo_stack_get() != NULL) : true;
if (use_undo) {
@@ -307,7 +316,7 @@ static void sculpt_dynamic_topology_enable_with_undo(Main *bmain,
Object *ob)
{
SculptSession *ss = ob->sculpt;
- if (ss->bm == NULL) {
+ if (ss->tm == NULL) {
/* May be false in background mode. */
const bool use_undo = G.background ? (ED_undo_stack_get() != NULL) : true;
if (use_undo) {
@@ -331,7 +340,7 @@ static int sculpt_dynamic_topology_toggle_exec(bContext *C, wmOperator *UNUSED(o
WM_cursor_wait(true);
- if (ss->bm) {
+ if (ss->tm) {
sculpt_dynamic_topology_disable_with_undo(bmain, depsgraph, scene, ob);
}
else {
@@ -381,7 +390,7 @@ enum eDynTopoWarnFlag SCULPT_dynamic_topology_check(Scene *scene, Object *ob)
enum eDynTopoWarnFlag flag = 0;
- BLI_assert(ss->bm == NULL);
+ BLI_assert(ss->tm == NULL);
UNUSED_VARS_NDEBUG(ss);
for (int i = 0; i < CD_NUMTYPES; i++) {
@@ -426,7 +435,7 @@ static int sculpt_dynamic_topology_toggle_invoke(bContext *C,
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
- if (!ss->bm) {
+ if (!ss->tm) {
Scene *scene = CTX_data_scene(C);
enum eDynTopoWarnFlag flag = SCULPT_dynamic_topology_check(scene, ob);
More information about the Bf-blender-cvs
mailing list