Page MenuHome

Hair: changing children related settings not updating in particle editmode (also crash when deleting a particle, then undo)
Open, Confirmed, MediumPublic

Description

System Information
Operating system: Windows-10-10.0.17134 64 Bits
Graphics card: GeForce GTX 1050/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 388.73

Blender Version
Broken: version: 2.80 (sub 75), branch: master, commit date: 2019-07-29 14:47, hash: rBf6cb5f54494e
Worked: (optional)

Short description of error
Hair particle system children won't update/refresh in viewport when editing their parameters or deleting a strand and blender crashes after deleting a strand and undoing the action.

Exact steps for others to reproduce the error

  • Add a hair particle system on any object and enable children (Simple)
  • Go to particle edit mode and enable children from right panel (N) ->Tool -> Options -> Viewport Display
  • Choose point select mode
  • Try changing any parameters related to the particle system's children or delete a particle point and will see no change on the viewport part (update occurs only after moving point or using settings like "Comb")

Or :

  • Select any particle point, delete it with Del button, undo (Ctrl-Z) and Blender will crash

Event Timeline

Philipp Oeser (lichtwerk) lowered the priority of this task from Needs Triage by Developer to Confirmed, Medium.Aug 21 2019, 5:22 PM

Can confirm

Blender, you keep confusing me.

Did a little digging, and this seems to work:

