Hi,
I'm having problem of the NGUI crashing when working with large atlases. What I'm doing is changing properties of series of atlases. I set padding, then select one of textures within atlas, then make it re-generate the atlas by clicking add/update. What I get at one point is:
DynamicHeapAllocator out of memory - Could not get memory for large allocationCould not allocate memory: System out of memory!
Trying to allocate: 8388612B with 32 alignment. MemoryLabel: Texture
Allocation happend at: Line:345 in /Applications/buildAgent/work/d9c061b1c154f5ae/Runtime/Graphics/Texture2D.cpp
Memory overview
[ ALLOC_TEMP_THREAD ] used: 32752B | peak: 0B | reserved: 262144B
[ ALLOC_DEFAULT ] used: 106606866B | peak: 411944658B | reserved: 268435456B
[ ALLOC_GFX ] used: 1052225466B | peak: 1111413203B | reserved: 1059411326B
Size | Num Used| Num Free|
8-15 | 0| 2|
16-31 | 0| 11|
32-63 | 39| 10|
64-127 | 113| 5|
128-255 | 77| 9|
256-511 | 132| 1|
512-1023 | 321| 6|
1024-2047 | 282| 9|
2048-4095 | 42| 5|
4096-8191 | 67| 4|
8192-16383 | 52| 6|
16384-32767 | 60| 1|
32768-65535 | 24| 0|
65536-131071 | 47| 1|
131072-262143 | 29| 0|
262144-524287 | 55| 0|
524288-1048575| 20| 1|
1048576-2097151| 8| 1|
2097152-4194303| 6| 0|
4194304-8388607| 9| 0|
8388608-16777215| 1| 0|
16777216-33554431| 2| 0|
33554432-67108863| 3| 0|
Label | Allocated| Count|Largest Alloc
VertexData | 201326| 110| 58152|
Geometry | 2640| 55| 48|
Texture | 1052021500| 1237| 89478488|
*Total* | 1052225466| 1402| N/A
One of the atlases is 4096x4096. When changed alone, it usually works (but not always!). But when changed in series one-by-one, it almost always crashes. Changing the atlas to 2048x2048 (for example by slicing the assets by half) helps, so it seems this is a memory problem indeed. This is a bit strange, as my system has 12 GB of ram. However, I suspect Unity gets only 4 GB or something (being 32 bit) and there we go having problems.
When debugging, I've located the error to happen at AssetDatabase.ImportAsset method. The call stack display gives the following:
UIAtlasMaker->AddOrUpdate->ExtractSprites->NGUIEditorTools.ImportTexture->ImportTexture->MakeTextureAnAtlas->ImportAsset
- BTW, NGUI is calling this method twice during each single atlas add/update operation, which seems pretty non-optimized.
Any help would be appreciated. I can't use smaller atlases, I can't use less atlases. I need the code to work OK under those conditions and it doesn't.