Sign in to follow this  
dmtuan

[SharpDX] 0x8007000E Error - E_OUTOFMEMORY/Out of memory (running on WP8.1)

Recommended Posts

Hi,

 

I have this engine written with SharpDX running as Windows Universal App. It is renderer capable of rendering and animating a character. The Windows 8.1 part of the Universal App works fine. I've been trying to rewrite the code used in Windows 8.1 part to make the engine run on Windows Phone 8.1. Since Windows Phone only supports DirectX feature level 9_3, I had to make some adjusments - like rewriting shaders originally from Shader Model 5 to Shader Model 2 and adjusting code. I am debugging on HTC 8x device (Windows Phone 8.1).

 

Now, in the initialisation phase, after I compile the shaders and create constant buffers, I get this weird error, which I really don't know how to deal with. It don't really understand, how it's even happening:

 

Exception = {SharpDX.SharpDXException: HRESULT: [0x8007000E], Module: [General], ApiCode: [E_OUTOFMEMORY/Out of memory], Message: Not enough storage is available to complete this operation.

 

Here's a snippet from my code:

#region Compile shaders
            // Compile Vertex Shader and create vertex InputLayout
            /// NOTE: commented line is for WinRT client
            //using (var bytecode = await HLSLCompiler.CompileFromFileAsync(@"Shaders\VS.hlsl", "VSMain", "vs_5_0"))
            using (var bytecode = await HLSLCompiler.CompileFromFileAsync(@"Shaders\VS.hlsl", "VSMain", "vs_4_0_level_9_3"))
            {
                vertexShader = new VertexShader(device, bytecode);
                vertexLayout = ToDispose(new InputLayout(device,
                   bytecode.GetPart(ShaderBytecodePart.InputSignatureBlob).Data,
                new[]
                {
                    // "SV_Position" = vertex coordinate in object space
                    new InputElement("SV_Position", 0, Format.R32G32B32_Float, 0, 0),
                    // "NORMAL" = the vertex normal
                    new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0),
                    // "COLOR"
                    new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 24, 0),
                    // "UV"
                    new InputElement("TEXCOORD", 0, Format.R32G32_Float, 28, 0),
                    // "BLENDINDICES"
                    // NOTE: commented line is for WinRT client
                    //new InputElement("BLENDINDICES", 0, Format.R32G32B32A32_UInt, 36, 0), 
                    new InputElement("BLENDINDICES", 0, Format.R32G32B32A32_Float, 36, 0),
                    // "BLENDWEIGHT"
                    new InputElement("BLENDWEIGHT", 0, Format.R32G32B32A32_Float, 52, 0),
                }));
            }

            // Compile pixel shader
            /// NOTE: commented line is for WinRT client
            //using (var bytecode = await HLSLCompiler.CompileFromFileAsync(@"Shaders\BlinnPhongPS.hlsl", "PSMain", "ps_5_0"))
            using (var bytecode = await HLSLCompiler.CompileFromFileAsync(@"Shaders\BlinnPhongPS.hlsl", "PSMain", "ps_4_0_level_9_3"))
                pixelShader = ToDispose(new PixelShader(device, bytecode));
            #endregion

            #region Create constant buffers
            // Create constant buffers

            // Create the constant buffer that will
            // store our worldViewProjection matrix
            perObjectBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(device, Utilities.SizeOf<ConstantBuffers.PerObject>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            // Create the per frame constant buffer
            // lighting / camera position
            perFrameBuffer = ToDispose(new Buffer(device, Utilities.SizeOf<ConstantBuffers.PerFrame>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            // Create the per material constant buffer
            perMaterialBuffer = ToDispose(new Buffer(device, Utilities.SizeOf<ConstantBuffers.PerMaterial>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            // Create the per armature/skeletong constant buffer
            perArmatureBuffer = ToDispose(new Buffer(device, ConstantBuffers.PerArmature.Size(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            #endregion

            #region Create pipeline state variables
            // Configure the depth buffer to discard pixels that are
            // further than the current pixel.
            depthStencilState = ToDispose(new DepthStencilState(device,
                new DepthStencilStateDescription()
                {
                    IsDepthEnabled = true, // enable depth?
                    DepthComparison = Comparison.Less,
                    DepthWriteMask = SharpDX.Direct3D11.DepthWriteMask.All,
                    IsStencilEnabled = false,// enable stencil?
                    StencilReadMask = 0xff, // 0xff (no mask)
                    StencilWriteMask = 0xff,// 0xff (no mask)
                }));

            rsCullBack = ToDispose(new RasterizerState(device, new RasterizerStateDescription
            {
                CullMode = CullMode.Back,
                IsFrontCounterClockwise = false,
                FillMode = FillMode.Solid,
            }));
            #endregion

The error occurs right on the line 164 - the rsCullBack = ToDispise() command.

 

What baffles me is that the error says its a our of memory problem, but this is just an initialization phase. If it was in the rendering loop, it would be more understandable, since there might be a memory leak or something, but this...? Does anyone know the way to see how much memory did I use up or how much memory I have left to use?

 

If anyone knows, what might cause this error or how to fix this, you'd be a lifesaver. Any comments, tips and advices are most welcoming.

Share this post


Link to post
Share on other sites

hello.

 

Does the above code load any .X files. It could be a aligned memory thing

 

Hi, it does not.

 

Although, I found out what the problem was. I do not know why the problem occurs, but I know what causes it. It is exactly this:

rsCullBack = ToDispose(new RasterizerState(device, new RasterizerStateDescription
            {
                CullMode = CullMode.Back,
                IsFrontCounterClockwise = false,
                FillMode = FillMode.Solid,
            }));

When I remove this from the code, it runs fine. For some reason, it makes the engine crash on a real device, but on emulator it runs fine.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this