1
2
3diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c
4index cadd66d564a..d28f5105186 100644
5--- a/source/blender/makesrna/intern/rna_particle.c
6+++ b/source/blender/makesrna/intern/rna_particle.c
7@@ -615,7 +615,7 @@ static void rna_ParticleSystem_mcol_on_emitter(ParticleSystem *particlesystem,
8 }
9 }
10
11-static void particle_recalc(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr, short flag)
12+static void particle_recalc(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr, short flag)
13 {
14 if (ptr->type == &RNA_ParticleSystem) {
15 Object *ob = ptr->id.data;
16@@ -626,6 +626,17 @@ static void particle_recalc(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRN
17 DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
18 }
19 else {
20+ /* This seems to be additionally needed for particle edit mode. */
21+ ParticleSettings *part = ptr->data;
22+ for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
23+ for (ParticleSystem *psys = ob->particlesystem.first; psys; psys = psys->next) {
24+ if (psys->part == part) {
25+ BKE_particle_batch_cache_dirty_tag(psys, BKE_PARTICLE_BATCH_DIRTY_ALL);
26+ }
27+ }
28+ }
29+
30+ /* this is enough for object mode */
31 DEG_id_tag_update(ptr->id.data, ID_RECALC_GEOMETRY | flag);
32 }
33

What is still unclear to me is this:
Even without this, I can see this being done in objectmode:

graph_id_tag_update: id=PAParticleSettings flags=GEOMETRY, PSYS_CHILD source=USER_EDIT
graph_id_tag_update: id=PAParticleSettings flags=GEOMETRY, PSYS_CHILD source=USER_EDIT
graph_id_tag_update: id=PAParticleSettings flags=COPY_ON_WRITE source=USER_EDIT
graph_id_tag_update: id=PAParticleSettings flags=COPY_ON_WRITE source=USER_EDIT
[SCScene :: View Layer]: Operation is entry point for update: PARTICLE_SETTINGS_INIT()
[SCScene :: View Layer]: Operation is entry point for update: PARTICLE_SETTINGS_RESET()
[SCScene :: View Layer]: Operation is entry point for update: PARTICLE_SETTINGS_EVAL()
[SCScene :: View Layer]: Operation is entry point for update: COPY_ON_WRITE()
[SCScene :: View Layer]: Accumulated recalc bits for OBCube: 2
[SCScene :: View Layer]: Accumulated recalc bits for PAParticleSettings: 8226
[SCScene :: View Layer]: deg_evaluate_copy_on_write on PAParticleSettings (0x7f7173efd008)
[SCScene :: View Layer]: BKE_particle_settings_eval_reset on PAParticleSettings (0x7f7173efd008)
[SCScene :: View Layer]: BKE_particle_system_eval_init on OBCube (0x7f7173f92208)
[SCScene :: View Layer]: BKE_object_eval_ptcache_reset on OBCube (0x7f7173f92208)
[SCScene :: View Layer]: BKE_object_eval_uber_data on OBCube (0x7f7173f92208)
[SCScene :: View Layer]: BKE_object_handle_data_update on OBCube (0x7f7173f92208)
Depsgraph updated in 0.011957 seconds.

And this is in particle editmode:

graph_id_tag_update: id=PAParticleSettings flags=GEOMETRY, PSYS_CHILD source=USER_EDIT
graph_id_tag_update: id=PAParticleSettings flags=GEOMETRY, PSYS_CHILD source=USER_EDIT
graph_id_tag_update: id=PAParticleSettings flags=COPY_ON_WRITE source=USER_EDIT
graph_id_tag_update: id=PAParticleSettings flags=COPY_ON_WRITE source=USER_EDIT
[SCScene :: View Layer]: Operation is entry point for update: PARTICLE_SETTINGS_INIT()
[SCScene :: View Layer]: Operation is entry point for update: PARTICLE_SETTINGS_RESET()
[SCScene :: View Layer]: Operation is entry point for update: PARTICLE_SETTINGS_EVAL()
[SCScene :: View Layer]: Operation is entry point for update: COPY_ON_WRITE()
[SCScene :: View Layer]: Accumulated recalc bits for OBCube: 2
[SCScene :: View Layer]: Accumulated recalc bits for PAParticleSettings: 8226
[SCScene :: View Layer]: deg_evaluate_copy_on_write on PAParticleSettings (0x7f7173efd008)
[SCScene :: View Layer]: BKE_particle_settings_eval_reset on PAParticleSettings (0x7f7173efd008)
[SCScene :: View Layer]: BKE_particle_system_eval_init on OBCube (0x7f7173f92208)
[SCScene :: View Layer]: BKE_object_eval_ptcache_reset on OBCube (0x7f7173f92208)
[SCScene :: View Layer]: BKE_object_eval_uber_data on OBCube (0x7f7173f92208)
[SCScene :: View Layer]: BKE_object_handle_data_update on OBCube (0x7f7173f92208)
Depsgraph updated in 0.012030 seconds.

Seems to do the same stuff, no?
Also BKE_particle_batch_cache_dirty_tag is called for both... (as part of BKE_object_eval_uber_data)
But edits just dont seem to come over to the correct ParticleSystems...
(this can go wrong the other way around as well: change children length in PE mode, then in OB mode --> go back to PE mode --> out of sync...)
Anyways, this all seem to be resolved by above patch (it seems)


Same is true for EffectorWeights btw. (changing those in particle editmode has no influence at all).
Here I am not even sure if these should be displayed in PE mode (2.79 also didnt do this), and doing the correct update in rna_EffectorWeight_update might be tricky...


This all being said, there might be a better way to do this, or this might not be look at at all (since new particles and hair are already on the way...)

This is the backtracke for deleting a whole particle, then Undo (cannot reproduce an Undo crash if I only delete a particle key...)
There, some ParticleCacheKey is broken...

1   copy_v3_v3                                                                                                                                                                                                math_vector_inline.c 63   0x22f5150 
2   offset_child                                                                                                                                                                                              particle.c           2196 0x22fb9be 
3   psys_thread_create_path                                                                                                                                                                                   particle.c           2642 0x22fd2cd 
4   exec_child_path_cache                                                                                                                                                                                     particle.c           2752 0x22fd83f 
5   BLI_task_pool_work_and_wait                                                                                                                                                                               task.c               939  0x24e2146 
6   psys_cache_child_paths                                                                                                                                                                                    particle.c           2814 0x22fdaff 
7   psys_update_path_cache                                                                                                                                                                                    particle_system.c    3245 0x231474a 
8   hair_step                                                                                                                                                                                                 particle_system.c    3541 0x231570a 
9   particle_system_update                                                                                                                                                                                    particle_system.c    4687 0x2318e71 
10  deformVerts                                                                                                                                                                                               MOD_particlesystem.c 212  0x2dd2ab5 
11  modwrap_deformVerts                                                                                                                                                                                       modifier.c           960  0x22affab 
12  mesh_calc_modifiers                                                                                                                                                                                       DerivedMesh.c        1221 0x24022a8 
13  mesh_build_data                                                                                                                                                                                           DerivedMesh.c        2056 0x240508f 
14  makeDerivedMesh                                                                                                                                                                                           DerivedMesh.c        2185 0x240556d 
15  BKE_object_handle_data_update                                                                                                                                                                             object_update.c      186  0x22ed7ee 
16  BKE_object_eval_uber_data                                                                                                                                                                                 object_update.c      354  0x22ee0b2
Philipp Oeser (lichtwerk) renamed this task from Hair particle system refresh and crash problem to Hair: changing children related settings not updating in particle editmode (also crash when deleting a particle, then undo).Sep 4 2019, 11:39 AM

@Philipp Oeser (lichtwerk)
Ah me. I can't connect the dot(s) from what I'm seeing to your August 21 musings.
Generally, what I'm seeing is AddressSanitizer catching a heap-buffer-overflow at particle.c:2549 in psys_thread_create_path. Just before falling into the abyss:

[2548]    /* get the parent path */
[2549]    key[0] = pcache[cpa->parent];

where:

(gdb) p *cpa
$50 = {
  num = -1, 
  parent = 1, 
  pa = {0, 0, 0, 0}, 
  w = {0, 0, 0, 0}, 
  fuv = {-0.0304894447, 0.411474943, 0.795426488, 0}, 
  foffset = 0, 
  rt = 0
}

But:

(gdb) p pcache[1]
$51 = (ParticleCacheKey *) 0x0

which offends the AddressSanitizer Gods.

A few lines up, at line 2549 where PTCacheEdit *edit is initialized, and from that pcache,
there seems to be a predicator of the buffer overflow in the bowels of *edit, in that the total point count exceeds the total cache count by one:

(gdb) p *edit
$52 = {
  flags = 0, 
  points = 0x604000306e98, 
  pid = {
    next = 0x0, 
    prev = 0x0, 
    scene = 0x0, 
    ob = 0x61b00013a988, 
    calldata = 0x617000142e88, 
    type = 1, 
    file_type = 0, 
    stack_index = 4294967295, 
    flag = 0, 
    default_step = 1, 
    max_step = 20, 
    data_types = 7, 
    info_types = 64, 
    write_point = 0x555576f57ea7 <ptcache_particle_write>, 
    read_point = 0x555576f593f7 <ptcache_particle_read>, 
    interpolate_point = 0x555576f5ac18 <ptcache_particle_interpolate>, 
    write_stream = 0x0, 
    read_stream = 0x0, 
    write_openvdb_stream = 0x0, 
    read_openvdb_stream = 0x0, 
    write_extra_data = 0x0, 
    read_extra_data = 0x0, 
    interpolate_extra_data = 0x0, 
    totpoint = 0x555576f5c0b4 <ptcache_particle_totpoint>, 
    error = 0x555576f5c14a <ptcache_particle_error>, 
    totwrite = 0x555576f5c159 <ptcache_particle_totwrite>, 
    write_header = 0x555576f565fb <ptcache_basic_header_write>, 
    read_header = 0x555576f5647e <ptcache_basic_header_read>, 
    cache = 0x61a0001bc088, 
    cache_ptr = 0x6170001430d0, 
    ptcaches = 0x6170001430d8
  }, 
  psys = 0x617000142e88, 
  psys_eval = 0x0, 
  psmd = 0x60f00007bd38, 
  psmd_eval = 0x0, 
  emitter_field = 0x60300027c678, 
  emitter_cosnos = 0x62900014a208, 
  mirror_cache = 0x0, 
  pathcache = 0x602000287178, 
  pathcachebufs = {
    first = 0x603000489708, 
    last = 0x603000489708
  }, 
  totpoint = 2,      /* totpoint and totcached are off by one... */ 
  totframes = 0, 
  totcached = 1, 
  edited = 0, 
  sel_col = "\377\377\377", 
  nosel_col = "\000\000"
}

psys_thread_create_path() is a busy boy, being called once for each child particle in a head of hair. In the example blend file I'm debugging with (hair_bug.blend), there are four child hair particles, so four threads run: two for parent hair zero, and two for parent hair one. ChildParticle *cpa is set up by the caller, and its parent index reflects this relationship. In this simple setting, two threads will index a parent that isn't in the cache, and stuff hits the fan.

So the obvious thing is out-of-sync structures, and I surmise that your August 21 musings on dependency graphs stems from this out-of-sync-ness, which I trust you've seen in one form or another. I haven't confirmed these guesses, because it is getting late, there are dogs to walk, and tomorrow I am with clients. Ah me.

Blend file and other artifacts attached, which may be useful. Take care.


hair_bug.blend


**system-info.txt


address_sanitizer.txt

Debugger command line, to get dependency graph dumps and single-thread as much as possible.

(gdb) show args
Argument list to give program being debugged when it is started is "--threads 1 --debug-depsgraph-no-threads --debug-depsgraph /media/render/gosgood/twoeight/hair_bug.blend ".

@Philipp Oeser (lichtwerk)
For what it is worth, I applied D5912 & D5914 here - no longer seeing the buffer overwrite or total point count / total cache count disagreement. These look like a go. Gave me useful insights as well; thank you for that. Very much appreciate your work in this dusty old particle code. Thank you for that as well.