Unity3d巨大的内存使用纹理

时间:2014-09-24 21:22:22

标签: memory windows-phone-8 unity3d textures

我在iOS3,Android和Windows Phone上运行的Unity3D中构建了一个3D无尽的跑步游戏。

它在具有1014MB及更高内存的Windows手机上运行良好,但在此之后它会在启动后立即崩溃(请参阅本文底部的Visual Studio的错误消息)。

查看分析器我可以看到纹理的内存使用率非常高,因为我知道Lumia 520上最多只能获得180MB RAM,我可以从分析器看到纹理单独占用359MB,甚至在第八个res(截图如下),他们仍然占用232MB!我已经完成了每一个纹理,使它尽可能小,压缩,我在这里做错了什么?如何找到有关纹理问题的更多信息?

我通常会在游戏开始时将所有程序级元素预加载到内存中,以便在运行时帮助提高帧速率,但即使完全关闭帧速率,内存使用量也不会受到影响。

任何向正确方向推进都会有所帮助,谢谢!

memory usage

Visual Studio崩溃控制台日志转储:

'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: DefaultDomain): Loaded 'C:\windows\system32\mscorlib.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Windows.RuntimeHost.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Windows.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Net.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Xml.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\EndlessRunner.DLL'. Symbols loaded.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\Microsoft.Phone.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\Microsoft.Phone.Interop.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\WinRTBridge.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\BridgeInterface.winmd'. Module was built without symbols.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\UnityPlayer.winmd'. Module was built without symbols.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\WinMetadata\Windows.winmd'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Core.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Runtime.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Build from 'release/4.5/release' branch, version is '4.5.0f6 (fd4616464986)' (Release build).

Physical memory: 395 MB, commited memory limit: 180 MB.

PlayerConnection initialized from C:/Data/Programs/{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}/Install/Data (debug = 0)

PlayerConnection initialized network socket : 0.0.0.0 55444

Multi-casting "[IP] 192.168.0.19 [Port] 55444 [Flags] 2 [Guid] 93005236 [EditorId] 1016877170 [Version] 1048832 [Id] WP8Player(192.168.0.19) [Debug] 0" to [225.0.0.222:54997]...

Direct3D:

    Version:  Direct3D 11.0 [level 9.3]

    Renderer: Qualcomm Adreno 305 (WDDM v1.2) (ID=0x30303330)

    Vendor:   Qualcomm

    VRAM:     96 MB

Initialize engine version: 4.5.0f6 (fd4616464986)

'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\UnityEngine.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\Assembly-CSharp-firstpass.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\Assembly-CSharp.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\BFSWP8Goodies.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\GPGSUtils.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\WinRTLegacy.DLL'. Module was built without symbols.
Could not allocate memory: System out of memory!
Trying to allocate: 1398128B with 32 alignment. MemoryLabel: Texture
Allocation happend at: Line:411 in C:/BuildAgent/work/aeedb04a1292f85a/Runtime/Graphics/Texture2D.cpp
Memory overview


[ ALLOC_DEFAULT ] used: 5715133B | peak: 5715181B | reserved: 6570457B 

[ ALLOC_GAMEOBJECT ] used: 43508B | peak: 43508B | reserved: 52731B 

[ ALLOC_GFX ] used: 155628390B | peak: 155628390B | reserved: 155631656B 

[ ALLOC_PROFILER ] used: 5028B | peak: 5028B | reserved: 12158B 

Could not allocate memory: System out of memory!
Trying to allocate: 1398128B with 32 alignment. MemoryLabel: Texture
Allocation happend at: Line:411 in C:/BuildAgent/work/aeedb04a1292f85a/Runtime/Graphics/Texture2D.cpp
Memory overview


[ ALLOC_DEFAULT ] used: 5715133B | peak: 5715181B | reserved: 6570457B 

[ ALLOC_GAMEOBJECT ] used: 43508B | peak: 43508B | reserved: 52731B 

[ ALLOC_GFX ] used: 155628390B | peak: 155628390B | reserved: 155631656B 

[ ALLOC_PROFILER ] used: 5028B | peak: 5028B | reserved: 12158B 


(Filename: C:/BuildAgent/work/aeedb04a1292f85a/Runtime/Allocator/MemoryManager.cpp Line: 909)


The program '[2540] TaskHost.exe' has exited with code -2147483645 (0x80000003).

2 个答案:

答案 0 :(得分:0)

  

我已经完成了每一个纹理,使它尽可能小,压缩,我在这里做错了什么?如何找到有关纹理问题的更多信息?

嗯......我不认为你做错了什么。硬件的内存限制是硬件问题,而不是艺术家问题。但是,艺术家必须应对限制才能应对硬件限制,然后:

  1. 如果你做3D,你可以:确保你的模型尽可能少的材料。模型上的材料越多,这种模型最可能需要的纹理越多。如果您仍然需要,请确保其他模型可以共享相同的材料或共享一些网格组,以便您可以优化绘制调用。

  2. 如果你能使用Atlas纹理也是很好的帮助,因为它只考虑了一种材料。然后它对内存的帮助不大,因为它仍然需要相同的内存。它主要有助于反对平局调用。

  3. 就像LearnCocos2D所说的那样,即使纹理“小”,每种颜色的位数也是巨大的*。例如,尝试不使用32位纹理。

  4. 纹理分辨率或纹素是关键。如果你正在使用一个角色并且你的角色在移动屏幕上很小,那么你应该对很小的纹理很好。例如,在某些游戏中,角色是6'高度和8'脚墙在覆盖范围内被翻译成512x512px纹理,比如在墙壁部分中砖块的贴片,与角色形成鲜明对比。例如,在这样的8'与这样的角色形成对比的脚等效高度墙已经开始浪费资源,视觉冲击将是最小的或根本不明显。为3D移动游戏定义纹理元素分辨率非常重要,以便能够更好地规划纹理资源。

    如果可以的话,我建议您使用本教程,它可以提供有关此问题的信息:http://www.digitaltutors.com/tutorial/1772-Creating-Professional-Studio-Game-Assets-for-Production-in-3ds-Max-and-Unity

  5. 然后最后在你的情况下,因为它是无限的,你真的需要使用启用/禁用而不是破坏,并确保相机剔除的距离正是你所需要的,否则你会#l; ll在没有必要的情况下加载大量玩家看不见的物体,这也可能是一个婴儿潮......只是说。

答案 1 :(得分:0)

我确实在Unity制作的项目中经常看到内存使用问题。 完成诸如纹理压缩设置之类的典型优化后,您可以尝试另一种方法。 从最近开始,Unity发布了一个名为Addressables的软件包。这将允许您保留对资产的引用,而无需加载它们。 在那里,由您决定何时加载/卸载它们。 我写了一篇有关它们的详细博客文章,它可能会对您有所帮助。 在https://thegamedev.guru/unity-addressables-learn-workflows/

中找到它