golgepapaz
Topic Author
Posts: 43
Joined: 01 Aug 2013, 01:59

[Unity] Null reference exception when binding set value

09 Jul 2014, 14:53

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?
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

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

10 Jul 2014, 02:27

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.
 
golgepapaz
Topic Author
Posts: 43
Joined: 01 Aug 2013, 01:59

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

10 Jul 2014, 09:16

No, I don't get any warning message in the console. I change my reference to strong reference, it solves the problem.

Thanks

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 6 guests