View Issue Details

IDProjectCategoryView StatusLast Update
0001538NoesisGUIUnitypublic2019-09-27 17:47
Reporterstonstad Assigned Tosfernandez  
PrioritynormalSeveritycrash 
Status resolvedResolutionfixed 
Product Version2.2.3 
Target Version2.2.5Fixed in Version2.2.5 
Summary0001538: Unity Crash on Project Load
Description

I'm getting a repeatable crash on Unity editor startup ... during project load. It appears to be related to an assertion from Noesis.

Editor.Log:

Assertion failed on expression: 'g_ThreadedGfxDevice'
Noesis.PropertyMetadata:.ctor(Object) (at Assets\NoesisGUI\Plugins\API\Proxies\PropertyMetadataExtend.cs:33)
StellarConquest.Presentation.Unity.UI.ViewboxGridControl:.cctor() (at Assets\User Interface\Controls\Viewbox Grid Control\ViewBoxGridControl.cs:10)

[C:\buildslave\unity\build\Runtime/GfxDevice/GfxDevice.cpp line 148]
(Filename: Assets/NoesisGUI/Plugins/API/Proxies/PropertyMetadataExtend.cs Line: 33)

The offending line of code is this:
public static readonly DependencyProperty ScalingEnabledProperty = DependencyProperty.Register("ScalingEnabled", typeof(bool), typeof(ViewboxGridControl), new PropertyMetadata(true));

If I move the line of code the stack trace line number changes, too. So I think this is the line.

I am attaching log, dump files, and the Noesis user control that seems to cause the crash. I am going to look to see if I can stop the crash. I might be doing something crazy -- I'll take a look. I thought this might be useful since it's a fatal editor crash.

Attached Files
ViewBoxGridControl.cs (2,102 bytes)   
using Noesis;
using System.Collections.Generic;
using Vector2 = UnityEngine.Vector2;
using Grid = Noesis.Grid;

namespace StellarConquest.Presentation.Unity.UI
{
    public partial class ViewboxGridControl : Grid
    {
        public static readonly DependencyProperty ScalingEnabledProperty = DependencyProperty.Register("ScalingEnabled", typeof(bool), typeof(ViewboxGridControl), new PropertyMetadata(true));

        public static readonly List<Vector2> AspectRatios = new List<Vector2>()
        {
            new Vector2(7680, 4320), // 0
            new Vector2(3840, 2160), // 1
            new Vector2(2560, 1440), // 2
            new Vector2(1920, 1080), // 3
            new Vector2(1600, 900),  // 4
            new Vector2(1366, 768),  // 5
            new Vector2(1280, 720),  // 6
            new Vector2(1152, 648),  // 7 
            new Vector2(1024, 576),  // 8
        };

        public static int DefaultAspectRatioIndex = 5;

        public ViewboxGridControl()
        {
            Loaded += (sender, e) =>
            {

                if (PlayerPreferences.Instance != null)
                    SetScale(PlayerPreferences.Instance.UserInterfaceSize);
                else
                    SetScale(DefaultAspectRatioIndex);
            };
        }

        public void SetScale(int index)
        {
            if (ScalingEnabled)
            {
                Width = AspectRatios[index].x;
                Height = AspectRatios[index].y;
            }
        }

        public Vector2 GetViewboxScale()
        {
            Viewbox viewbox = this.Parent as Viewbox;
            if (viewbox == null)
                return new Vector2(1, 1);
            float x = viewbox.ActualWidth / ActualWidth;
            float y = viewbox.ActualHeight / ActualHeight;

            return new Vector2(x, y);
        }

        public bool ScalingEnabled
        {
            get { return (bool)GetValue(ScalingEnabledProperty); }
            set { SetValue(ScalingEnabledProperty, value); }
        }
    }
}
ViewBoxGridControl.cs (2,102 bytes)   
ViewboxGridControl.xaml (401 bytes)   
<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
    x:Class="ViewboxGridControl"
    d:DesignWidth="1280" d:DesignHeight="720">
</UserControl>
ViewboxGridControl.xaml (401 bytes)   
PlatformAny

Activities

stonstad

stonstad

2019-08-16 00:33

reporter   ~0005923

Commenting out the dependency property and turning the property setter/getter to no-ops resolves the behavior. I'm investigating further...

stonstad

stonstad

2019-08-16 00:45

reporter   ~0005924

Last edited: 2019-08-16 00:59

Things I tried to prevent crash that does not work
1) comment out all code in constructor, including loaded event.
2) make get/set no-op.
3) rename to ScalingEnabledProperty to ScalingEnabled2Property.
4) use different constructor for dependency property to avoid using PropertyMetadata(true) parameter. Result: crash occurs in DependencyPropertyExtend, Line 13 instead.

Things I tried that does prevent the crash
1) comment out the dependency property, ScalingEnabledProperty. See works.cs for what code looks like that does work every time.

What is strange is that this worked fine for several days (2+ weeks?) and now it is happening every time I load/start Unity. My only workaround right now is to remove the DependencyProperty ScalingEnabledProperty.

Works.cs (2,243 bytes)   
using Noesis;
using System.Collections.Generic;
using UnityEngine;
using Grid = Noesis.Grid;
using Vector2 = UnityEngine.Vector2;

namespace StellarConquest.Presentation.Unity.UI
{
    public partial class ViewboxGridControl : Grid
    {
        //public static readonly DependencyProperty ScalingEnabledProperty = DependencyProperty.Register("ScalingEnabled", typeof(bool), typeof(ViewboxGridControl), new PropertyMetadata(true));

