calling obj.data.materials.clear() on an object with 2+ materials in lookdev or rendered(eevee) shading crashes Blender #67999

Closed
opened 2019-07-31 14:46:20 +02:00 by MACHIN3 · 12 comments

System Information
Operating system: Linux-4.13.10-041310-generic-x86_64-with-debian-stretch-sid 64 Bits
Graphics card: GeForce GTX 1050/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 390.67

Blender Version
Broken: version: 2.80 (sub 75), branch: master, commit date: 2019-07-29 14:47, hash: f6cb5f5449,
Also Broken: version: 2.81 (sub 0), branch: master, commit date: 2019-07-30 20:50, hash: 5359b7a033

Short description of error
Have object with 2 or more materials applied. Be in lookdev or rendered shading(using Eevee).
Use obj.data.materials.clear() in the console or from a script to remove materials and slots. Blender crashes.
I've had sb. else mention it takes more than 2 materials for him, but for me 2 are sufficient, and clearing them crashes Blender every time.

obj.data.matrials.clear()_crashes_blender_in_eevee_shading.blend

Exact steps for others to reproduce the error

  • load the blend file
  • if you aren't already in the scripting layout, enter C.active_object.data.materials.clear() in the python console and hit return, otherwise it's already typed out and you can just hit return
  • Blender should crash
**System Information** Operating system: Linux-4.13.10-041310-generic-x86_64-with-debian-stretch-sid 64 Bits Graphics card: GeForce GTX 1050/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 390.67 **Blender Version** Broken: version: 2.80 (sub 75), branch: master, commit date: 2019-07-29 14:47, hash: `f6cb5f5449`, Also Broken: version: 2.81 (sub 0), branch: master, commit date: 2019-07-30 20:50, hash: `5359b7a033` **Short description of error** Have object with 2 or more materials applied. Be in lookdev or rendered shading(using Eevee). Use `obj.data.materials.clear()` in the console or from a script to remove materials and slots. Blender crashes. I've had sb. else mention it takes more than 2 materials for him, but for me 2 are sufficient, and clearing them crashes Blender every time. [obj.data.matrials.clear()_crashes_blender_in_eevee_shading.blend](https://archive.blender.org/developer/F7639576/obj.data.matrials.clear___crashes_blender_in_eevee_shading.blend) **Exact steps for others to reproduce the error** * load the blend file * if you aren't already in the scripting layout, enter `C.active_object.data.materials.clear()` in the python console and hit return, otherwise it's already typed out and you can just hit return * Blender should crash
Author

Added subscriber: @MACHIN3

Added subscriber: @MACHIN3
MACHIN3 changed title from calling obj.data.materials.clear() on an object with 2+ materials in lookedev or rendered(eevee) shading crashes Blender to calling obj.data.materials.clear() on an object with 2+ materials in lookdev or rendered(eevee) shading crashes Blender 2019-07-31 14:46:51 +02:00

Added subscriber: @dr.sybren

Added subscriber: @dr.sybren

I can confirm this crash on current master (03be31e817). In debug mode it fails an assertion, showing that there is a difference between the number of material slots on the mesh and the object:

/usr/lib/x86_64-linux-gnu/libasan.so.4(+0x558c0) [0x7f28459b88c0]
blenderdebug(BLI_system_backtrace+0xaa) [0x55cf9cb1c9ef]
blenderdebug(DRW_mesh_batch_cache_get_surface_shaded+0x1d1) [0x55cf9defa966]
blenderdebug(DRW_cache_mesh_surface_shaded_get+0x158) [0x55cf9de7334b]
blenderdebug(DRW_cache_object_surface_material_get+0x155) [0x55cf9de620e9]
blenderdebug(EEVEE_materials_cache_populate+0xaf0) [0x55cf9ddd9350]
blenderdebug(EEVEE_cache_populate+0x20d) [0x55cf9dd9bd46]
blenderdebug(+0x449f839) [0x55cf9dd17839]
blenderdebug(DRW_draw_render_loop_ex+0x9f7) [0x55cf9dd1a038]
blenderdebug(DRW_draw_view+0x276) [0x55cf9dd1963e]
blenderdebug(+0x526b2ed) [0x55cf9eae32ed]
blenderdebug(view3d_main_region_draw+0x43) [0x55cf9eae33eb]
blenderdebug(ED_region_do_draw+0x3a6) [0x55cf9ed05d59]
blenderdebug(+0x3a3ee12) [0x55cf9d2b6e12]
blenderdebug(+0x3a3f935) [0x55cf9d2b7935]
blenderdebug(wm_draw_update+0xec) [0x55cf9d2b851f]
blenderdebug(WM_main+0x48) [0x55cf9d2ad0fc]
blenderdebug(+0x2958d97) [0x55cf9c1d0d97]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7) [0x7f283db91b97]
blenderdebug(_start+0x2a) [0x55cf9c1d042a]
BLI_assert failed: /home/sybren/workspace/blender-git/blender/source/blender/draw/intern/draw_cache_impl_mesh.c:4546, DRW_mesh_batch_cache_get_surface_shaded(), at 'gpumat_array_len == cache->mat_len'
I can confirm this crash on current master (03be31e817a21ebd658). In debug mode it fails an assertion, showing that there is a difference between the number of material slots on the mesh and the object: ``` /usr/lib/x86_64-linux-gnu/libasan.so.4(+0x558c0) [0x7f28459b88c0] blenderdebug(BLI_system_backtrace+0xaa) [0x55cf9cb1c9ef] blenderdebug(DRW_mesh_batch_cache_get_surface_shaded+0x1d1) [0x55cf9defa966] blenderdebug(DRW_cache_mesh_surface_shaded_get+0x158) [0x55cf9de7334b] blenderdebug(DRW_cache_object_surface_material_get+0x155) [0x55cf9de620e9] blenderdebug(EEVEE_materials_cache_populate+0xaf0) [0x55cf9ddd9350] blenderdebug(EEVEE_cache_populate+0x20d) [0x55cf9dd9bd46] blenderdebug(+0x449f839) [0x55cf9dd17839] blenderdebug(DRW_draw_render_loop_ex+0x9f7) [0x55cf9dd1a038] blenderdebug(DRW_draw_view+0x276) [0x55cf9dd1963e] blenderdebug(+0x526b2ed) [0x55cf9eae32ed] blenderdebug(view3d_main_region_draw+0x43) [0x55cf9eae33eb] blenderdebug(ED_region_do_draw+0x3a6) [0x55cf9ed05d59] blenderdebug(+0x3a3ee12) [0x55cf9d2b6e12] blenderdebug(+0x3a3f935) [0x55cf9d2b7935] blenderdebug(wm_draw_update+0xec) [0x55cf9d2b851f] blenderdebug(WM_main+0x48) [0x55cf9d2ad0fc] blenderdebug(+0x2958d97) [0x55cf9c1d0d97] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7) [0x7f283db91b97] blenderdebug(_start+0x2a) [0x55cf9c1d042a] BLI_assert failed: /home/sybren/workspace/blender-git/blender/source/blender/draw/intern/draw_cache_impl_mesh.c:4546, DRW_mesh_batch_cache_get_surface_shaded(), at 'gpumat_array_len == cache->mat_len' ```
Sybren A. Stüvel self-assigned this 2019-07-31 16:15:05 +02:00

