-
- golgepapaz
- Posts: 43
- Joined:
[Unity] Null reference exception when binding set value
Hi,
I am getting the following null reference exception when changing value of text box.
I am getting the following null reference exception when changing value of text box.
This is my model classNullReferenceException: 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 view[Noesis.Extended]
public class Person : BaseComponent
{
private string name;
public string Name
{
get { return name; }
set
{
name = value;
NotifyPropertyChanged("Name");
}
}
}
Am I missing something?Person person = new Person() { Name = "John" };
TextBox tb = new TextBox();
Binding binding = new Binding("Name");
binding.SetSource(person );
BindingOperations.SetBinding(tb, TextBox.TextProperty, binding);
-
-
sfernandez
Site Admin
- Posts: 3222
- Joined:
Re: [Unity] Null reference exception when binding set value
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.
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
- Posts: 43
- Joined:
Re: [Unity] Null reference exception when binding set value
No, I don't get any warning message in the console. I change my reference to strong reference, it solves the problem.
Thanks
Thanks
Who is online
Users browsing this forum: Google [Bot] and 7 guests