Cycles standalone randomly crashing on Mojave and Catalina but not on Sierra. #74415

Closed
opened 2020-03-04 01:19:44 +01:00 by Giovanni Remigi · 4 comments

I've been using Cycles as a library inside my own project for years, building it on Windows (MinGW64), Linux (gcc) and macOS Sierra (clang) without any issue. I've recently migrated to Mojave and updated all Cycles code to the very last commit the end of February 2020. On Sierra, after the update, it still compiles and works perfectly as ever, but on Mojave and Catalina it crashes randomly. On Windows and Linux it runs perfectly.

Initially, I blamed the new version of Xcode, but if I compile on Sierra (with the latest code of cycles) and then move the application to Mojave, I still experience random crashes.

It seems the crash appears when I create and destroy a session (either working in background or directly on screen) multiple times. I spent one month to dig up the problem and I found one single line of code which causes the random crash, the line which creates the array data1 in the file bvh.cpp, see snippet below.

        /* Modify offsets into arrays */
        int4 data = bvh_nodes[i + nsize_bbox];
        int4 data1 = bvh_nodes[i + nsize_bbox - 1]; <-- this is the line
        if (use_obvh) {
          data.z += (data.z < 0) ? -noffset_leaf : noffset;
          data.w += (data.w < 0) ? -noffset_leaf : noffset;
          data.x += (data.x < 0) ? -noffset_leaf : noffset;
          data.y += (data.y < 0) ? -noffset_leaf : noffset;
          data1.z += (data1.z < 0) ? -noffset_leaf : noffset;
          data1.w += (data1.w < 0) ? -noffset_leaf : noffset;
          data1.x += (data1.x < 0) ? -noffset_leaf : noffset;
          data1.y += (data1.y < 0) ? -noffset_leaf : noffset;
        }
        else {
          data.z += (data.z < 0) ? -noffset_leaf : noffset;
          data.w += (data.w < 0) ? -noffset_leaf : noffset;
          if (use_qbvh) {
            data.x += (data.x < 0) ? -noffset_leaf : noffset;
            data.y += (data.y < 0) ? -noffset_leaf : noffset;
          }
        }
        pack_nodes[pack_nodes_offset + nsize_bbox] = data;
        if (use_obvh) {
          pack_nodes[pack_nodes_offset + nsize_bbox - 1] = data1;
        }

I fixed the issue by moving the line which creates the array data1 into the if condition as following.

        /* Modify offsets into arrays */
        int4 data = bvh_nodes[i + nsize_bbox];
        if (use_obvh) {
          int4 data1 = bvh_nodes[i + nsize_bbox - 1];
          data.z += (data.z < 0) ? -noffset_leaf : noffset;
          data.w += (data.w < 0) ? -noffset_leaf : noffset;
          data.x += (data.x < 0) ? -noffset_leaf : noffset;
          data.y += (data.y < 0) ? -noffset_leaf : noffset;
          data1.z += (data1.z < 0) ? -noffset_leaf : noffset;
          data1.w += (data1.w < 0) ? -noffset_leaf : noffset;
          data1.x += (data1.x < 0) ? -noffset_leaf : noffset;
          data1.y += (data1.y < 0) ? -noffset_leaf : noffset;
          pack_nodes[pack_nodes_offset + nsize_bbox] = data;
          pack_nodes[pack_nodes_offset + nsize_bbox - 1] = data1;
        }
        else {
          data.z += (data.z < 0) ? -noffset_leaf : noffset;
          data.w += (data.w < 0) ? -noffset_leaf : noffset;
          if (use_qbvh) {
            data.x += (data.x < 0) ? -noffset_leaf : noffset;
            data.y += (data.y < 0) ? -noffset_leaf : noffset;
          }
          pack_nodes[pack_nodes_offset + nsize_bbox] = data;
        }

The code of both snippets does exactly the same thing, there is no functional change. The only difference is that data1 is created only when it is used. If I used a layout BH2, data1 is not required but it is created anyway.

I cannot really explain why the random crash happens on Mojave and Catalina only, I think it is due to some concurrency issue while sessions are created and destroyed one after the other in close sequence. Considering that both snippets of code are equivalent and that the new code avoid the creation of the array data1 when not required, the change seems to me a reasonable one with a small gain in performance when using a BH2 layout. It definitely fixes the random crash I've experienced on macOS Mojave and Catalina.

Regards,

Giovanni

