User avatar
ai_enabled
Posts: 221
Joined: 18 Jul 2013, 05:28
Contact:

Re: Unity: Do DependencyProperties / Control.SetBinding work

01 Mar 2015, 15:52

Just catch the same issue. Commented out dependency property in code and it works, so I'm sure the issue is same.
The workaround is seems to work, but in my case, controls must be instantiated via .NET Activator (I have a dozens for controls defined in Unity prefabs as full type name and instantiate them via .NET Activator).
If you have any ideas how to fix it - please tell me!

UPD. Calling Noesis.Extend.RegisterNativeType(type) where type is type of Control to instantiate helps to resolve this issue. But there are some other cases where I instantiate controls via direct constructor call...

UPD 2. Added logging to AddNativeType() in Noesis.Extend: Debug.LogWarning("NosisGUI: Register type " + info.Type.FullName);
It seems that some (maybe all) UserControls inheritors is not registered. If I register them manually, they work as expected.

UPD 3. Registering manually all UserControl inheritors helps, but the error still appears for some other classes - inheritors of DependencyObject. Registering manually them still not helps, as the new issues appears...
For example, calling VisualTreeHelper.GetChild() throws exception "Native type is not registered".
If I register manually all (absolutely all) inheritors from BaseComponent, I get this error:
"Exception System.ApplicationException: Can't add a 'Assets.UI.Menus.MainMenu' to a 'UIElementCollection'" which is absolutely nonsense...

UPD 4. Registered manually all used by the game UserControls, DependencyObjects and BaseComponents inheritors, it seems the game is running now. So the issue is that NoesisGUI 1.2.0 doesn't registering custom classes (which had [Extend] attribute on them in 1.0.x/1.1.x) automatically and workaround is to do it manually.
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
 
User avatar
ai_enabled
Posts: 221
Joined: 18 Jul 2013, 05:28
Contact:

Re: Unity: Do DependencyProperties / Control.SetBinding work

02 Mar 2015, 08:00

The game seems to run stable now, but there are still some non-registered controls - when I do recursive loop from LayoutRoot to all its childrens NoesisGUI throws "Native type is not registered" for some childs (method VisualTreeHelper.GetChild()).
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: Unity: Do DependencyProperties / Control.SetBinding work

02 Mar 2015, 20:34

I think I have a clue on what is happening thanks to all your comments.

Please try the following and let me know if solves your problems:

- Modify Assets/Plugins/NoesisGUI/Scripts/Core/NoesisExtend.cs line 985 by adding a new version of the RegisterNativeType function:
////////////////////////////////////////////////////////////////////////////////////////////////
public static IntPtr RegisterNativeType(Type type)
{
    return RegisterNativeType(type, true);
}

////////////////////////////////////////////////////////////////////////////////////////////////
public static IntPtr RegisterNativeType(Type type, bool registerDP)
{
  // ...

  if (type.GetTypeInfo().IsSubclassOf(typeof(Noesis.DependencyObject)))
  {
    if (registerDP)
    {
        RegisterDependencyProperties(type);
    }

    // ...
}
- Modify Assets/Plugins/NoesisGUI/Scripts/Proxies/DependencyPropertyExtend.cs line 12:
public static DependencyProperty Register(string propertyName, System.Type propertyType,
  System.Type ownerType, PropertyMetadata propertyMetadata)
{
  IntPtr ownerNativeType = Noesis.Extend.TryGetNativeType(ownerType);
  if (ownerNativeType == IntPtr.Zero)
  {
    // Force native type registration, but skip DP registration because we are inside
    // static constructor and DP are already being registered
    Noesis.Extend.RegisterNativeType(ownerType, false);
  }

  // ...
}
Hope this helps ;)


EDIT: There was a an error in the DependencyProperty.Register() code I posted, the the comparison should check == IntPtr.Zero instead. I fixed the code.
 
User avatar
ai_enabled
Posts: 221
Joined: 18 Jul 2013, 05:28
Contact:

Re: Unity: Do DependencyProperties / Control.SetBinding work

03 Mar 2015, 04:34

Thanks for suggestion, I've done it, but unfortunately it throws a new exception now:
Exception: System.TypeInitializationException: An exception was thrown by the type initializer for Assets.UI.Common.Controls.ScreenViewbox ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ApplicationException: Type 'Assets.UI.Common.Controls.ScreenViewbox' already registered
  at Noesis.ContentControl.Extend (System.Type type) [0x0001b] in c:\Projects\Games\AtomicTorch.GameEngine\NoesisGUI\Noesis\NoesisGUI\Scripts\Proxies\ContentControl.cs:152 

