Fix #108591: Handle null material adding paint slot #108592

Merged
YimingWu merged 5 commits from ChengduLittleA/blender:fix-108591 into blender-v3.6-release 2023-06-06 04:13:08 +02:00
Member

When adding a texture paint slot to an object, the object could have no
material, this patch handles that so it won't need to call
default_paint_slot_color_get to get color from the material before
calling the operator.

When adding a texture paint slot to an object, the object could have no material, this patch handles that so it won't need to call `default_paint_slot_color_get` to get color from the material before calling the operator.
YimingWu added the
Module
Sculpt, Paint & Texture
label 2023-06-05 08:07:16 +02:00
Pratik Borhade requested review from Joseph Eagar 2023-06-05 10:42:21 +02:00
Member

Crash was caused by 859c0d9edf btw. @HooglyBoogly

Crash was caused by 859c0d9edf btw. @HooglyBoogly

Hay, as i can see, default_paint_slot_color_get already has branch to solve
null material / node tree case. This fix just should start to use this case, instead
another checking with new constant value.

Hay, as i can see, `default_paint_slot_color_get` already has branch to solve null material / node tree case. This fix just should start to use this case, instead another checking with new constant value.
Author
Member

Good point. I changed it to set default values in default_paint_slot_color_get.

Good point. I changed it to set default values in `default_paint_slot_color_get`.

I mean something like

      bNodeTree *ntree = nullptr;
      bNode *in_node = nullptr;
      if (me != nullptr && ma->nodetree != nullptr) {
        ma->nodetree->ensure_topology_cache();
        const blender::Span<bNode *> nodes = ma->nodetree->nodes_by_type("ShaderNodeBsdfPrincipled");
        in_node = nodes.is_empty() ? nullptr : nodes.first();
      }
      if (!in_node) {
        /* An existing material or Principled BSDF node could not be found.
         * Copy default color values from a default Principled BSDF instead. */
        ntree = ntreeAddTree(nullptr, "Temporary Shader Nodetree", ntreeType_Shader->idname);
        in_node = nodeAddStaticNode(nullptr, ntree, SH_NODE_BSDF_PRINCIPLED);
      }
I mean something like ```Cpp bNodeTree *ntree = nullptr; bNode *in_node = nullptr; if (me != nullptr && ma->nodetree != nullptr) { ma->nodetree->ensure_topology_cache(); const blender::Span<bNode *> nodes = ma->nodetree->nodes_by_type("ShaderNodeBsdfPrincipled"); in_node = nodes.is_empty() ? nullptr : nodes.first(); } if (!in_node) { /* An existing material or Principled BSDF node could not be found. * Copy default color values from a default Principled BSDF instead. */ ntree = ntreeAddTree(nullptr, "Temporary Shader Nodetree", ntreeType_Shader->idname); in_node = nodeAddStaticNode(nullptr, ntree, SH_NODE_BSDF_PRINCIPLED); } ```
Member

This PR should probably target 3.6 instead of main.

This PR should probably target 3.6 instead of main.
Author
Member

thanks @mod_moder.

thanks @mod_moder.
YimingWu changed title from Fix #108591: Handle `mat==null` adding paint slot to Fix #108591: Handle `mat==null` adding paint slot 2023-06-05 15:15:55 +02:00
ChengduLittleA changed target branch from main to blender-v3.6-release 2023-06-05 15:15:57 +02:00
YimingWu changed title from Fix #108591: Handle `mat==null` adding paint slot to Fix #108591: Handle `mat==null` adding paint slot 2023-06-05 15:16:44 +02:00
ChengduLittleA changed target branch from blender-v3.6-release to main 2023-06-05 15:16:46 +02:00
YimingWu force-pushed fix-108591 from 1f1bdb9683 to 22baaaf987 2023-06-05 15:20:12 +02:00 Compare
YimingWu changed title from Fix #108591: Handle `mat==null` adding paint slot to Fix #108591: Handle `mat==null` adding paint slot 2023-06-05 15:20:20 +02:00
ChengduLittleA changed target branch from main to blender-v3.6-release 2023-06-05 15:20:22 +02:00
Hans Goudey reviewed 2023-06-05 16:19:51 +02:00
@ -6643,0 +6641,4 @@
if (ma && ma->nodetree) {
ma->nodetree->ensure_topology_cache();
const blender::Span<bNode *> nodes = ma->nodetree->nodes_by_type("ShaderNodeBsdfPrincipled");
nodes.is_empty() ? nullptr : nodes.first();
Member

Am I missing something? nodes.is_empty() ? nullptr : nodes.first(); doesn't seem to do anything

Am I missing something? `nodes.is_empty() ? nullptr : nodes.first();` doesn't seem to do anything
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2023-06-06 03:50:48 +02:00
Hans Goudey approved these changes 2023-06-06 03:56:04 +02:00
Hans Goudey changed title from Fix #108591: Handle `mat==null` adding paint slot to Fix #108591: Handle null material adding paint slot 2023-06-06 03:56:25 +02:00
YimingWu merged commit 8a0a9ec0c3 into blender-v3.6-release 2023-06-06 04:13:08 +02:00
YimingWu deleted branch fix-108591 2023-06-06 04:13:11 +02:00
Sign in to join this conversation.
No reviewers
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
4 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#108592
No description provided.