Page 1 of 1

[Unity] Null reference exception when binding set value

Posted: 09 Jul 2014, 14:53
by golgepapaz
Hi,

I am getting the following null reference exception when changing value of text box.
NullReferenceException: Object reference not set to an instance of an object
Noesis.Extend.GetExtendInfo (IntPtr cPtr) (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisExtend.cs:1207)
Noesis.Extend.GetInstance (IntPtr cPtr) (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisExtend.cs:1195)
Noesis.Extend.SetPropertyValue_String (IntPtr unityType, Int32 propertyIndex, IntPtr cPtr, IntPtr val) (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisExtend.cs:974)
(wrapper native-to-managed) Noesis.Extend:SetPropertyValue_String (intptr,int,intptr,intptr)
Noesis.UIRenderer.Noesis_KeyDown (Int32 rendererId, Int32 key) (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisUIRendererImports.cs:241)
Noesis.UIRenderer.ProcessEvent (UnityEngine.Event ev, Boolean enableKeyboard, Boolean enableMouse) (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisUIRenderer.cs:248)
NoesisGUIPanel.OnGUI () (at Assets/Plugins/NoesisGUI/Scripts/NoesisGUIPanel.cs:135)
This is my model class
[Noesis.Extended]
public class Person : BaseComponent
{
private string name;

public string Name
{
get { return name; }
set
{
name = value;

NotifyPropertyChanged("Name");
}
}
}
This is view
Person person = new Person() { Name = "John" };
TextBox tb = new TextBox();
Binding binding = new Binding("Name");
binding.SetSource(person );
BindingOperations.SetBinding(tb, TextBox.TextProperty, binding);
Am I missing something?

Re: [Unity] Null reference exception when binding set value

Posted: 10 Jul 2014, 02:27
by sfernandez
Are you getting a warning message in the console saying "Extend already removed" or "Extend instance already destroyed"?

The problem I'm seeing is that in our native implementation, the Binding doesn't keep a strong reference to the Source object (because it can create circular references, then memory leaks). So if you don't keep a strong reference yourself to the Person instance, this object will be destroyed by the GC anytime after the variable gets out of scope.

Anyway, we should detect that binding source was destroyed and disable it instead of generating a null reference exception when TextBox is updated.

Re: [Unity] Null reference exception when binding set value

Posted: 10 Jul 2014, 09:16
by golgepapaz
No, I don't get any warning message in the console. I change my reference to strong reference, it solves the problem.

Thanks