Particle system children sometimes not generated on reload #43427

Closed
opened 2015-01-27 10:24:45 +01:00 by Lukas Tönne · 6 comments
Member

Hair systems with heavy child calculation doesn't show up after reload (somewhat randomly), until explicitly reloading texture images.
This happens regularly with the victor character of the Gooseberry project (file is too heavy to upload here).

The reason seems to be that the particle system expects image textures to lazy-load image buffers on request during the creation of child hair paths:
https://developer.blender.org/diffusion/B/browse/master/source/blender/blenkernel/intern/particle.c$3413
https://developer.blender.org/diffusion/B/browse/master/source/blender/render/intern/source/imagetexture.c$126

However, this ibuf acquisition is prevented by the R.r.scemode & R_NO_IMAGE_LOAD flag. This flag is used to prevent the icon render job from loading large texture files. It is only set by that job's start method:
https://developer.blender.org/diffusion/B/browse/master/source/blender/editors/render/render_preview.c$721

What appears to be happening is a kind of thread race between icon render and scene update jobs after loading a blend file: The first hair system usually loads fine, because it manages to acquire ibufs before the icon job kicks in. Then however, if the 1st psys takes some time to create paths, the icon render sets this scene flag, thus preventing any later psys eval from lazy-loading it's textures. The only way to then get correct hair paths is to force image loading some other way (open in image editor, force reload, etc) and kick the psys.

Effectively the icon rendering totally disables all lazy ibuf loading! It makes sense to not load large textures during icon rendering (this was the reason for introduction of the flag), but because it uses a persistent scene flag for this it interferes with all other users of textures ... I suppose the flag should be some kind of localized job context setting, rather than abusing the scene's RenderData flags for the purpose.

Hair systems with heavy child calculation doesn't show up after reload (somewhat randomly), until explicitly reloading texture images. This happens regularly with the victor character of the Gooseberry project (file is too heavy to upload here). The reason seems to be that the particle system expects image textures to lazy-load image buffers on request during the creation of child hair paths: https://developer.blender.org/diffusion/B/browse/master/source/blender/blenkernel/intern/particle.c$3413 https://developer.blender.org/diffusion/B/browse/master/source/blender/render/intern/source/imagetexture.c$126 However, this ibuf acquisition is prevented by the `R.r.scemode & R_NO_IMAGE_LOAD` flag. This flag is used to prevent the __icon render job__ from loading large texture files. It is *only* set by that job's `start` method: https://developer.blender.org/diffusion/B/browse/master/source/blender/editors/render/render_preview.c$721 What appears to be happening is a kind of thread race between icon render and scene update jobs after loading a blend file: The first hair system usually loads fine, because it manages to acquire ibufs before the icon job kicks in. Then however, if the 1st psys takes some time to create paths, the icon render sets this scene flag, thus preventing any later psys eval from lazy-loading it's textures. The only way to then get correct hair paths is to force image loading some other way (open in image editor, force reload, etc) and kick the psys. Effectively the icon rendering totally disables all lazy ibuf loading! It makes sense to not load large textures during icon rendering (this was the reason for introduction of the flag), but because it uses a persistent scene flag for this it interferes with all other users of textures ... I suppose the flag should be some kind of localized job context setting, rather than abusing the scene's `RenderData` flags for the purpose.
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Lukas Tönne self-assigned this 2015-01-27 10:24:45 +01:00
Author
Member

Added subscriber: @Sergey

Added subscriber: @Sergey
Author
Member

@Sergey Here is a bad tentative fix for the issue:

diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 94fd30d..476aec8 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -68,6 +68,7 @@
 - include "BKE_effect.h"
 - include "BKE_global.h"
 #include "BKE_group.h"
+#include "BKE_image.h"
 - include "BKE_main.h"
 - include "BKE_lattice.h"
 
@@ -2341,6 +2342,19 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd
        totchild = ctx.totchild;
        totparent = ctx.totparent;
        
+       {
+               MTex *mtex;
+               int a;
+               
+               for (a = 0; a < MAX_MTEX; a++) {
+                       mtex = sim->psys->part->mtex[a];
+                       if (mtex && mtex->tex && mtex->tex->type == TEX_IMAGE && mtex->tex->ima) {
+                               struct ImBuf *ibuf = BKE_image_pool_acquire_ibuf(mtex->tex->ima, &mtex->tex->iuser, NULL);
+                               BKE_image_pool_release_ibuf(mtex->tex->ima, ibuf, NULL);
+                       }
+               }
+       }
+       
        if (editupdate && sim->psys->childcache && totchild == sim->psys->totchildcache) {
                ; /* just overwrite the existing cache */
        }

Certainly this is not the way to do it, just shows how forcibly loading ibufs avoids the issue ...

@Sergey Here is a **bad** tentative fix for the issue: ``` diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 94fd30d..476aec8 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -68,6 +68,7 @@ - include "BKE_effect.h" - include "BKE_global.h" #include "BKE_group.h" +#include "BKE_image.h" - include "BKE_main.h" - include "BKE_lattice.h" @@ -2341,6 +2342,19 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd totchild = ctx.totchild; totparent = ctx.totparent; + { + MTex *mtex; + int a; + + for (a = 0; a < MAX_MTEX; a++) { + mtex = sim->psys->part->mtex[a]; + if (mtex && mtex->tex && mtex->tex->type == TEX_IMAGE && mtex->tex->ima) { + struct ImBuf *ibuf = BKE_image_pool_acquire_ibuf(mtex->tex->ima, &mtex->tex->iuser, NULL); + BKE_image_pool_release_ibuf(mtex->tex->ima, ibuf, NULL); + } + } + } + if (editupdate && sim->psys->childcache && totchild == sim->psys->totchildcache) { ; /* just overwrite the existing cache */ } ``` Certainly this is not the way to do it, just shows how forcibly loading ibufs avoids the issue ...

This issue was referenced by d9c77a490c

This issue was referenced by d9c77a490cc5ed9dde396022cd6800e78057cc2b

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Closed by commit d9c77a490c.

Closed by commit d9c77a490c.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#43427
No description provided.