Hello Guest

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 - imkc

Pages: [1]
1
And I tried to free the memory of PNG files by appending last bold lines below:

bool assignTextureInst = false;
            if (pngTextures.Length > 0) {
               assignTextureInst = true;
               textureInsts = new Texture2D[pngTextures.Length];
               for (int i = 0; i < pngTextures.Length; ++i) {
                  Texture2D tex = new Texture2D(4, 4, TextureFormat.ARGB32, textureMipMaps);
                  tex.LoadImage(pngTextures.bytes);
                  textureInsts = tex;
                  tex.filterMode = textureFilterMode;
   #if UNITY_EDITOR
                  tex.hideFlags = HideFlags.DontSave;
   #endif
                  tex.Apply(textureMipMaps, true);
               }
    #if !UNITY_EDITOR
               pngTextures = new TextAsset[0];
    #endif

            }

It works properly in my case. However,  png atlases cost more memory than Unity Texture in XCode debugger, but the wasted memory should be reserved by mono, which is reported in Unity Profiler as well, and I don't think it does matter in my case ;D

2
Investigated this and it looks like using LoadImage (which the png atlases use) allocates another copy in memory which Unity doesn't seem to free. A 5.3MB 1024x1024 texture takes up 10.7MB, which makes absolutely no sense.
Edit: I missed something in the profiler - It actually does seem to matter if Apply is called. Try adding this line to tk2dSpriteCollectionData.cs to see if it improves things.


            bool assignTextureInst = false;
            if (pngTextures.Length > 0) {
               assignTextureInst = true;
               textureInsts = new Texture2D[pngTextures.Length];
               for (int i = 0; i < pngTextures.Length; ++i) {
                  Texture2D tex = new Texture2D(4, 4, TextureFormat.ARGB32, textureMipMaps);
                  tex.LoadImage(pngTextures.bytes);
                  textureInsts = tex;
                  tex.filterMode = textureFilterMode;
   #if UNITY_EDITOR
                  tex.hideFlags = HideFlags.DontSave;
   #endif
                  tex.Apply(textureMipMaps, true);
               }
            }

It works as expected! Thank you so much!

3
png textures use more memory on IOS as the png file will be loaded into memory in addition to the texture itself.  Shouldn't be double though - how are you getting this data?

In the Unity(4.3.4)'s Profiler, connected with a device running iOS 7.0.4.
You can find in the attachment 1, which is using Unity Texture. The largest atlas costs 16MB here.
And in attachment 2, which is using PNG atlases, the largest atlas's gone in "Assets->Texture2D" section of profiler.
But we can find it in "Scene Memory" section, which costs 32MB in attachment 3. I am sure it is the same atlas as the one of attachment 1.
And the XCode debugger also reported the similar increasement of memory usage.


4
Hi,

I've tried to use PNG atlases to reduce the app size after installed in iOS. I could see the the app size become 55MB from more than 70MB.
But I found the memory usage increased after changed to PNG atlases. I could see in the profiler, The memory usage of "MainCollection" atlas in PNG is 32MB, while it is 16MB in Unity Texture. The screenshots of settings are attached, and "PremulVertexColor" is used for both. Is there anything I missed?

5
Support / Problem when creating PNG atlases on 2.3
« on: November 15, 2013, 02:33:56 am »
Hi,

I tried to change one of the old atlas to PNG atlas, but I got the following message:

IndexOutOfRangeException: Array index is out of range.
tk2dSpriteCollectionBuilder.Rebuild (.tk2dSpriteCollection gen) (at Assets/TK2DROOT/tk2d/Editor/Sprites/tk2dSpriteCollectionBuilder.cs:1298)
tk2dSpriteCollectionEditorPopup.Commit () (at Assets/TK2DROOT/tk2d/Editor/Sprites/SpriteCollectionEditor/tk2dSpriteCollectionEditorPopup.cs:446)
tk2dSpriteCollectionEditorPopup.DrawToolbar () (at Assets/TK2DROOT/tk2d/Editor/Sprites/SpriteCollectionEditor/tk2dSpriteCollectionEditorPopup.cs:436)
tk2dSpriteCollectionEditorPopup.OnGUI () (at Assets/TK2DROOT/tk2d/Editor/Sprites/SpriteCollectionEditor/tk2dSpriteCollectionEditorPopup.cs:889)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

Is there anything I missed?
btw, it is on Unity 4.3.

Pages: [1]