From bc71d48ba9dfc7e7062779d6d12b9ef269e521b1 Mon Sep 17 00:00:00 2001 From: Antoine Lelievre Date: Fri, 1 Oct 2021 13:16:35 +0200 Subject: [PATCH] Fixed errors when a parameter is destroyed and it's reference is still used in the graph. --- .../Runtime/Elements/ExposedParameter.cs | 2 +- .../Runtime/Elements/ParameterNode.cs | 7 +++++++ CHANGELOG.md | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Assets/com.alelievr.NodeGraphProcessor/Runtime/Elements/ExposedParameter.cs b/Assets/com.alelievr.NodeGraphProcessor/Runtime/Elements/ExposedParameter.cs index 03d666ad..75adaa6e 100644 --- a/Assets/com.alelievr.NodeGraphProcessor/Runtime/Elements/ExposedParameter.cs +++ b/Assets/com.alelievr.NodeGraphProcessor/Runtime/Elements/ExposedParameter.cs @@ -68,7 +68,7 @@ void ISerializationCallbackReceiver.OnBeforeSerialize() {} protected virtual Settings CreateSettings() => new Settings(); public virtual object value { get; set; } - public virtual Type GetValueType() => value.GetType(); + public virtual Type GetValueType() => value == null ? typeof(object) : value.GetType(); static Dictionary exposedParameterTypeCache = new Dictionary(); internal ExposedParameter Migrate() diff --git a/Assets/com.alelievr.NodeGraphProcessor/Runtime/Elements/ParameterNode.cs b/Assets/com.alelievr.NodeGraphProcessor/Runtime/Elements/ParameterNode.cs index bc05b806..d86856e2 100644 --- a/Assets/com.alelievr.NodeGraphProcessor/Runtime/Elements/ParameterNode.cs +++ b/Assets/com.alelievr.NodeGraphProcessor/Runtime/Elements/ParameterNode.cs @@ -97,6 +97,13 @@ protected override void Process() parameter = graph.GetExposedParameterFromGUID(parameterGUID); #endif + ClearMessages(); + if (parameter == null) + { + AddMessage($"Parameter not found: {parameterGUID}", NodeMessageType.Error); + return; + } + if (accessor == ParameterAccessor.Get) output = parameter.value; else diff --git a/CHANGELOG.md b/CHANGELOG.md index 92cce7ff..ea582db0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed fields with [Settings] attribute not showing up with inheritance. - Fixed selection still active when selecting nodes without inspector fields. - Fixed multi-selection drag and drop of edges. +- Fixed errors when a parameter is destroyed and it's reference is still used in the graph. ### Changed - Fields with both attributes [SerializeField] and [ShowInInspector] are now visible in both the node and inspector.