Blender crashes when reading to bgl.Buffer / gpu.types.Buffer #91828
Labels
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
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#91828
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?
System Information
Operating system: macOS Big Sur (11.2.1)
Graphics card: Intel Iris Plus Graphics 1536 MB
Blender Version
Broken: 2.83+
Worked: Unknown if this ever worked
Short description of error
I use the "template" option of bgl.Buffer to read pixel data from an OpenGL texture to a numpy array in a fast way. To get a maximum speed, I want to read in RGB mode instead of RGBA mode because that reduces the amount of data to handle in the array. However, Blender crashes with a
Segmentation fault: 11
when trying to read from an OpenGL texture to a bgl.Buffer in RGB mode instead of RGBA mode. The following crash log is generated:The same thing happens, if I use the new GPU module API (gpu.types.Buffer etc.).
Exact steps for others to reproduce the error
Open Blender, enter the following code in the Script window and execute the script. It may be that you have to run the script two or three times until Blender crashes. If you change the
IMAGE_COLORMODE = bgl.GL_RGB
toIMAGE_COLORMODE = bgl.GL_RGBA
you will see that everything works fine without crash.Added subscriber: @regcs
Added subscribers: @GottfriedHofmann, @fclem, @brecht, @ideasman42, @mano-wii
Removed subscribers: @ideasman42, @brecht, @fclem, @GottfriedHofmann
Changed status from 'Needs Triage' to: 'Needs User Info'
bgl
is a module that is at the end of its life.Depending on the problem, we no longer maintain it.
The replacement is the
gpu
module.You are working with a python wrapper from a low level C API (OpenGL).
bgl
has few safe guards and the problem is probably not in Blender.I suspect the problem is with the calculated buffer size.
Although it's
RGB
, the driver might calculate pads that are added to each pixel and thus force the user to calculate a buffer as if it had 4 channels.It would be necessary to investigate in more detail. But I'm pretty sure what's happening is a misuse of OpenGL.
If you can replicate the same problem using the
gpu
module, we'll take a closer look.Thanks for your response. I don't understand why you consider this a misuse of OpenGL, but if it is, then the same thing happens with the new
gpu
module as I mentioned above. Please run the following modified version in Blender 3.0 to see the crash happen with thegpu
module:If you use
IMAGE_COLORMODE = "RGB"
it crashes, if you useIMAGE_COLORMODE = "RGBA"
it does not. Please note that based on this string definition, this code snipped passes a3
or a4
to the channel parameters in both the numpy array definition and thegpu.types.GPUFrameBuffer.read_color()
method.Thanks for the code.
I tested it and had no problems.
This indicates that the problem may be with your installed graphics driver.
I also edited the code to see if there's anything relating to the pad that I mentioned before:
But everything returned according to the size calculated by channels. So that apparently wasn't the problem.
Can you test this script as well and report what appears on the console?
Also, although I'm not sure if this option works on Mac, could you try running blender with the
--debug-gpu
option? After replicating the crash, we will probably have more information about the problem.For best performance just use RGBA, it's natively stored that way and converting to and from RGB has a cost.
The reason this fails is because
GL_UNPACK_ALIGNMENT
is set to 4 by default in OpenGL, which means rows must be aligned to 4 bytes.Added subscriber: @brecht
Thanks, @mano-wii for spending time on that. The code you delivered does not crash on my machine, but it also uses a 12x12 image instead of the 819x455 I chose before. Indeed, if I chose row sizes that are divisible by 4 my code does not crash either. So, what Brecht says seems to be the right thing.
@brecht I wanted to use RGB data instead of RGBA data because I need to reduce the amount of data in my script. The images I handle with the script are send via an interprocess communication to another app and the latency is too large for the image sizes I target (2k to 4k). skipping the (not required) alpha channel reduces the data and the latency a lot.
Is there any way I can manipulate the
GL_UNPACK_ALIGNMENT
with the newgpu
module (I would rather choose not to manually add zero padding to the pixel data to fill the rows)?Edit: @brecht Just tested the speed of reading RGB and RGBA data for a 4096x4096 image - reading RGB to the numpy array via the above method is ~30% faster than reading RGBA. That is in contradiction to your statement about the performance. I guess, the computation cost required to copy a large amount of data is relevant here.
Edit 2: Yes, it is indeed dependent on the image / buffer size. For smaller images, reading RGBA is faster than reading in RGB.
From what I can see in the code,
GL_UNPACK_ALIGNMENT
is set to1
by default in Blender.https://developer.blender.org/diffusion/B/browse/master/source/blender/gpu/opengl/gl_state.cc$54
Does this not work for some OS?
It would be nice if this value were checked and tested on different hardware.
@mano-wii. Actually in this case I think it's
GL_PACK_ALIGNMENT
since it's reading the texture back. I guess we can set that to 1 without causing problems.This issue was referenced by
bdc66c9569
Yes, @brecht is right. Just verified that by setting the
GL_PACK_ALIGNMENT
to 1 with my old bgl code manually and the crash is gone.Edit: Thanks for the commit, @mano-wii.
Still under review, but I don't think it will take long to land on master ;)
Yeah, not a lot to review this time. ^^
By the way, will this also make it's way into 2.93 LTS as a bug fix?
Changed status from 'Needs User Info' to: 'Resolved'
Well, I don't see a problem in backporting, but for LTS it was decided to backport only critical issues.
Does this issue qualify as being critical?
The 3.0 release is getting close (December).
And you can work around the problem by using the bgl module in 2.93.
Yeah, sure I can work around it in LTS with the bgl. I was just curious if that will be backported or not, since I don’t yet fully understood what the usual workflow with bug fixes is. Like, who decides if a bug fix like this is considered critical or not. Or if anything that leads to crashes (like this reported thing here) is automatically backported.