Crash accessing python gpu module in background mode. #59773
Labels
No Label
Interest
Animation & Rigging
Interest
Blender Cloud
Interest
Collada
Interest
Core
Interest
Documentation
Interest
Eevee & Viewport
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
Import and Export
Interest
Modeling
Interest
Modifiers
Interest
Nodes & Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds, Tests & Devices
Interest
Python API
Interest
Rendering & Cycles
Interest
Sculpt, Paint & Texture
Interest
Translations
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Meta
Good First Issue
Meta
Papercut
Module
Add-ons (BF-Blender)
Module
Add-ons (Community)
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
5 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-addons#59773
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Just run e.g.
path/to/blender -b --python-expr "import bpy; bpy.ops.wm.addon_enable(module='space_view3d_math_vis')"
(or even enable that add-on in userpref and try to start Blender 2.8 in background mode, I guess).There are several level to that issue (and several ways to fix it, too, but that’s not my area of code so will live it to the experts ;) ):
math_vis should absolutely not do what it does in first lines of its
draw.py
, callinggpu.shader.from_builtin()
at module level, i.e. during init… tsst. This can be solved in many ways (not even sure it's worth storing in py those shaders? afaik this is cached internally anyway?), as long as it does not do any call outside of functions. Lazy init ftw!Think gpu module code (
gpu_py_shader.c
and friends) should ensure it has a valid OpenGL context blabla too? Unless add-ons are expected to do those checks themselves before using it?Added subscriber: @mont29
blender/blender#59929 was marked as duplicate of this issue
blender/blender#59787 was marked as duplicate of this issue
Added subscriber: @fclem
@ideasman42 assigned to you because math_vis is your add-on, and think you were involved in gpu api work? maybe @fclem or other #opengl_gfx guys are interested too…
math_vis thingy is currently blocking i18n update process, will have to work around that unless it’s fixed soonish. ;)
Added subscriber: @JacquesLucke
@JacquesLucke object_scatter has exact same issue btw.
Added subscriber: @AmirShehata
Added subscriber: @mano-wii
I think it would be best if the addons chek out these errors themselves.
But for this, instead of crash it would be better to raise an error message:
P877: patch for #59773
animation nodes addon also triggers this crash
Also tested the patch and it works.
IMHO, first thing first, addons should not call those gpu functions at module level, that means they get called during first eval of the code (first import). This is bad practice in general, unless absolutely mandatory we avoid that kind of extra processing since it makes Blender loading slower.
In fact, not even sure why those global storage of
gpu.shader.from_builtin()
results are needed at all, afaict those are already cached internally, so call itself should be cheap after first time? But if they are needed, then a lazy init solution should be used instead (like using a dummy class with accessors, or so).I can fix the Object Scatter and Math Vis addon in that regard (maybe also the UV Export addon).
However, it might take me a couple of days because I'm on vacation and have to work on my Bachelor thesis..
Feel free to assign the addon updates to me.
Will those addons never work in background mode, or is it just the wrong time to initialize? (I'm especially talking about the png export of the Export UV addon, which uses opengl to render the image)
Do you recommend adding an assert or raise error if the gpu module is imported at module level?
@JacquesLucke Think most of the time they won't work in background mode, no, which would solve most of the crashes already. For cases where OGL context is used in background mode, indeed that patch sounds OK to me, and it's add-on responsibility to handle the issue properly. And no rush here, it can wait for you to get back from holidays! ;)
@mano-wii importing gpu module is fine, what is not fine is calling some of its functions at global level.
Added subscribers: @MaTcHo0o, @brecht
This issue was referenced by blender/blender@945007b32e
Changed status from 'Open' to: 'Resolved'