Skip to content

Commit 7232e81

Browse files
PaulDemeulenaereGitHub Enterprise
authored andcommitted
[Fix] Null Ref Exception due to IsAssetEditable (#221)
* Resource can be null on a block inspector while we are removing it Use safe check of resource before IsAssetEditable * *Update changelog * Fix issue https://github.cds.internal.unity3d.com/unity/vfx-graphics/pull/221#discussion_r113060
1 parent eb6f548 commit 7232e81

File tree

7 files changed

+14
-8
lines changed

7 files changed

+14
-8
lines changed

com.unity.visualeffectgraph/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4141
- Safe Normalization of Cross Products in Orient blocks [Case 1272724](https://issuetracker.unity3d.com/product/unity/issues/guid/1272724)
4242
- Property Binder : Undo after reset [Case 1293794](https://issuetracker.unity3d.com/product/unity/issues/guid/1293794/)
4343
- Property Binder : Allow copy/past from a game object to another
44+
- Deleting a context node and a block while both are selected throws a null ref exception. [Case 315578](https://issuetracker.unity3d.com/product/unity/issues/guid/1315578/)
4445

4546
## [11.0.0] - 2020-10-21
4647

com.unity.visualeffectgraph/Editor/Debug/VFXUIDebug.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ void AddSystemInfoEntry(string systemName, int id, Color color)
838838
var maxAliveButton = new Button();
839839
maxAliveButton.name = "debug-system-stat-entry";
840840
maxAliveButton.text = "0";
841-
maxAliveButton.SetEnabled(m_Graph.visualEffectResource.IsAssetEditable());
841+
maxAliveButton.SetEnabled(m_Graph.visualEffectResource != null && m_Graph.visualEffectResource.IsAssetEditable());
842842
maxAliveButton.clickable.clickedWithEventInfo += setCapacity;
843843
maxAlive = maxAliveButton;
844844
}
@@ -937,7 +937,7 @@ Action<EventBase> CapacitySetter(string systemName, out bool isSystemInSubGraph)
937937
isSystemInSubGraph = true;
938938
return (e) =>
939939
{
940-
if (!m_Graph.visualEffectResource.IsAssetEditable())
940+
if (m_Graph.visualEffectResource != null && !m_Graph.visualEffectResource.IsAssetEditable())
941941
return; //The button should be disabled but state update can have a delay
942942

943943
var button = e.currentTarget as Button;
@@ -957,7 +957,7 @@ void UpdateSystemInfoEntry(int systemId, VFXParticleSystemInfo stat)
957957
alive.text = stat.aliveCount.ToString();
958958
if (statUI[4] is TextElement maxAliveText)
959959
{
960-
maxAliveText.SetEnabled(m_Graph.visualEffectResource.IsAssetEditable());
960+
maxAliveText.SetEnabled(m_Graph.visualEffectResource != null && m_Graph.visualEffectResource.IsAssetEditable());
961961
maxAliveText.text = Mathf.Max(int.Parse(maxAliveText.text), stat.aliveCount).ToString();
962962
}
963963
if (statUI[5] is TextElement efficiency)

com.unity.visualeffectgraph/Editor/GraphView/Views/VFXView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ void ControllerChanged(int change)
901901

902902
public bool IsAssetEditable()
903903
{
904-
return controller.model.IsAssetEditable();
904+
return controller.model != null && controller.model.IsAssetEditable();
905905
}
906906

907907
void NewControllerSet()

com.unity.visualeffectgraph/Editor/Inspector/VFXParameterEditor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public override SerializedProperty DoInspectorGUI()
4747
var saveEnabled = GUI.enabled;
4848

4949
var referenceModel = serializedObject.targetObject as VFXModel;
50-
if (!referenceModel.GetResource().IsAssetEditable())
50+
var resource = referenceModel.GetResource();
51+
if (resource != null && !resource.IsAssetEditable())
5152
{
5253
GUI.enabled = false;
5354
saveEnabled = false;

com.unity.visualeffectgraph/Editor/Inspector/VFXSlotContainerEditor.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ public override void OnInspectorGUI()
229229
{
230230
serializedObject.Update();
231231
var referenceModel = serializedObject.targetObject as VFXModel;
232-
GUI.enabled = referenceModel.GetResource().IsAssetEditable();
232+
233+
var resource = referenceModel.GetResource();
234+
GUI.enabled = resource != null ? resource.IsAssetEditable() : true;
233235

234236
SerializedProperty modifiedProperty = DoInspectorGUI();
235237

com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXBasicSpawner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public override void OnInspectorGUI()
8282
serializedObject.Update();
8383

8484
var referenceContext = serializedObject.targetObject as VFXContext;
85-
GUI.enabled = referenceContext.GetResource().IsAssetEditable();
85+
var resource = referenceContext.GetResource();
86+
GUI.enabled = resource != null ? resource.IsAssetEditable() : true;
8687

8788
EditorGUI.BeginChangeCheck();
8889
EditorGUILayout.PropertyField(m_LoopDurationProperty);

com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXBasicUpdate.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public override void OnInspectorGUI()
6969
serializedObject.Update();
7070

7171
var referenceContext = serializedObject.targetObject as VFXContext;
72-
GUI.enabled = referenceContext.GetResource().IsAssetEditable();
72+
var resource = referenceContext.GetResource();
73+
GUI.enabled = resource != null ? resource.IsAssetEditable() : true;
7374

7475
DisplaySpace();
7576
DisplayName();

0 commit comments

Comments
 (0)