Maniphest T94736

Crash when modifying strength of world environment texture
Closed, Resolved

Assigned To
Michael Jones (michael_jones)
Authored By
Leonard Göttert (Leonard)
Jan 8 2022, 10:59 AM
Tags
  • BF Blender
  • Render & Cycles
Subscribers
Aled Brown (Gelert)
Jesse Yurkovich (deadpin)
Leonard Göttert (Leonard)
Michael (michael64)
Michael Jones (michael_jones)
Wouter Stomp (wouterstomp)

Description

System Information
Operating system: macOS-12.1-arm64-arm-64bit 64 Bits
Graphics card: Apple M1 Pro Apple 4.1 Metal - 76.3

Blender Version
Broken: version: 3.1.0 Alpha, branch: master, commit date: 2022-01-07 23:28, hash: rB741ed5fcd2e2

Short description of error
When viewing a scene using Viewport Shading with Cycles on Metal, Blender crashes when playing with the Strength value of the World Background Surface.

Exact steps for others to reproduce the error

  • Open attached .blend file. It just contains a cube and an environment texture on the world background surface.

  • Go into viewport shading mode.
  • Modify the strength value. The crash happens both using click-dragging as well as repeatedly entering values numerically. It does not always crash immediately, but for me it always crashes within a couple of seconds.

Revisions and Commits

rC Cycles
D13875
rB Blender
D13875

Event Timeline

Leonard Göttert (Leonard) created this task.Jan 8 2022, 10:59 AM
Wouter Stomp (wouterstomp) added a subscriber: Wouter Stomp (wouterstomp).Jan 8 2022, 12:45 PM

For others to replicate this, you should probably add the exr or pack it in the blend file.

Leonard Göttert (Leonard) updated the task description.Jan 8 2022, 12:50 PM
Wouter Stomp (wouterstomp) added a comment.EditedJan 8 2022, 12:51 PM

I get the same result as you in rendered view.

System Information
Operating system: macOS-12.1-arm64-arm-64bit 64 Bits
Graphics card: Apple M1 Max Apple 4.1 Metal - 76.3

Blender Version
Broken: version: 3.1.0 Alpha, branch: master, commit date: 2022-01-07 23:28, hash: rB741ed5fcd2e2

Crash report:

Leonard Göttert (Leonard) added a comment.Jan 8 2022, 12:51 PM

I packed the exr file into the .blend file and edited the original post.

Michael (michael64) added subscribers: Michael Jones (michael_jones), Michael (michael64).Jan 8 2022, 5:55 PM

This is a case of use-after-free error.
One could apply P2707, then build and run Blender with this scene as described
and see the following log messages when reducing the surface strength from 1.000 to 0.900:

reached useful breakpoint site at intern/cycles/device/metal/device_impl.mm:535
generic_free at intern/cycles/device/metal/device_impl.mm:558 generic_free mmem: 0x2c04fe780  mmem.mtlBuffer: 0x17f153cc0  size: 67125248
enqueue in intern/cycles/device/metal/queue.mm:217 accessing mmem: 0x2c04fe780  mmem->mtlBuffer: 0x2  mmem->size: 0  pointer_index: 36
The mmem->mtlBuffer was deleted in another MetalDevice::MetalMem struct and -[MTLArgumentEncoder setBuffer:offset:atIndex:] would have crashed here

So first a MetalDevice::MetalMem struct is freed by way of LightManager::device_free which seems correct.
The memory of this struct is now free and undefined and will be reused immediately that is why we get a mmem->mtlBuffer of 0x2 and a mmem->size of 0 later.
In MetalDeviceQueue::enqueue the memory address of this freed region is pulled in via &metal_device->launch_params + offset
and -[MTLArgumentEncoder setBuffer:offset:atIndex:] is called with invalid parameter values.
Because accidentally mmem->size is 0 at this point this can be used to set a nice breakpoint for debugging but we should not even have this memory reference any more.
Maybe @Michael Jones (michael_jones) can have a look at this?

Michael (michael64) mentioned this in T94740: Crash on deleting last light.Jan 12 2022, 10:50 AM
Jesse Yurkovich (deadpin) added a subscriber: Aled Brown (Gelert).
Jesse Yurkovich (deadpin) changed the task status from Needs Triage to Confirmed.Jan 16 2022, 11:31 PM
Jesse Yurkovich (deadpin) added a project: Render & Cycles.
Jesse Yurkovich (deadpin) added a subscriber: Jesse Yurkovich (deadpin).

Will confirm since it seems legit and many folks are running into this.

Michael Jones (michael_jones) closed this task as Resolved by committing rB17cab47ed10a: Cycles: Fix T94736: Crash when modifying strength of world environment texture.Jan 19 2022, 7:17 PM
Michael Jones (michael_jones) claimed this task.
Michael Jones (michael_jones) added a commit: rB17cab47ed10a: Cycles: Fix T94736: Crash when modifying strength of world environment texture.
Brecht Van Lommel (brecht) added a commit: rC20cc512a7852: Fix t94736: crash when modifying strength of world environment texture.Jan 27 2022, 11:38 PM