Fix crash when modify parameter of visual shader #112111
                
     Open
            
            
          
      
        
          +16
        
        
          −0
        
        
          
        
      
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Issue Description
When changed parameter value of Visual Shader, we will trigger a "changed" signal and invoke
VisualShaderEditor::_param_property_changed(). Notification chain is as follows:visual_shader._set_preview_shader_parameter()visual_shader.emit_changed(), trigger "changed" signalShaderMaterial::_shader_changed()ShaderMaterial::notify_property_list_changed(), trigger "property_list_changed" signalVisualShaderEditor::_update_preview_parameter_list()In
_update_preview_parameter_list(), we usedget_shader_parameter_list()fromRenderingServerto sync UI tree list. The problem is we need determine whether we need re-create parameter tree. Current behavior clean and re-create parameter tree all the time. But after re-created tree,VisualShaderEditorstill want to focus to the previous selected node. But the tree is re-created, we cannot get the previous selected tree, so theselect_nodeisnullptr, then crashed.Solution
I checked the properties from
RenderingServerand the current parameter list from Editor. If there is NO inserted or removed parameters, we donot need to re-create parameter tree. So we can prevent crash.Also, I add a
ERR_FAIL_NULL_MSGto prevent get_selected_node is null, that is for safe.