2D Toolkit Forum

2D Toolkit => Support => Topic started by: mterlecki on January 31, 2015, 12:05:48 am

Title: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: mterlecki on January 31, 2015, 12:05:48 am
Hi,
 I have my project built and running fine on a PC. I copied the whole project over to a MAC and when I open it - I get hundreds of errors - one for each sprite:

NullReferenceException: Object reference not set to an instance of an object
tk2dSpriteCollectionData.get_inst () (at Assets/TK2DROOT/tk2d/Code/Sprites/tk2dSpriteCollectionData.cs:555)
tk2dBaseSprite.Awake () (at Assets/TK2DROOT/tk2d/Code/Sprites/tk2dBaseSprite.cs:909)
tk2dSprite.Awake () (at Assets/TK2DROOT/tk2d/Code/Sprites/tk2dSprite.cs:21)

I found that if I open the sprite collection and rebuild it - it works ok.

Do I have to rebuild all my spritecollections each time I move from the MAC to a PC?
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: unikronsoftware on January 31, 2015, 12:18:09 am
We use it cross platform all the time with no issues. How are you moving the project? Do you have meta files on / version control? Are you ensuring the libraries folder isn't copied?
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: mterlecki on January 31, 2015, 04:21:37 pm
Hi,
  I fixed all the errors on the MAC by opening each sprite collection and re-commiting them. However, when I went back to the PC - I got the same errors.

 The project is moved back and forth via version control - Perforce.

I have Hidden Mete Files selected as my version control mode in the editor settings.

No - the library folder is not copied.

-Mike
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: unikronsoftware on February 02, 2015, 12:12:17 am
Are the meta files being submitted?
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: mterlecki on February 02, 2015, 03:36:40 pm
Yes - the meta files are checked-in.
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: unikronsoftware on February 02, 2015, 04:04:59 pm
Hmm thats weird, what version of tk2d & unity are you using, and does the issue happen both ways? (do you have issues if you open a mac project on pc?)

we use it cross platform all the time, and I know many others do too. We'll need to figure out why you're having issues, as there shouldn't really be any issues ilke this.
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: mterlecki on February 02, 2015, 05:36:55 pm
Yes - it happens both ways.
The first time it happened on the MAC - I saw that all my sprites were missing their Material references, so I opened each Sprite Collection and re-committed it. (Pressed the Commit button).
That fixed all of the problems on the MAC. Then I checked-in all those files and when I synced to the PC and opened the project I got the exact same errors. Opening each Sprite Collection and re-committing once again fixed the problem, but obviously this isn't a viable solution.

My project is set for 2 platforms (1x and 2x). I did notice that in the 2D ToolKit preferences dialog, under platform - nothing was selected, so I selected 1x.

Also as a rule of thumb, when I add a project to Perforce, I add the entire Assets directory. After reading a piece about using 2D Toolkit and version control - I saw that there were many files used by 2D Toolkit, that should NOT be added to version control (i.e. -tk2d.asset, -tk2d.asset.meta and all of the files in the Resources/tk2d directory).

I removed all of these files from version control, deleted the library directory, opened Unity and rebuilt the 2D Toolkit indexes. This was on the PC. Then I checked-in, checked-out on the MAC and did the same - no help. All sprites are missing their material references.

I'm at a loss for what to try next.
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: unikronsoftware on February 02, 2015, 06:00:41 pm
Ok... if you have platforms, that narrows it down slightly. Have you tried restarting unity once it is broken?
Can you create a minimal repro case for this? Ideally 1 scene and one simple sprite collection, should be able to track it down if I can get it to consistenly break over here.
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: mterlecki on February 02, 2015, 08:25:29 pm
So I copied my project to a separate directory and paired it down to a single scene and 2 sprite collections. Not surprisingly, after doing this the problem disappeared.

I don't know if this helps - but when I initially started the project, I had no platforms. It wasn't until later on that I started using multiple resolution textures. At that point I turned on platform support (1x,2x) for each of the sprite collections.
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: unikronsoftware on February 02, 2015, 11:08:19 pm
Does just copying it into a separate directory make a difference? Before you delete stuff.
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: mterlecki on February 04, 2015, 05:49:35 pm
Yes - strangely it does. I copied it locally to a shared location on my pc and then from there to the MAC and it works.
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: mterlecki on February 05, 2015, 01:51:42 am
Copying the project directory over to a MAC works fine - checking it to Perforce and then Checking it out on the MAC breaks all of the Material references in all the sprites. It appears that Perforce is doing something to the files.

I have my Serialization Mode set to "Force Text" - this leads me to believe "Line Endings" in the text files may be the culprit.

Have you transitioned from MAC->PC using a version control system?
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: unikronsoftware on February 05, 2015, 04:30:32 pm
Yes, we do it on a daily basis, the 2D Toolkit repo itself is in svm - we use PlasticSCM. I haven't used perforce with unity though.
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: mterlecki on February 05, 2015, 09:57:42 pm
Do you have any other suggestions on how to correct this issue?
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: unikronsoftware on February 05, 2015, 10:48:00 pm
I don't know what the the problem - if its due to line endings, then there must be something in the version control system to normalise that? Either that or not everything that is needed is version controlled. You could do a diff between the 2 folders to see any diff between a working and broken project.
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: mterlecki on February 08, 2015, 03:06:49 pm
I have located the  problem and mostly fixed it. There were several files missing from Perforce - somehow they did not get added. However I still have a problem that after I do a build - some of my textures turn "Hot Pink" because they have lost the material reference. "Rebuild all sprites" fixes the issue.

But that does lead to another question. I have two platforms enabled (1x,2x), however when I look in sprite collection's data folder - there are 4 additional folders - I was expecting 2.

For example I have a sprite collection for my title screen name TitleBGSprites.

2DToolkit generated a folder by the name of "TitleBGSprites Data", inside this folder are 4 additional folders; "TitleBGSprites@1x 1 Data", "TitleBGSprites@1x Data", "TitleBGSprites@2x 1 Data" and "TitleBGSprites@2x Data"

Can you explain why there are 4 and what is in each one?
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: unikronsoftware on February 08, 2015, 09:11:23 pm
It looks like leftover files from a failed build.

Imagine a situation when the original files are there in TitleBGSprites@1x Data, at some point it didn't copy across properly and if a build was done at that point, it'd try to write into that directory again - the code then appends a "1" to the name to avoid name collisions, and creates the second folder there. In this case it sounds like you probably have a TitleBGSprites@1x 1.prefab in there too.
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: mterlecki on February 08, 2015, 10:46:06 pm
Yes I have a prefab file as well.
So the "TitleBGSprites@1x 1 Data" file should not be there. What is the safest way to delete these extra files?
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: unikronsoftware on February 09, 2015, 10:30:58 am
You need to find out which ones are used. the easiest way I guess is to select the sprite collection in the inspector, switch the inspector to debug mode and find the referenced data objects. You'll have to dig trough a couple levels of data there but you can follow the entire trail using the data objecr
Title: Re: Transfer Sprite Collections from PC to MAC results in NullReference error
Post by: mterlecki on February 10, 2015, 04:04:08 pm
I was able to use the GUID references in the sprite collection and compare them with the ones inside the sprite data ".meta" files and determine which sets of data were actually being used.
I deleted the others without issue. Everything seems to be working correctly now - thank you for you assistance.