[Bf-blender-cvs] [d6e2e2572af] temp-fracture-modifier-2.8: crash fix attempts for split to island function
Martin Felke
noreply at git.blender.org
Sat Dec 1 22:22:10 CET 2018
Commit: d6e2e2572afc1a3c3898e1cf4155f260cf4a3e68
Author: Martin Felke
Date: Sat Dec 1 22:21:57 2018 +0100
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rBd6e2e2572afc1a3c3898e1cf4155f260cf4a3e68
crash fix attempts for split to island function
===================================================================
M source/blender/blenkernel/BKE_fracture.h
M source/blender/blenkernel/intern/fracture.c
M source/blender/blenkernel/intern/fracture_prefractured.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_fracture.h b/source/blender/blenkernel/BKE_fracture.h
index 35d2d3fb7f4..7e6074b6f92 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -170,8 +170,8 @@ void BKE_fracture_clear_cache(struct FractureModifierData* fmd, struct Scene *sc
void BKE_fracture_meshisland_vertexgroups_do(struct FractureModifierData *fmd, struct Object *ob, struct Shard* mi);
void BKE_fracture_meshislands_pack(struct FractureModifierData *fmd, struct Object* obj, struct Main* bmain, struct Scene* scene);
-void BKE_fracture_postprocess_meshisland(struct FractureModifierData *fmd, struct Object* ob, struct Shard*mi,
- struct Mesh** temp_meshs, int count, struct Scene* scene, int frame);
+void BKE_fracture_postprocess_meshisland(struct FractureModifierData *fmd, struct Object* ob, struct Shard* mi,
+ struct Mesh** temp_meshs, int count, struct Scene* scene, int frame, struct Shard **shards);
void BKE_fracture_meshisland_normals_fix(struct FractureModifierData *fmd, struct Shard* mi, struct Mesh* orig_me);
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 71746f61b17..70e14288914 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -466,7 +466,7 @@ static void process_cells(FractureModifierData* fmd, Shard* mii, Object* ob, Sce
/* parse to raw meshisland*/
Shard *mi = parse_cell(c[i]);
- BLI_kdtree_insert(tree, count, mi->loc);
+ BLI_kdtree_insert(tree, i, mi->loc);
islands[i] = mi;
/* check whether it needs to be processed */
@@ -541,12 +541,10 @@ static void process_cells(FractureModifierData* fmd, Shard* mii, Object* ob, Sce
}
}
- BKE_fracture_postprocess_meshisland(fmd, ob, mii, temp_meshs, count, scene, frame);
+ BKE_fracture_postprocess_meshisland(fmd, ob, mii, temp_meshs, count, scene, frame, islands);
BLI_kdtree_balance(tree);
- MEM_freeN(temp_meshs);
-
/* swap old last islands and tree against new for next run */
if (fmd->shared->last_island_tree)
{
@@ -562,7 +560,7 @@ static void process_cells(FractureModifierData* fmd, Shard* mii, Object* ob, Sce
{
if (fmd->shared->last_islands[k])
{
- BLI_remlink(&fmd->shared->shards, fmd->shared->last_islands[k]);
+ //BLI_remlink(&fmd->shared->shards, fmd->shared->last_islands[k]);
BKE_fracture_mesh_island_free(fmd, fmd->shared->last_islands[k], scene);
}
}
@@ -570,6 +568,7 @@ static void process_cells(FractureModifierData* fmd, Shard* mii, Object* ob, Sce
MEM_freeN(fmd->shared->last_islands);
}
+ MEM_freeN(temp_meshs);
fmd->shared->last_islands = islands;
fmd->shared->last_islands_count = count;
}
@@ -877,8 +876,8 @@ static void intersect_mesh_by_mesh(FractureModifierData* fmd, Object* ob, Mesh*
}
}
-void BKE_fracture_postprocess_meshisland(FractureModifierData *fmd, Object* ob, Shard*mi, Mesh** temp_meshs, int count,
- Scene* scene, int frame)
+void BKE_fracture_postprocess_meshisland(FractureModifierData *fmd, Object* ob, Shard* mi, Mesh** temp_meshs, int count,
+ Scene* scene, int frame, Shard** shards)
{
int count_new = count+1;
int j = 1, i = 0;
@@ -887,23 +886,22 @@ void BKE_fracture_postprocess_meshisland(FractureModifierData *fmd, Object* ob,
if (fmd->flag & MOD_FRACTURE_USE_SPLIT_TO_ISLANDS)
{
- int diff = 1;
- for (i = 0; i < count; i++)
+ for (i = 0; i < count+1; i++)
{
if (temp_meshs[i]) {
+ int oldcount = count_new;
+ double start = PIL_check_seconds_timer();
+
BKE_fracture_split_islands(fmd, ob, temp_meshs[i], &temp_meshs, &count_new );
BKE_fracture_mesh_free(temp_meshs[i]);
temp_meshs[i] = NULL;
- }
-
- diff = count_new - (count+1);
- if (diff > 1) {
- if (temp_meshs[i+diff-1]) {
- BKE_fracture_split_islands(fmd, ob, temp_meshs[i+diff-1], &temp_meshs, &count_new );
- BKE_fracture_mesh_free(temp_meshs[i+diff-1]);
- temp_meshs[i+diff-1] = NULL;
+ if ((i < count) && shards && shards[i]) {
+ //flag as being freed, set null here ! so no other free attempt happens
+ shards[i]->mesh = NULL;
}
+
+ printf("Splitting to %d islands done, %g \n", count_new - oldcount, PIL_check_seconds_timer() - start);
}
}
}
@@ -1019,7 +1017,7 @@ static Shard* fracture_cutter_process(FractureModifierData* fmd, Object *obA, Me
temp_meshs[1] = NULL;
}
- BKE_fracture_postprocess_meshisland(fmd, obB, miB, temp_meshs, 2, scene, frame);
+ BKE_fracture_postprocess_meshisland(fmd, obB, miB, temp_meshs, 2, scene, frame, NULL);
MEM_freeN(temp_meshs);
@@ -3195,13 +3193,10 @@ void BKE_fracture_meshisland_vertexgroups_do(FractureModifierData *fmd, Object*
void BKE_fracture_split_islands(FractureModifierData *fmd, Object* ob, Mesh *me, Mesh*** temp_islands, int* count)
{
- double start;
BMesh *bm_work;
bm_work = BKE_fracture_mesh_to_bmesh(me);
- start = PIL_check_seconds_timer();
mesh_separate_loose(bm_work, fmd, ob, temp_islands, count);
- printf("Splitting to %d islands done, %g \n", *count, PIL_check_seconds_timer() - start);
}
static void do_island_index_map(FractureModifierData *fmd, Object* obj, int frame)
@@ -3466,6 +3461,18 @@ void BKE_fracture_duplis_to_shards(FractureModifierData *fmd, Object *ob, Scene
mi = BKE_fracture_mesh_island_create(me_tmp, scene, ob, frame);
fracture_meshisland_add(fmd, mi);
mi->id = dob->persistent_id[0]+1;
+
+ if (dob->particle_system) {
+ ParticleData* pa = dob->particle_system->particles + mi->id-1;
+ if (pa && pa->alive == PARS_ALIVE)
+ {
+ copy_v3_v3(mi->rigidbody->pos, pa->state.co);
+ copy_qt_qt(mi->rigidbody->orn, pa->state.rot);
+ copy_v3_v3(mi->rigidbody->lin_vel, pa->state.vel);
+ copy_v3_v3(mi->rigidbody->ang_vel, pa->state.ave);
+ }
+ }
+
//mi_tmp = MEM_reallocN(mi_tmp, sizeof(Shard*) * (j+1));
//mi_tmp[j] = mi;
//j++;
@@ -3484,10 +3491,10 @@ void BKE_fracture_duplis_to_shards(FractureModifierData *fmd, Object *ob, Scene
copy_v3_v3(mi->rigidbody->ang_vel, pa->state.ave);
if (!mi->rigidbody->shared->physics_object) {
- float size[3] = {1, 1, 1};
+ //float size[3] = {1, 1, 1};
mi->rigidbody->flag |= RBO_FLAG_NEEDS_VALIDATE;
mi->rigidbody->flag |= RBO_FLAG_NEEDS_RESHAPE;
- BKE_rigidbody_validate_sim_shard(scene->rigidbody_world, mi, ob, fmd, false, true, size);
+ //BKE_rigidbody_validate_sim_shard(scene->rigidbody_world, mi, ob, fmd, false, true, size);
}
if (mi->rigidbody->shared->physics_object) {
@@ -3500,9 +3507,6 @@ void BKE_fracture_duplis_to_shards(FractureModifierData *fmd, Object *ob, Scene
mi->rigidbody->ang_vel);
}
}
- else {
- //mi->endframe = frame - 1;
- }
}
}
}
diff --git a/source/blender/blenkernel/intern/fracture_prefractured.c b/source/blender/blenkernel/intern/fracture_prefractured.c
index 9d111972a2d..67aa21e57fe 100644
--- a/source/blender/blenkernel/intern/fracture_prefractured.c
+++ b/source/blender/blenkernel/intern/fracture_prefractured.c
@@ -155,7 +155,8 @@ static void do_initial_prefracture(FractureModifierData* fmd, Object* ob, Depsgr
mi = BKE_fracture_mesh_island_create(me_tmp, scene, ob, frame);
mi->id = 0;
- BLI_addtail(&fmd->shared->shards, mi);
+ //temporary shard, do not link up !
+ //BLI_addtail(&fmd->shared->shards, mi);
if (fmd->shared->last_islands) {
MEM_freeN(fmd->shared->last_islands);
More information about the Bf-blender-cvs
mailing list