This issue was referenced by 92a3995c6d

This issue was referenced by 92a3995c6d4487e5bc0735b35fbef5c34b29421a

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Author

Changed status from 'Resolved' to: 'Open'

Changed status from 'Resolved' to: 'Open'
MACHIN3 reopened this issue 2019-08-15 11:21:16 +02:00
Author

I'm opening this one again, because the issue seems to have re-appeared in cb7ead2e3b. Seems like it's - in my case at least - for 3+ Materials now, so make sure to use the cube on the right in the example blend above.

I'm opening this one again, because the issue seems to have re-appeared in `cb7ead2e3b`. Seems like it's - in my case at least - for 3+ Materials now, so make sure to use the cube on the right in the example blend above.

Added subscriber: @brecht

Added subscriber: @brecht

The root cause of the crash is that something is allowed via Python that we never do from C. The Mesh.materials.clear() function will remove all the material slots from the mesh, but it keeps the polygon material indices (mpoly->mat_nr) intact. The drawing code then uses mpoly->mat_nr to index into the material slots, which crashes because they aren't there.

The crash is resolved by passing Mesh.materials.clear(update_data=True). From C we always pass update_data=true to the underlying BKE_material_clear_id() function, as that updates the polygon material and keeps things in sync. My proposal is to remove the update_data parameter altogether, both in C and Python, and always update the polygon material indices. This would then have the same effect as removing the material slots one by one in the UI (that also removes the poly assignment). I do want to discuss this with @brecht though.

I've updated extract_tris_init() (the function that crashes) to clamp the material indices to the number of material slots, to see what would be drawn in that case. It's clear that this isn't supported by the rest of the draw code:

image.png

(left/right = before/after material removal)

The root cause of the crash is that something is allowed via Python that we never do from C. The `Mesh.materials.clear()` function will remove all the material slots from the mesh, but it keeps the polygon material indices (`mpoly->mat_nr`) intact. The drawing code then uses `mpoly->mat_nr` to index into the material slots, which crashes because they aren't there. The crash is resolved by passing `Mesh.materials.clear(update_data=True)`. From C we always pass `update_data=true` to the underlying `BKE_material_clear_id()` function, as that updates the polygon material and keeps things in sync. My proposal is to remove the `update_data` parameter altogether, both in C and Python, and always update the polygon material indices. This would then have the same effect as removing the material slots one by one in the UI (that also removes the poly assignment). I do want to discuss this with @brecht though. I've updated `extract_tris_init()` (the function that crashes) to clamp the material indices to the number of material slots, to see what would be drawn in that case. It's clear that this isn't supported by the rest of the draw code: ![image.png](https://archive.blender.org/developer/F7667048/image.png) (left/right = before/after material removal)
Author

Thanks for looking into this! I've also occasionally seen those vanishing faces when it didn't crash. Also, wasn't aware of the update_data argument, either.

Thanks for looking into this! I've also occasionally seen those vanishing faces when it didn't crash. Also, wasn't aware of the update_data argument, either.

This issue was referenced by c70f975d5c

This issue was referenced by c70f975d5c3b961e0c77eba3a35c8a892f39214d

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
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#67999
No description provided.