Switching Grease Pencil material slot link to Object and back to Data corrupts material #64896

Closed
opened 2019-05-20 20:15:55 +02:00 by matc · 10 comments

Blender Version
Broken: 9efe117535, master, 2018-05-20

Short description of error
For normal objects switching a material slot link to Object and back to Data will result in the material to reappear in the slot. For Grease Pencil objects the material in the slot will point to 0xcccc.... This causes blender to crash while rendering the viewport.

Exact steps for others to reproduce the error

  • File -> New -> 2D Animation
  • Switch Link of material slot to Object (Bottom right button in material slot selector.)
  • Switch Link of same material slot back to Data
  • Blender crashes on viewport render
**Blender Version** Broken: 9efe117535c6, master, 2018-05-20 **Short description of error** For normal objects switching a material slot link to Object and back to Data will result in the material to reappear in the slot. For Grease Pencil objects the material in the slot will point to `0xcccc...`. This causes blender to crash while rendering the viewport. **Exact steps for others to reproduce the error** - File -> New -> 2D Animation - Switch **Link** of material slot to **Object** (Bottom right button in material slot selector.) - Switch **Link** of same material slot back to **Data** - Blender crashes on viewport render
Author

Added subscriber: @matc

Added subscriber: @matc
Antonio Vazquez was assigned by Brecht Van Lommel 2019-05-29 02:45:36 +02:00

Added subscriber: @brecht

Added subscriber: @brecht

@brecht I have been doing debug and I have seen the problem is when retry the material.

The material is recovered using

give_current_material(ob, ob->actcol);

You can find the code in BKE_gpencil_object_material_get_from_brush()

IIRC you told me the function give_current_material() Is used to get the mat for Data and for Objet mode, but in this case, the function is returning NaN. I have checked and the Object parameter is correct and the ob->actcol=1, so not sure why this is not working... at least the function could return NULL intead of garbage data.

Any idea?

@brecht I have been doing debug and I have seen the problem is when retry the material. The material is recovered using ``` give_current_material(ob, ob->actcol); ``` You can find the code in BKE_gpencil_object_material_get_from_brush() IIRC you told me the function give_current_material() Is used to get the mat for Data and for Objet mode, but in this case, the function is returning NaN. I have checked and the Object parameter is correct and the ob->actcol=1, so not sure why this is not working... at least the function could return NULL intead of garbage data. Any idea?

I have seen this in the console, not sure if related or not:

find_node_operation: Failed for (MATERIAL_UPDATE, '')
add_relation(Material -> GP Data) - Could not find op_from (OperationKey(type: SHADING, component name: '', operation code: MATERIAL_UPDATE))
add_relation(Material -> GP Data) - Failed, but op_to (ComponentKey(GDStroke, GEOMETRY)) was ok
I have seen this in the console, not sure if related or not: ``` find_node_operation: Failed for (MATERIAL_UPDATE, '') add_relation(Material -> GP Data) - Could not find op_from (OperationKey(type: SHADING, component name: '', operation code: MATERIAL_UPDATE)) add_relation(Material -> GP Data) - Failed, but op_to (ComponentKey(GDStroke, GEOMETRY)) was ok ```
Author

Could be that the problem is in DepsgraphNodeBuilder::build_object_data_geometry where only materials are handled which are returned by give_current_material. When setting a link to Object, then the material in ob->data is ignored. But I'm not sure how this wouldn't have caused problems with the default cube.

This would fix the problem:

diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
index 93e5dd14ae0..acdf08b7f32 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
@@ -1191,9 +1191,19 @@ void DepsgraphNodeBuilder::build_object_data_geometry(Object *object, bool is_ob
       function_bind(BKE_object_eval_uber_data, _1, scene_cow, object_cow));
   op_node->set_as_exit();
   /* Materials. */
-  if (object->totcol != 0) {
-    for (int a = 1; a <= object->totcol; a++) {
-      Material *ma = give_current_material(object, a);
+  if (object->totcol) {
+    for (int a = 0; a < object->totcol; a++) {
+      Material *ma = object->mat[a];
+      if (ma != NULL) {
+        build_material(ma);
+      }
+    }
+  }
+  short *totcolp = give_totcolp(object);
+  if (*totcolp) {
+    Material ***matarar = give_matarar(object);
+    for (int a = 0; a < *totcolp; a++) {
+      Material *ma = (*matarar)[a];
       if (ma != NULL) {
         build_material(ma);
       }
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index 54d5223497e..117b1fd6d19 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -1918,8 +1918,18 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object)
   }
   /* Materials. */
   if (object->totcol) {
-    for (int a = 1; a <= object->totcol; a++) {
-      Material *ma = give_current_material(object, a);
+    for (int a = 0; a < object->totcol; a++) {
+      Material *ma = object->mat[a];
+      if (ma != NULL) {
+        build_material(ma);
+      }
+    }
+  }
+  short *totcolp = give_totcolp(object);
+  if (*totcolp) {
+    Material ***matarar = give_matarar(object);
+    for (int a = 0; a < *totcolp; a++) {
+      Material *ma = (*matarar)[a];
       if (ma != NULL) {
         build_material(ma);
       }

Could be that the problem is in `DepsgraphNodeBuilder::build_object_data_geometry` where only materials are handled which are returned by `give_current_material`. When setting a link to Object, then the material in `ob->data` is ignored. But I'm not sure how this wouldn't have caused problems with the default cube. This would fix the problem: ``` diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc index 93e5dd14ae0..acdf08b7f32 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc @@ -1191,9 +1191,19 @@ void DepsgraphNodeBuilder::build_object_data_geometry(Object *object, bool is_ob function_bind(BKE_object_eval_uber_data, _1, scene_cow, object_cow)); op_node->set_as_exit(); /* Materials. */ - if (object->totcol != 0) { - for (int a = 1; a <= object->totcol; a++) { - Material *ma = give_current_material(object, a); + if (object->totcol) { + for (int a = 0; a < object->totcol; a++) { + Material *ma = object->mat[a]; + if (ma != NULL) { + build_material(ma); + } + } + } + short *totcolp = give_totcolp(object); + if (*totcolp) { + Material ***matarar = give_matarar(object); + for (int a = 0; a < *totcolp; a++) { + Material *ma = (*matarar)[a]; if (ma != NULL) { build_material(ma); } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 54d5223497e..117b1fd6d19 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -1918,8 +1918,18 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object) } /* Materials. */ if (object->totcol) { - for (int a = 1; a <= object->totcol; a++) { - Material *ma = give_current_material(object, a); + for (int a = 0; a < object->totcol; a++) { + Material *ma = object->mat[a]; + if (ma != NULL) { + build_material(ma); + } + } + } + short *totcolp = give_totcolp(object); + if (*totcolp) { + Material ***matarar = give_matarar(object); + for (int a = 0; a < *totcolp; a++) { + Material *ma = (*matarar)[a]; if (ma != NULL) { build_material(ma); } ```

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk

@lichtwerk I don't know what to do here... maybe you need reassign to someone that knows how to fix it, because it looks something outside Gpencil code.

@lichtwerk I don't know what to do here... maybe you need reassign to someone that knows how to fix it, because it looks something outside Gpencil code.
Antonio Vazquez was unassigned by Philipp Oeser 2019-09-13 13:49:10 +02:00
Member

Added subscriber: @antoniov

Added subscriber: @antoniov

Closed as duplicate of #63757

Closed as duplicate of #63757

Closed by error. This has been fixed in #66293

Closed by error. This has been fixed in #66293
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#64896
No description provided.