Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - alexkring

Pages: [1]
1
NGUI Version: 3.7.4 (looking at the code, it looks like it also exists in 3.9)

Bug: 'panel' is null, inside UIDrawCall.cs, in the function UpdateGeometry, in this block of code:

  1. // Non-automatic render queues rely on Z position, so it's a good idea to trim everything
  2.                                 if (!trim && panel.renderQueue != UIPanel.RenderQueue.Automatic)
  3.                                         trim = (mMesh == null || mMesh.vertexCount != verts.buffer.Length);

Temporary Fix: Add the following code at the top of the UpdateGeometry function in UIDrawCall.cs

  1. if ( panel == null )
  2.                 {
  3.                         return;
  4.                 }

This would occasionally happen in our game, when the user would press a UI button that restarted the game. In the case of the bug, the OnDisable is called on the UIDrawCall object (since the game is closing), which sets panel to null. Then the parent panel calls UpdateGeometry in the same frame, which originates from the LateUpdate function of the panel.

I consider the fix above a hack, because it doesn't actually fix all of the potential bugs, it only fixes the bug I described. The real fix should be this: all of the public functions check to see if the object is disabled (including the public static functions), and respond to this state accordingly. In most cases, the functions should not be called when the object is disabled.

Would it be possible to get a real fix for this, in a future release? Thanks!

2
NGUI 3 Support / Re: UIAtlasMaker exception
« on: July 31, 2014, 06:41:18 PM »
Here is the main block of code for creating the temporary gameobject.

  1.    // I needed to assign the temporary texture to a GameObject, because otherwise the texture will be unloaded
  2.            // whenever AssetDatabase.Refresh is called (this triggers a call to Resources.UnloadUnusedAssets). We
  3.            // need for this texture to be in memory while creating atlases in the editor.
  4.            sprite.temporaryGameObject = new GameObject(sprite.name);
  5.            MeshRenderer mr = sprite.temporaryGameObject.AddComponent<MeshRenderer>();
  6.            Material tempMaterial = new Material( NGUISettings.atlas.spriteMaterial );
  7.            mr.sharedMaterial = tempMaterial;
  8.            mr.sharedMaterial.SetTexture("_MainTex", sprite.tex);
  9.  

3
NGUI 3 Support / Re: UIAtlasMaker exception
« on: July 29, 2014, 12:27:31 PM »
I've been able to reproduce this bug, and I have a temporary fix.

Here are my repro steps:
1. Create an atlas with about 70 100x100 icons, with the following options checked in the Atlas Maker
- Trim Alpha
- Truecolor
- Force Square
This should result in a 2048x2048 texture that is about half-full.
2. Select all of the icons again, and hit the "Add/Update" button to update them all.
3. Observe errors.

The bug is difficult to reproduce because it is dependent on your computer hardware. More specifically, it is dependent upon how long the garbage collection takes.

The problem is this: NGUI is creating temporary textures during atlas creation. Unity is destroying these textures when AssetDatabase.Refresh is called (ex: through NGUIEditorTools.ImportTexture), since this triggers a Resources.UnloadUnusedAssets. The temporary textures will then be unloaded from memory, and set to null.

My solution was to create a temporary gameobject when a temporary texture is created inside the CreateSprites function. I also create a temporary material, and assign the temp texture to this material. When ReleaseSprites is called, I destroy that gameobject.

Here is another helpful tip for more clearly understanding this bug. Go to around line 665 of the UIAtlasMaker.cs file, within this function 

UpdateAtlas (List<Texture> textures, bool keepSprites)

Right after the call to CreateSprites, iterate through each SpriteEntry, and print a log message if the texture of any of those entries is set to null. You should see that at this point, if you have a large number of textures to update, the temporary textures will have their texture set to null.

Pages: [1]