directx – SlimDX在一段时间后停止加载大纹理

我的应用程序不时初始化一堆DirectX东西并加载场景,有时包含一些大纹理(每个纹理最多200-300 MB).起初,一切正常,但过了一段时间FromMemory()只是停止工作,但只适用于大纹理:

SlimDX.Direct3D11.Direct3D11Exception: E_FAIL: An undetermined error occurred (-2147467259)
  at SlimDX.Result.Throw[T](Object dataKey, Object dataValue)
  at SlimDX.Result.Record[T](Int32 hr, Boolean failed, Object dataKey, Object dataValue)
  at SlimDX.Direct3D11.ShaderResourceView.ConstructFromMemory(Device device, Byte[] memory, D3DX11_IMAGE_LOAD_INFO* loadInformation)
  at SlimDX.Direct3D11.ShaderResourceView.FromMemory(Device device, Byte[] memory)

当然,我在加载新场景之前处理所有先前加载的ShaderResourceViews.但只有在应用程序重启后,FromMemory()才会重新开始工作.你能告诉我还有什么可能是错的吗?

UPD:

使用Texture2D.FromMemory(),我得到这个:

System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
  at D3DX11CreateTextureFromMemory(ID3D11Device* , Void* , UInt32 , D3DX11_IMAGE_LOAD_INFO* , ID3DX11ThreadPump* , ID3D11Resource** , Int32* )
  at SlimDX.Direct3D11.Resource.ConstructFromMemory(Device device, Byte[] memory, D3DX11_IMAGE_LOAD_INFO* info)
  at SlimDX.Direct3D11.Texture2D.FromMemory(Device device, Byte[] memory)

并启用本机代码调试:

Exception thrown at 0x748AA882 in app.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x00AFC7C8.
Exception thrown: 'System.Runtime.InteropServices.SEHException' in SlimDX.dll

遗憾的是,我不知道D3DX11CreateTextureFromMemory()实际上是如何工作的,为什么它会尝试重新分配内存.也许是时候转向x64 ……

最佳答案 发现了问题.事实证明我所要做的就是将“LARGEADDRESSAWARE”标志添加到可执行文件中.没有它,1 GB是极限 – 每个纹理300 MB很容易实现.

当然,由于大多数数据最终都在大对象堆中,因此GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce也有帮助.

抱歉浪费你的时间.

点赞