use-after-free crash after setting scene's render.engine inside custom render engine context #88404

Open
opened 2021-05-19 17:40:55 +02:00 by mike w. · 4 comments

System Information
Operating system: Ubuntu 20.04.2LTS

Blender Version
Broken: 2.93.0 Beta, branch: master, commit date: 2021-05-19 10:14, hash: a294670bac, type: release
Also Broken: 0efb627bbd

Short description of error
Blender crashes when setting some scene's render.engine property inside __init__ or the view_update context of a custom render engine to a different one than the custom engine.

T88404_asan_report.txt
Code to reproduce the error

import bpy
import bgl

class CustomRenderEngine(bpy.types.RenderEngine):
    bl_idname = "CUSTOM"
    bl_label = "Custom"
    bl_use_preview = True
    
    def __init__(self):
        return
        scene = bpy.data.scenes.new("foo")
        scene.render.engine = "CYCLES"
        bpy.data.scenes.remove(scene)

    def __del__(self):
        pass

    def view_update(self, context, depsgraph):
        scene = bpy.data.scenes.new("foo")
        scene.render.engine = "CYCLES"
        bpy.data.scenes.remove(scene)

    def view_draw(self, context, depsgraph):
        pass

def get_panels():
    exclude_panels = {
        'VIEWLAYER_PT_filter',
        'VIEWLAYER_PT_layer_passes',
    }

    panels = []
    for panel in bpy.types.Panel.__subclasses__():
        if hasattr(panel, 'COMPAT_ENGINES') and 'BLENDER_RENDER' in panel.COMPAT_ENGINES:
            if panel.__name__ not in exclude_panels:
                panels.append(panel)

    return panels


def register():
    bpy.utils.register_class(CustomRenderEngine)

    for panel in get_panels():
        panel.COMPAT_ENGINES.add('CUSTOM')


def unregister():
    bpy.utils.unregister_class(CustomRenderEngine)

    for panel in get_panels():
        if 'CUSTOM' in panel.COMPAT_ENGINES:
            panel.COMPAT_ENGINES.remove('CUSTOM')

if __name__ == "__main__":
    register()

Exact steps for others to reproduce the error

  1. Copy code from above into a new script file inside of Blender
  2. Run the script
  3. Select "Custom" as Render Engine inside Render Properties
  4. Select "Material Preview" as display method in the viewport.

crash.blend

Crash log:

# Blender 2.93.0, Commit date: 2021-05-19 10:14, Hash a294670bacb1
Engine 'CUSTOM' not available for scene 'Scene' (an add-on may need to be installed or enabled)  # Error
bpy.ops.text.run_script()  # Operator

# backtrace
./blender(BLI_system_backtrace+0x20) [0xa63c950]
./blender() [0xf6082a]
/lib/x86_64-linux-gnu/libc.so.6(+0x46210) [0x7f7ce17be210]
./blender(GPU_framebuffer_blit+0x2f) [0x8664faf]
./blender() [0x1485fc3]
./blender() [0x14597fe]
./blender(DRW_draw_render_loop_ex+0x242) [0x1459a72]
./blender(view3d_main_region_draw+0x8f) [0x1d3570f]
./blender(ED_region_do_draw+0x851) [0x189c771]
./blender(wm_draw_update+0x52e) [0x130cc9e]
./blender(WM_main+0x30) [0x130aa20]
./blender(main+0x319) [0xe881c9]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x7f7ce179f0b3]
./blender() [0xf5d1bc]

# Python backtrace
**System Information** Operating system: Ubuntu 20.04.2LTS **Blender Version** Broken: 2.93.0 Beta, branch: master, commit date: 2021-05-19 10:14, hash: a294670bacb1, type: release Also Broken: 0efb627bbd3ac3e53afb95591ae4e244bd1f8af4 **Short description of error** Blender crashes when setting some scene's render.engine property inside `__init__` or the `view_update` context of a custom render engine to a different one than the custom engine. [T88404_asan_report.txt](https://archive.blender.org/developer/F10165484/T88404_asan_report.txt) **Code to reproduce the error** ``` import bpy import bgl class CustomRenderEngine(bpy.types.RenderEngine): bl_idname = "CUSTOM" bl_label = "Custom" bl_use_preview = True def __init__(self): return scene = bpy.data.scenes.new("foo") scene.render.engine = "CYCLES" bpy.data.scenes.remove(scene) def __del__(self): pass def view_update(self, context, depsgraph): scene = bpy.data.scenes.new("foo") scene.render.engine = "CYCLES" bpy.data.scenes.remove(scene) def view_draw(self, context, depsgraph): pass def get_panels(): exclude_panels = { 'VIEWLAYER_PT_filter', 'VIEWLAYER_PT_layer_passes', } panels = [] for panel in bpy.types.Panel.__subclasses__(): if hasattr(panel, 'COMPAT_ENGINES') and 'BLENDER_RENDER' in panel.COMPAT_ENGINES: if panel.__name__ not in exclude_panels: panels.append(panel) return panels def register(): bpy.utils.register_class(CustomRenderEngine) for panel in get_panels(): panel.COMPAT_ENGINES.add('CUSTOM') def unregister(): bpy.utils.unregister_class(CustomRenderEngine) for panel in get_panels(): if 'CUSTOM' in panel.COMPAT_ENGINES: panel.COMPAT_ENGINES.remove('CUSTOM') if __name__ == "__main__": register() ``` **Exact steps for others to reproduce the error** 1) Copy code from above into a new script file inside of Blender 2) Run the script 3) Select "Custom" as Render Engine inside Render Properties 4) Select "Material Preview" as display method in the viewport. [crash.blend](https://archive.blender.org/developer/F10127097/crash.blend) Crash log: ``` # Blender 2.93.0, Commit date: 2021-05-19 10:14, Hash a294670bacb1 Engine 'CUSTOM' not available for scene 'Scene' (an add-on may need to be installed or enabled) # Error bpy.ops.text.run_script() # Operator # backtrace ./blender(BLI_system_backtrace+0x20) [0xa63c950] ./blender() [0xf6082a] /lib/x86_64-linux-gnu/libc.so.6(+0x46210) [0x7f7ce17be210] ./blender(GPU_framebuffer_blit+0x2f) [0x8664faf] ./blender() [0x1485fc3] ./blender() [0x14597fe] ./blender(DRW_draw_render_loop_ex+0x242) [0x1459a72] ./blender(view3d_main_region_draw+0x8f) [0x1d3570f] ./blender(ED_region_do_draw+0x851) [0x189c771] ./blender(wm_draw_update+0x52e) [0x130cc9e] ./blender(WM_main+0x30) [0x130aa20] ./blender(main+0x319) [0xe881c9] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x7f7ce179f0b3] ./blender() [0xf5d1bc] # Python backtrace ```
Author

Added subscriber: @mikewazowski11

Added subscriber: @mikewazowski11

Added subscriber: @timodriaan

Added subscriber: @timodriaan
Ankit Meel changed title from Crash after setting scene's render.engine inside custom render engine context to use-after-free crash after setting scene's render.engine inside custom render engine context 2021-06-10 12:09:17 +02:00
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Added subscriber: @ankitm

Added subscriber: @ankitm
Philipp Oeser removed the
Interest
EEVEE & Viewport
label 2023-02-09 15:13:39 +01:00
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#88404
No description provided.