Here is the crash log ( short ):
2013-04-24 19:56:24 +0000 Memotion Unhandled managed exception: Object reference not set to an instance of an object (System.NullReferenceException)
at Pipedream.UI.UIElement.set_Size (Vector2 value) [0x00000] in :0
at Pipedream.UI.StageLayer..ctor (Pipedream.ComponentID id) [0x00000] in :0
at Pipedream.UI.Stage.CreateLayer (Pipedream.ComponentID id) [0x00000] in :0
Actually the code of the constructor looks like this:
internal StageLayer(ComponentID id)
: base(id, ComponentLayer.System)
{
base.Size = ApplicationBase.Instance.ScreenSize;
ApplicationBase.Instance.PropertyChanged += HandlePropertyChanged;
}
And the property looks like this:
public virtual Vector2 Size
{
get
{
return _Size;
}
set
{
Vector2 old = _Size;
if (SetData(SizeDeclaration, value, ref _Size, Invalidate))
{
CompareUpdate(WidthDeclaration, _Size.X, old.X);
CompareUpdate(HeightDeclaration, _Size.Y, old.Y);
}
}
}
Well the Vector2
is a struct and cannot be null
. Also this code works perfectly on desktop. I can't think of any reason why this code should crash but it also does not on iOS simulator, only on iOS-device ( I currently have no device so i'm not able to debug it directly ).
I start some tasks before this code is called, but they using their own data and cannot conflict with the current data, even then there should not be any NullReferenceException
.
Edit
It turns out that the exception is thrown when the CompareUpdate
-method should be called. Anyway i thought that non virtual generic methods should not make any issues?
protected Boolean CompareUpdate<T>(DependencyProperty property, T newValue, T oldValue)
{
if (!Object.Equals(newValue, oldValue))
{
ForceUpdate(property, newValue, oldValue);
return true;
}
return false;
}
Edit 2
After some more test cases i found out that that this might be a real compiler issue. The following test fails:
Log.Info(_Size.X.ToString()); // _Size is still a struct
With this exception:
System.NullReferenceException: Object reference not set to an instance of an object
at System.Single.ToString () [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Single.cs:260
at Pipedream.UI.UIElement.set_Size (Vector2 value) [0x00031] in C:\WORK\00_PROJECTS\16 Pipedream\00_FRAMEWORK\trunk\Pipedream\UI\UIElement.cs:332
If i change the original code to the following there is also no error:
Vector2 old = _Size;
if (SetData(SizeDeclaration, value, ref _Size, Invalidate))
{
CompareUpdate(WidthDeclaration, 0f, 0f);
CompareUpdate(HeightDeclaration, 0f, 0f);
}
This error also occurs when i remove the SetData
-method, so this can't be the error cause. I've checked the this reference so the stack seems to be ok, but if i try to access the _Size
s variable X
and try to print it to the console the NullReferenceException occurs again.