Debugging crashes in Unity with NoesisGUI
Posted: 31 May 2013, 18:23
Hey guys,
I'm running into a crash manipulating one of my UIs, and I'm trying find out what the issue is. It looks like the crash happens right after calling ScrollViewer.ScrollToHorizontalOffset. This makes me curious about a couple things.
First, is there anyway to shield Unity from errors in NoesisGUI? Right now a single binding or API getting invalid input takes down the entire editor process, which makes iteration a bit of a pain.
Second, I noticed a log file in the bin folder of the SDK. Is that from the runtime of NoesisGUI? I tried to get some information from that about my crash, but it doesn't look like it's plain text file. Do you have a custom application for viewing these logs? If so, are there plans to include this with the SDK so we can view them?
Here is stack trace that shows up in the Unity crash reporter logs:
XAML:
ScrollViewDragger.cs:
I'm running into a crash manipulating one of my UIs, and I'm trying find out what the issue is. It looks like the crash happens right after calling ScrollViewer.ScrollToHorizontalOffset. This makes me curious about a couple things.
First, is there anyway to shield Unity from errors in NoesisGUI? Right now a single binding or API getting invalid input takes down the entire editor process, which makes iteration a bit of a pain.
Second, I noticed a log file in the bin folder of the SDK. Is that from the runtime of NoesisGUI? I tried to get some information from that about my crash, but it doesn't look like it's plain text file. Do you have a custom application for viewing these logs? If so, are there plans to include this with the SDK so we can view them?
Here is stack trace that shows up in the Unity crash reporter logs:
Code: Select all
(0x28333960) (Noesis): (filename not available): Noesis::Gui::ScrollContentPresenter::SetHorizontalOffset + 0x0
(0x1FAFC416) (Mono JIT code): (filename not available): (wrapper delegate-invoke) Noesis.NoesisUnityPINVOKE/Point_SetXDelegate:invoke_void__this___HandleRef_single (System.Runtime.InteropServices.HandleRef,single) + 0x1ae (1FAFC268 1FAFC42D) [07EB6BD0 - Unity Child Domain] + 0x0
(0x1FAFD7E0) (Mono JIT code): (filename not available): Noesis.NoesisUnityPINVOKE:ScrollViewer_ScrollToHorizontalOffset (System.Runtime.InteropServices.HandleRef,single) + 0x58 (1FAFD788 1FAFD7F7) [07EB6BD0 - Unity Child Domain] + 0x0
(0x1FAFD762) (Mono JIT code): (filename not available): Noesis.ScrollViewer:ScrollToHorizontalOffset (single) + 0x52 (1FAFD710 1FAFD779) [07EB6BD0 - Unity Child Domain] + 0x0
(0x1FAFA92A) (Mono JIT code): (filename not available): ScrollViewDragger:OnPreviewMouseMove (Noesis.BaseComponent,Noesis.MouseEventArgs) + 0x26a (1FAFA6C0 1FAFA941) [07EB6BD0 - Unity Child Domain] + 0x0
(0x1FAFA3AC) (Mono JIT code): (filename not available): Noesis.UIElement:RaisePreviewMouseMove (intptr,intptr) + 0xbc (1FAFA2F0 1FAFA3C3) [07EB6BD0 - Unity Child Domain] + 0x0
(0x1A480170) (Mono JIT code): (filename not available): (wrapper native-to-managed) Noesis.UIElement:RaisePreviewMouseMove (intptr,intptr) + 0xa0 (1A4800D0 1A480189) [07EB6BD0 - Unity Child Domain] + 0x0
(0x28481B84) (Noesis): (filename not available): CSharp_BindEventTimelineCompleted + 0x134
(0x28374659) (Noesis): (filename not available): Noesis::Gui::UIElement::TunnelingEvent + 0x49
(0x28371FB6) (Noesis): (filename not available): Noesis::Gui::UIElement::RaiseEvent + 0x36
(0x282F6D45) (Noesis): (filename not available): Noesis::Gui::Mouse::Move + 0x95
(0x284829E9) (Noesis): (filename not available): Noesis_MouseMove + 0x19
(0x1FAF67C9) (Mono JIT code): (filename not available): (wrapper delegate-invoke) Noesis.UIRenderer/MouseMoveDelegate:invoke_void__this___intptr_single_single (intptr,single,single) + 0x159 (1FAF6670 1FAF67E0) [07EB6BD0 - Unity Child Domain] + 0x0
(0x1FAF6653) (Mono JIT code): (filename not available): No
Code: Select all
<Border xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
<Border.Resources>
<ResourceDictionary>
<!-- ListBox Style -->
<Style TargetType="{x:Type ListBox}">
<Setter Property="UseLayoutRounding" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="Foreground" Value="Transparent"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border
Name="Border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="1"
CornerRadius="2"
UseLayoutRounding="True">
<ScrollViewer
x:Name="Scroller"
Margin="{TemplateBinding Padding}"
Focusable="false"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
CanContentScroll="{TemplateBinding ScrollViewer.CanContentScroll}">
<ItemsPresenter UseLayoutRounding="{TemplateBinding UseLayoutRounding}"/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="SelectionItem" TargetType="{x:Type ListBoxItem}">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<DockPanel LastChildFill="True" Width="128" Height="128" Margin="8,0,0,0">
<ContentPresenter DockPanel.Dock="Bottom" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Border Background="#F2B600">
<TextBlock Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="32">?</TextBlock>
</Border>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
</ResourceDictionary>
</Border.Resources>
<ListBox x:Name="MyList">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem Style="{StaticResource SelectionItem}" Content="1" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="2" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="3" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="4" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="5" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="1" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="2" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="3" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="4" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="5" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="1" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="2" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="3" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="4" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="5" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="1" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="2" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="3" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="4" />
<ListBoxItem Style="{StaticResource SelectionItem}" Content="5" />
</ListBox>
</Border>
Code: Select all
using UnityEngine;
using Noesis;
public class ScrollViewDragger : MonoBehaviour
{
public float m_friction = 0.2f;
// Use this for initialization
void Start()
{
m_scrollTarget = new Point();
m_scrollStartPoint = new Pointi();
m_scrollStartOffset = new Point();
m_velocity = new Point();
m_previousPos = new Pointi();
var gui = GetComponent<NoesisGUIPanel>();
m_grid = gui.GetRoot<Grid>();
m_picker = m_grid.FindName<ListBox>("MyList");
if (m_picker != null)
{
var template = m_picker.GetTemplate();
var scroller = template.FindName("Scroller");
m_scrollViewer = scroller.As<ScrollViewer>();
m_picker.PreviewMouseDown += OnPreviewMouseDown;
m_picker.PreviewMouseMove += OnPreviewMouseMove;
m_picker.PreviewMouseUp += OnPreviewMouseUp;
}
}
void OnPreviewMouseUp(BaseComponent sender, MouseButtonEventArgs e)
{
Debug.Log("OnPreviewMouseUp: IsMouseCaptured=" + m_grid.GetIsMouseCaptured());
if (m_mouseCaptured)//m_grid.GetIsMouseCaptured())
{
m_mouseCaptured = false;
//m_grid.ReleaseMouseCapture();
Debug.Log("OnPreviewMouseUp: MouseCaptureReleased!");
}
}
void OnPreviewMouseDown(BaseComponent sender, MouseButtonEventArgs e)
{
Debug.Log("OnPreviewMouseDown: mouse over=" + m_picker.GetIsMouseOver());
if (m_picker.GetIsMouseOver())
{
m_scrollStartPoint = m_picker.GetMouse().GetPosition();
m_scrollStartOffset.x = m_scrollViewer.GetHorizontalOffset();
m_scrollStartOffset.y = m_scrollViewer.GetVerticalOffset();
m_mouseCaptured = true;
//if (m_grid.CaptureMouse())
// Debug.Log("OnPreviewMouseDown: Mouse captured!");
}
}
void OnPreviewMouseMove(BaseComponent sender, MouseEventArgs e)
{
//Debug.Log("OnPreviewMouseMove: IsMouseCaptured=" + m_grid.GetIsMouseCaptured());
if (m_mouseCaptured)//m_grid.GetIsMouseCaptured())
{
Point currentPoint = e.position;
Point delta = new Point(m_scrollStartPoint.x - currentPoint.x, m_scrollStartPoint.y - currentPoint.y);
m_scrollTarget.x = m_scrollStartOffset.x + delta.x;
m_scrollTarget.y = m_scrollStartOffset.y + delta.y;
Debug.Log(string.Format("OnPreviewMouseMove: scrollTarget.x={0}", m_scrollTarget.x));
m_scrollViewer.ScrollToHorizontalOffset(Mathf.Clamp(m_scrollTarget.x, 0f, m_scrollViewer.GetExtentWidth() - m_scrollViewer.GetViewportWidth()));
}
}
// Update is called once per frame
void Update()
{
if (m_mouseCaptured)//m_grid.GetIsMouseCaptured())
{
Pointi currentPos = m_picker.GetMouse().GetPosition();
//Vector3 currentPos = Input.mousePosition;
m_velocity.x = m_previousPos.x - currentPos.x;
m_velocity.y = m_previousPos.y - currentPos.y;
m_previousPos = currentPos;
}
else
{
if (!Mathf.Approximately(m_velocity.x, 0.0f))
{
float friction = 1.0f - Mathf.Clamp(m_friction, 0f, 1f);
m_scrollViewer.ScrollToHorizontalOffset(Mathf.Clamp(m_scrollTarget.x, 0f, m_scrollViewer.GetExtentWidth() - m_scrollViewer.GetViewportWidth()));
m_scrollTarget.x += m_velocity.x;
m_velocity.x *= friction;
m_velocity.y *= friction;
}
}
}
ListBox m_picker;
Pointi m_scrollStartPoint;
Point m_scrollStartOffset;
Point m_scrollTarget;
Point m_velocity;
Pointi m_previousPos;
Grid m_grid;
bool m_mouseCaptured;
ScrollViewer m_scrollViewer;
}