I've been using Cycles as a library inside my own project for years, building it on Windows (MinGW64), Linux (gcc) and macOS Sierra (clang) without any issue. I've recently migrated to Mojave and updated all Cycles code to the very last commit the end of February 2020. On Sierra, after the update, it still compiles and works perfectly as ever, but on Mojave and Catalina it crashes randomly. On Windows and Linux it runs perfectly. Initially, I blamed the new version of Xcode, but if I compile on Sierra (with the latest code of cycles) and then move the application to Mojave, I still experience random crashes. It seems the crash appears when I create and destroy a session (either working in background or directly on screen) multiple times. I spent one month to dig up the problem and I found one single line of code which causes the random crash, the line which creates the array data1 in the file bvh.cpp, see snippet below. ``` /* Modify offsets into arrays */ int4 data = bvh_nodes[i + nsize_bbox]; int4 data1 = bvh_nodes[i + nsize_bbox - 1]; <-- this is the line if (use_obvh) { data.z += (data.z < 0) ? -noffset_leaf : noffset; data.w += (data.w < 0) ? -noffset_leaf : noffset; data.x += (data.x < 0) ? -noffset_leaf : noffset; data.y += (data.y < 0) ? -noffset_leaf : noffset; data1.z += (data1.z < 0) ? -noffset_leaf : noffset; data1.w += (data1.w < 0) ? -noffset_leaf : noffset; data1.x += (data1.x < 0) ? -noffset_leaf : noffset; data1.y += (data1.y < 0) ? -noffset_leaf : noffset; } else { data.z += (data.z < 0) ? -noffset_leaf : noffset; data.w += (data.w < 0) ? -noffset_leaf : noffset; if (use_qbvh) { data.x += (data.x < 0) ? -noffset_leaf : noffset; data.y += (data.y < 0) ? -noffset_leaf : noffset; } } pack_nodes[pack_nodes_offset + nsize_bbox] = data; if (use_obvh) { pack_nodes[pack_nodes_offset + nsize_bbox - 1] = data1; } ``` I fixed the issue by moving the line which creates the array data1 into the if condition as following. ``` /* Modify offsets into arrays */ int4 data = bvh_nodes[i + nsize_bbox]; if (use_obvh) { int4 data1 = bvh_nodes[i + nsize_bbox - 1]; data.z += (data.z < 0) ? -noffset_leaf : noffset; data.w += (data.w < 0) ? -noffset_leaf : noffset; data.x += (data.x < 0) ? -noffset_leaf : noffset; data.y += (data.y < 0) ? -noffset_leaf : noffset; data1.z += (data1.z < 0) ? -noffset_leaf : noffset; data1.w += (data1.w < 0) ? -noffset_leaf : noffset; data1.x += (data1.x < 0) ? -noffset_leaf : noffset; data1.y += (data1.y < 0) ? -noffset_leaf : noffset; pack_nodes[pack_nodes_offset + nsize_bbox] = data; pack_nodes[pack_nodes_offset + nsize_bbox - 1] = data1; } else { data.z += (data.z < 0) ? -noffset_leaf : noffset; data.w += (data.w < 0) ? -noffset_leaf : noffset; if (use_qbvh) { data.x += (data.x < 0) ? -noffset_leaf : noffset; data.y += (data.y < 0) ? -noffset_leaf : noffset; } pack_nodes[pack_nodes_offset + nsize_bbox] = data; } ``` The code of both snippets does exactly the same thing, there is no functional change. The only difference is that data1 is created only when it is used. If I used a layout BH2, data1 is not required but it is created anyway. I cannot really explain why the random crash happens on Mojave and Catalina only, I think it is due to some concurrency issue while sessions are created and destroyed one after the other in close sequence. Considering that both snippets of code are equivalent and that the new code avoid the creation of the array data1 when not required, the change seems to me a reasonable one with a small gain in performance when using a BH2 layout. It definitely fixes the random crash I've experienced on macOS Mojave and Catalina. Regards, Giovanni

Added subscriber: @GiovanniRemigi

Added subscriber: @GiovanniRemigi
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke
Member

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

Changed status from 'Needs Triage' to: 'Archived'
Jacques Lucke self-assigned this 2020-03-04 10:44:07 +01:00
Member

Can you upload this as a patch, please? Then it can go through normal code review.

I'll close this as invalid, because this should be a patch.

Thanks for the contribution.

Can you upload this as a patch, please? Then it can go through normal code review. I'll close this as invalid, because this should be a patch. Thanks for the contribution.
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
2 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#74415
No description provided.