Noesis.Error.Check () (at c:/Projects/Games/AtomicTorch.GameEngine/NoesisGUI/Noesis/NoesisGUI/Scripts/Core/NoesisError.cs:21)
Noesis.UIRenderer.Noesis_CreateRenderer (IntPtr root) (at c:/Projects/Games/AtomicTorch.GameEngine/NoesisGUI/Noesis/NoesisGUI/Scripts/Core/NoesisUIRendererImports.cs:87)
Noesis.UIRenderer..ctor (Noesis.FrameworkElement content, Vector2 offscreenSize, UnityEngine.GameObject target) (at c:/Projects/Games/AtomicTorch.GameEngine/NoesisGUI/Noesis/NoesisGUI/Scripts/Core/NoesisUIRenderer.cs:61)
NoesisGUIPanel.OnEnable () (at c:/Projects/Games/AtomicTorch.GameEngine/NoesisGUI/Noesis/NoesisGUI/Scripts/NoesisGUIPanel.cs:172)
UnityEngine.Object:Instantiate(Object)
Loader:OnLevelWasLoaded() (at Assets/Scripts/Loader.cs:86)
Loader:Awake() (at Assets/Scripts/Loader.cs:46)
UPD. I've added check in RegisterNativeType() (at the beginning of method):
       {
                        // check if Native Type is already registered
		        IntPtr nativeType;
		        if (Noesis.Extend._managedTypes.TryGetValue(type, out nativeType))
		        {
			        return nativeType;
		        }
	        }
So now it throws exception:
Exception System.Exception: Unknown Unity extended type

   -------------------------stack-------------------------

  at Noesis.Error.Check () [0x00026] in c:\Projects\Games\AtomicTorch.GameEngine\NoesisGUI\Noesis\NoesisGUI\Scripts\Core\NoesisError.cs:21 

  at Noesis.DependencyProperty.Noesis_RegisterDependencyProperty_BaseComponent_ (IntPtr classType, IntPtr propertyName, IntPtr propertyType, IntPtr propertyMetadata) [0x0000b] in c:\Projects\Games\AtomicTorch.GameEngine\NoesisGUI\Noesis\NoesisGUI\Scripts\Proxies\DependencyPropertyExtend.cs:347 

  at Noesis.DependencyProperty.Register (System.String propertyName, System.Type propertyType, System.Type ownerType, Noesis.PropertyMetadata propertyMetadata) [0x00788] in c:\Projects\Games\AtomicTorch.GameEngine\NoesisGUI\Noesis\NoesisGUI\Scripts\Proxies\DependencyPropertyExtend.cs:188 

  at Assets.UI.Menus.MainMenu..cctor () [0x00000] in <filename unknown>:0 
UPD 2. It works now with modified code for DependencyPropertyExtend.Register method:
  public static DependencyProperty Register(string propertyName, System.Type propertyType,
            System.Type ownerType, PropertyMetadata propertyMetadata)
        {
			//IntPtr ownerNativeType = Noesis.Extend.TryGetNativeType(ownerType);
			//if (ownerNativeType != IntPtr.Zero)
			//{
				// Force native type registration, but skip DP registration because we are inside
				// static constructor and DP are already being registered
				Noesis.Extend.RegisterNativeType(ownerType, false);
			//}
              ...
        }
Thanks! I've removed workaround used for manual registration and use this fix.
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: Unity: Do DependencyProperties / Control.SetBinding work

03 Mar 2015, 10:07

I feel a bit silly looking now at the code of DependencyProperty.Register I posted :shock:

The correct code is this (I already fixed it in my previous post):
public static DependencyProperty Register(string propertyName, System.Type propertyType,
  System.Type ownerType, PropertyMetadata propertyMetadata)
{
  IntPtr ownerNativeType = Noesis.Extend.TryGetNativeType(ownerType);
  if (ownerNativeType == IntPtr.Zero)
  {
    // Force native type registration, but skip DP registration because we are inside
    // static constructor and DP are already being registered
    Noesis.Extend.RegisterNativeType(ownerType, false);
  }

  // ...
} 
 
User avatar
ai_enabled
Posts: 221
Joined: 18 Jul 2013, 05:28
Contact:

Re: Unity: Do DependencyProperties / Control.SetBinding work

04 Mar 2015, 06:13

Thanks for the fixed code, now it's working properly!
Regards!
AtomicTorch Studio Pte. Ltd. http://atomictorch.com

Who is online

Users browsing this forum: Bing [Bot] and 0 guests