        public static readonly List<Vector2> AspectRatios = new List<Vector2>()
        {
            new Vector2(7680, 4320), // 0
            new Vector2(3840, 2160), // 1
            new Vector2(2560, 1440), // 2
            new Vector2(1920, 1080), // 3
            new Vector2(1600, 900),  // 4
            new Vector2(1366, 768),  // 5
            new Vector2(1280, 720),  // 6
            new Vector2(1152, 648),  // 7 
            new Vector2(1024, 576),  // 8
        };

        public static int DefaultAspectRatioIndex = 5;

        public ViewboxGridControl()
        {
            Loaded += (sender, e) =>
            {
                if (PlayerPreferences.Instance != null)
                    SetScale(PlayerPreferences.Instance.UserInterfaceSize);
                else
                    SetScale(DefaultAspectRatioIndex);
            };
        }

        public void SetScale(int index)
        {
            if (ScalingEnabled)
            {
                Width = AspectRatios[index].x;
                Height = AspectRatios[index].y;
            }
        }

        public Vector2 GetViewboxScale()
        {
            Viewbox viewbox = this.Parent as Viewbox;
            if (viewbox == null)
                return new Vector2(1, 1);
            float x = viewbox.ActualWidth / ActualWidth;
            float y = viewbox.ActualHeight / ActualHeight;

            return new Vector2(x, y);
        }

        public bool ScalingEnabled
        {
            get
            {
                //return (bool)GetValue(ScalingEnabledProperty);
                return false;
            }
            set
            {
                //SetValue(ScalingEnabledProperty, value);
            }
        }
    }
}
Works.cs (2,243 bytes)   
stonstad

stonstad

2019-08-16 01:00

reporter   ~0005926

Maybe bool needs to be added as a valid property type?

sfernandez

sfernandez

2019-08-21 14:33

manager   ~0005932

Last edited: 2019-08-21 14:39

It seems a problem with the loading of Noesis library while starting Unity.

Could you please try the following code for your ViewboxGridControl?

using Noesis;
using System.Collections.Generic;
using Vector2 = UnityEngine.Vector2;
using Grid = Noesis.Grid;

namespace StellarConquest.Presentation.Unity.UI
{
public partial class ViewboxGridControl : Grid
{
static ViewboxGridControl()
{
Noesis.GUI.Init();

        ScalingEnabledProperty = DependencyProperty.Register("ScalingEnabled", typeof(bool), typeof(ViewboxGridControl), new PropertyMetadata(true));
    }

    public static readonly DependencyProperty ScalingEnabledProperty = null; // DependencyProperty.Register("ScalingEnabled", typeof(bool), typeof(ViewboxGridControl), new PropertyMetadata(true));
    ...
}

}


If this fixes the problem then I need to understand why this class is used without Noesis being initialized. Are you using that class from code in a MonoBehavior?

stonstad

stonstad

2019-08-21 20:56

reporter   ~0005933

OK, perfect. Your analysis is spot on. The change worked, and helped me identify the cause.

The class contains a static property, ViewBoxGridControl.DefaultAspectRatioIndex. MonoBehavior code referred to this variable which, when accessed, caused the static initializer for ViewBoxGridControl to be called, which includes initialization of the dependency property. I moved the constant to a better location and all is well. Candidate for closure -- thank you for helping me understand this.

jsantos

jsantos

2019-08-22 01:25

manager   ~0005934

Thanks for the feedback stonstad.

I wonder if we could detect this scenario sergio, like having asserts if Noesis API is trying to be used without initialization. Not sure how many entries and how many asserts would be needed. And we don't want this code to be present in the non-editor build.

sfernandez

sfernandez

2019-08-23 01:13

manager   ~0005937

Yes, we should be more robust against this scenario.
I'll move this ticket for the next release so we can think about how to solve it.

Issue History

Date Modified Username Field Change
2019-08-16 00:30 stonstad New Issue
2019-08-16 00:30 stonstad File Added: Crash_2019-08-15_222455133.zip
2019-08-16 00:30 stonstad File Added: ViewBoxGridControl.cs
2019-08-16 00:30 stonstad File Added: ViewboxGridControl.xaml
2019-08-16 00:33 stonstad Note Added: 0005923
2019-08-16 00:45 stonstad File Added: Works.cs
2019-08-16 00:45 stonstad Note Added: 0005924
2019-08-16 00:54 stonstad Note Edited: 0005924
2019-08-16 00:59 stonstad Note Edited: 0005924
2019-08-16 01:00 stonstad Note Added: 0005926
2019-08-19 16:41 sfernandez Assigned To => sfernandez
2019-08-19 16:41 sfernandez Status new => assigned
2019-08-19 16:41 sfernandez Product Version 2.2.4 => 2.2.3
2019-08-19 16:41 sfernandez Target Version => 2.2.4
2019-08-19 16:41 sfernandez Description Updated
2019-08-21 14:33 sfernandez Status assigned => feedback
2019-08-21 14:33 sfernandez Note Added: 0005932
2019-08-21 14:39 sfernandez Note Edited: 0005932
2019-08-21 20:56 stonstad Note Added: 0005933
2019-08-21 20:56 stonstad Status feedback => assigned
2019-08-22 01:25 jsantos Note Added: 0005934
2019-08-23 01:13 sfernandez Target Version 2.2.4 => 2.2.5
2019-08-23 01:13 sfernandez Note Added: 0005937
2019-09-27 17:47 sfernandez Status assigned => resolved
2019-09-27 17:47 sfernandez Resolution open => fixed
2019-09-27 17:47 sfernandez Fixed in Version => 2.2.5
2025-10-10 13:29 jsantos Category Unity3D => Unity