Blender 4.2.1 and 4.3.0 bad crash guide while file open. #126147

Closed
opened 2024-08-09 17:42:14 +02:00 by Kent Davis · 5 comments

System Information
Operating system: macOS-13.6.8-x86_64-i386-64bit 64 Bits
Graphics card: Metal API AMD Radeon Pro 575 1.2

Blender Version
Broken: version: 4.3.0 Alpha, branch: main, commit date: 2024-08-06 23:40, hash: c20bb31325a6
Broken: 4.2.1
Worked: (newest version of Blender that worked as expected)

Short description of error
Blender 4.2.1 and 4.3.0 bad crash guide while file open.

Exact steps for others to reproduce the error
File bad crash open on Blender 4.2.1 and 4.3.0
See youtube: https://youtu.be/xfeuohJUcC0

Steps to Reproduce

  • Open Bunny character 1.0.3.blend
**System Information** Operating system: macOS-13.6.8-x86_64-i386-64bit 64 Bits Graphics card: Metal API AMD Radeon Pro 575 1.2 **Blender Version** Broken: version: 4.3.0 Alpha, branch: main, commit date: 2024-08-06 23:40, hash: `c20bb31325a6` Broken: 4.2.1 Worked: (newest version of Blender that worked as expected) **Short description of error** Blender 4.2.1 and 4.3.0 bad crash guide while file open. **Exact steps for others to reproduce the error** File bad crash open on Blender 4.2.1 and 4.3.0 See youtube: https://youtu.be/xfeuohJUcC0 **Steps to Reproduce** - Open Bunny character 1.0.3.blend
Kent Davis added the
Type
Report
Severity
Normal
Status
Needs Triage
labels 2024-08-09 17:42:14 +02:00
Member

the ips files seems to be indicating different crash scenarios.

  • 4 of them crashed in BKE_undosys_step_push_with_type after reading files.
  • 1 of them in BKE_packedfile_duplicate (during viewport copying?)
  • 1 of them in blender::eevee::MaterialModule::material_sync from drawing, likely because of material thumbnail caching.
  • 3 of them in BKE_packedfile_free on exiting blender.
the `ips` files seems to be indicating different crash scenarios. - 4 of them crashed in `BKE_undosys_step_push_with_type` after reading files. - 1 of them in `BKE_packedfile_duplicate` (during viewport copying?) - 1 of them in `blender::eevee::MaterialModule::material_sync` from drawing, likely because of material thumbnail caching. - 3 of them in `BKE_packedfile_free` on exiting blender.
Bart van der Braak added
Type
Bug
and removed
Type
Report
labels 2024-08-14 12:52:51 +02:00
Member

Hi, thanks for the report. I can confirm the crash on launch. Running mesh.validate() has detected the invalid mesh data of object Blink hair object. After fixing it, crash seems to be happening in image files. So looks like file/data is corrupted.

ERROR (bke.mesh): C:\Users\prati\OneDrive\Desktop\BlenderOSP\blender\source\blender\blenkernel\intern\mesh_validate.cc:699 BKE_mesh_validate_arrays:    Corner 172009 is unused
Hi, thanks for the report. I can confirm the crash on launch. Running mesh.validate() has detected the invalid mesh data of `object Blink hair` object. After fixing it, crash seems to be happening in image files. So looks like file/data is corrupted. ``` ERROR (bke.mesh): C:\Users\prati\OneDrive\Desktop\BlenderOSP\blender\source\blender\blenkernel\intern\mesh_validate.cc:699 BKE_mesh_validate_arrays: Corner 172009 is unused ```
Member

Looks like eye blink image data is not null but members of ima->packedfiles pointing to null data
@mont29 might know better.

Looks like `eye blink` image data is not null but members of `ima->packedfiles` pointing to null data @mont29 might know better.

OK so... Not sure how expected it is to have invalid packed data in .blendfile (there is a non-null data pointer, but it does not resolve to any actual data). But not sure we are going to be able to reproduce this situation and investigate the cause, unless @mac4kent has a way to do so from the 1.0.1 or 1.0.2 files?

In the mean while, the reading code is not behaving properly either - likely for quite some time, but the addition of the implicit sharing code made things even more hairy here.

This simple patch fixes the problem with this file and allows to open it (with two images missing). But would like to pull @JacquesLucke in the discussion, as ideally BKE_packedfile_blend_read should be able to gracefully handle failure to retrieve valid data from readfile code?

Note that similar fix would be needed in other places in the readfile code too.

diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc
index d3ec70cffbf..299d34b17da 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -410,10 +410,14 @@ static void image_blend_read_data(BlendDataReader *reader, ID *id)
   BLO_read_struct_list(reader, ImagePackedFile, &(ima->packedfiles));
 
   if (ima->packedfiles.first) {
-    LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) {
+    LISTBASE_FOREACH_MUTABLE (ImagePackedFile *, imapf, &ima->packedfiles) {
       BKE_packedfile_blend_read(reader, &imapf->packedfile);
+      if (!imapf->packedfile) {
+        BLI_remlink(&ima->packedfiles, imapf);
+        MEM_freeN(imapf);
+      }
+      ima->packedfile = nullptr;
     }
-    ima->packedfile = nullptr;
   }
   else {
     BKE_packedfile_blend_read(reader, &ima->packedfile);
diff --git a/source/blender/blenkernel/intern/packedFile.cc b/source/blender/blenkernel/intern/packedFile.cc
index 3811f523aab..a8adf861dcc 100644
--- a/source/blender/blenkernel/intern/packedFile.cc
+++ b/source/blender/blenkernel/intern/packedFile.cc
@@ -905,15 +905,20 @@ void BKE_packedfile_blend_read(BlendDataReader *reader, PackedFile **pf_p)
   if (pf == nullptr) {
     return;
   }
-  /* NOTE: there is no way to handle endianness switch here. */
-  pf->sharing_info = BLO_read_shared(reader, &pf->data, [&]() {
-    BLO_read_data_address(reader, &pf->data);
-    return blender::implicit_sharing::info_for_mem_free(const_cast<void *>(pf->data));
-  });
+  if (BLO_read_get_new_data_address_no_us(reader, pf->data, pf->size)) {
+    /* NOTE: there is no way to handle endianness switch here. */
+    pf->sharing_info = BLO_read_shared(reader, &pf->data, [&]() {
+      BLO_read_data_address(reader, &pf->data);
+      return blender::implicit_sharing::info_for_mem_free(const_cast<void *>(pf->data));
+    });
+  }
+  else {
+    pf->data = nullptr;
+  }
   if (pf->data == nullptr) {
     /* We cannot allow a PackedFile with a nullptr data field,
      * the whole code assumes this is not possible. See #70315. */
     printf("%s: nullptr packedfile data, cleaning up...\n", __func__);
-    MEM_SAFE_FREE(pf);
+    MEM_SAFE_FREE(*pf_p);
   }
 }
OK so... Not sure how expected it is to have invalid packed data in .blendfile (there is a non-null data pointer, but it does not resolve to any actual data). But not sure we are going to be able to reproduce this situation and investigate the cause, unless @mac4kent has a way to do so from the 1.0.1 or 1.0.2 files? In the mean while, the reading code is not behaving properly either - likely for quite some time, but the addition of the implicit sharing code made things even more hairy here. This simple patch fixes the problem with this file and allows to open it (with two images missing). But would like to pull @JacquesLucke in the discussion, as ideally `BKE_packedfile_blend_read` should be able to gracefully handle failure to retrieve valid data from readfile code? Note that similar fix would be needed in other places in the readfile code too. ```diff diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index d3ec70cffbf..299d34b17da 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -410,10 +410,14 @@ static void image_blend_read_data(BlendDataReader *reader, ID *id) BLO_read_struct_list(reader, ImagePackedFile, &(ima->packedfiles)); if (ima->packedfiles.first) { - LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) { + LISTBASE_FOREACH_MUTABLE (ImagePackedFile *, imapf, &ima->packedfiles) { BKE_packedfile_blend_read(reader, &imapf->packedfile); + if (!imapf->packedfile) { + BLI_remlink(&ima->packedfiles, imapf); + MEM_freeN(imapf); + } + ima->packedfile = nullptr; } - ima->packedfile = nullptr; } else { BKE_packedfile_blend_read(reader, &ima->packedfile); diff --git a/source/blender/blenkernel/intern/packedFile.cc b/source/blender/blenkernel/intern/packedFile.cc index 3811f523aab..a8adf861dcc 100644 --- a/source/blender/blenkernel/intern/packedFile.cc +++ b/source/blender/blenkernel/intern/packedFile.cc @@ -905,15 +905,20 @@ void BKE_packedfile_blend_read(BlendDataReader *reader, PackedFile **pf_p) if (pf == nullptr) { return; } - /* NOTE: there is no way to handle endianness switch here. */ - pf->sharing_info = BLO_read_shared(reader, &pf->data, [&]() { - BLO_read_data_address(reader, &pf->data); - return blender::implicit_sharing::info_for_mem_free(const_cast<void *>(pf->data)); - }); + if (BLO_read_get_new_data_address_no_us(reader, pf->data, pf->size)) { + /* NOTE: there is no way to handle endianness switch here. */ + pf->sharing_info = BLO_read_shared(reader, &pf->data, [&]() { + BLO_read_data_address(reader, &pf->data); + return blender::implicit_sharing::info_for_mem_free(const_cast<void *>(pf->data)); + }); + } + else { + pf->data = nullptr; + } if (pf->data == nullptr) { /* We cannot allow a PackedFile with a nullptr data field, * the whole code assumes this is not possible. See #70315. */ printf("%s: nullptr packedfile data, cleaning up...\n", __func__); - MEM_SAFE_FREE(pf); + MEM_SAFE_FREE(*pf_p); } } ```
Member

Hm, this is weird. I think I had a similar case a few weeks ago: 85760b6a13 (was the first time I had seen this issue). That was unrelated to implicit sharing though. I could not figure out under which condition it's possible to create such a .blend file yet.

As you can see, my fix back then was similar to what you suggest here. Would still be great to figure out what may be the root cause of this...

Hm, this is weird. I think I had a similar case a few weeks ago: 85760b6a132e84473e976ee778a2daac970c503b (was the first time I had seen this issue). That was unrelated to implicit sharing though. I could not figure out under which condition it's possible to create such a .blend file yet. As you can see, my fix back then was similar to what you suggest here. Would still be great to figure out what may be the root cause of this...
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2024-08-16 15:04:38 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
5 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#126147
No description provided.