DanRP
August 29, 2013, 4:21pm
1
Hello,
I’m just getting started with exporting for Windows Store / Windows 8 and I’m getting a run-time error that I can’t figure out. I’ve included the code below. Note: I’m using the 2D Toolkit add-on.
GameObject oGameObject = null;
Texture2D oTexture = null;
oTexture = Resources.Load( pFilename, typeof(Texture2D) ) as Texture2D;
if (!ReferenceEquals(oTexture, null)) {
Rect tSize = new Rect(0, 0, oTexture.width, oTexture.height);
Vector2 tAnch = new Vector2( oTexture.width * OffsetX, oTexture.height * (1.0f - OffsetY));
tk2dSpriteCollectionSize tkCollectionSize = tk2dSpriteCollectionSize.ForTk2dCamera();
oGameObject = tk2dSprite.CreateFromTexture( oTexture, tkCollectionSize, tSize, tAnch );
oSprite = oGameObject.GetComponent<tk2dSprite>();
}
I’m getting a the error “Exception: Object reference not set to an instance of an object.” on this line:
oGameObject = tk2dSprite.CreateFromTexture( oTexture, tkCollectionSize, tSize, tAnch );
I believe that the problem is with the oTexture object.
Here’s what I know:
When I Debug.Log my oTexture object, it shows as “BaseObject: NotAvailableDuringDebugging”
I know the resource is being loaded because the width and height properties are correct (100)
This code works perfectly when exporting to android and iOS
It seems that something is wrong with my oTexture object when exporting for Windows Store…
Can anyone help me figure out why this code is failing?
Thanks!
Dan
DanRP
August 29, 2013, 9:26pm
3
tk2dSprite is a 2D sprite object that is part of the 2D Toolkit add-on.
That means CreateFromTexture belongs to 2D sprite object, do you know how it’s implemented?
DanRP
August 29, 2013, 11:56pm
5
I do have the source for the CreateFromTexture function…
Upon a closer look at the log file, this is the full error:
Exception: Object reference not set to an instance of an object.
InnerException:
AdditionalInfo:
at tk2dSprite.Awake() in c:\data\Games\StackTheStatesUnity\Assets\TK2DROOT\tk2d\Code\Sprites\tk2dSprite.cs:line 25
at tk2dSprite.UnityFastInvoke_Awake()
Here’s the code around line 25:
24: mesh = new Mesh();
25: mesh.hideFlags = HideFlags.DontSave;
26: GetComponent<MeshFilter>().mesh = mesh;
It’s almost as if the “mesh = new Mesh();” line maybe doesn’t produce a valid instance of Mesh?
Try to debug it with Visual Studio, you can also enable all exceptions in Debug->Exceptions, and continue until you hit that exception
DanRP
August 30, 2013, 1:47am
7
I’ll see what I can do. I haven’t been able to setup Visual Studio to set breakpoints in my code. I tried following the instructions below, but haven’t had any luck.
https://docs.unity3d.com/Documentation/Manual/windowsstore-debugging.html
I went to Debug->Exceptions and set it to stop on all exceptions. Execution did stop at a few places, but not in my code…
You should have hit “Object reference not set to an instance of an object.” unless your bug is not deterministic
DanRP
September 3, 2013, 7:12pm
9
It looks like this bug is specific to those using the 2D Toolkit add-on. I’ll continue discussion of this issue on their forum.
http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,2518.0.html
(Thanks Tomas1856 for your initial help!)
Dan
Tomas,
This is happening because RequireComponent isn’t creating the prerequisite components (MeshRenderer MeshFilter) when running on Windows Store builds. It seems to work on all other builds (Web, Pc, iOS and Android). Is this expected behaviour? If not I’ll file a bug.