Jump to content
  • Advertisement
Sign in to follow this  
PolGraphic

DX11 DirectX11 mesh loading - error because of textures (using SDKmesh.h)? Access violation reading location 0x00000000

This topic is 2325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was trying to load a mesh from file in my DirectX 11 application.
As the base I took my own code (that renders some Primitives now) and I wanted to add to it code of mesh creating/rendering from "Basic HLSL" Project from DirectX 11 SDK Samples (which uses e.g. SDKmesh.h and DXUT.h from samples.

The mesh code is:
I was trying to load a mesh from file in my DirectX 11 application.
As the base I took my own code (that renders some Primitives now) and I wanted to add to it code of mesh creating/rendering from "Basic HLSL" Project from DirectX 11 SDK Samples (which uses e.g. SDKmesh.h and DXUT.h from samples.

The mesh code is:

[source lang="cpp"]
class FeyModel : public Graphic::Model, public FeyGraphicElement{
protected:
CDXUTSDKMesh mesh;
public:
FeyModel(ID3D11Device * device, std::string filename, const Common::Point3D center){
mesh.Create( device, L"tiny\\tiny.sdkmesh", false ); //for now tiny.sdkmesh
}

void render(FeyShader * shader,
FeyCamera * camera,
ID3D11DeviceContext* context,
float t
){

UINT Strides[1];
UINT Offsets[1];
ID3D11Buffer* pVB[1];
pVB[0] = mesh.GetVB11( 0, 0 );
Strides[0] = ( UINT )mesh.GetVertexStride( 0, 0 );
Offsets[0] = 0;
context->IASetVertexBuffers( 0, 1, pVB, Strides, Offsets );
context->IASetIndexBuffer( mesh.GetIB11( 0 ), mesh.GetIBFormat11( 0 ), 0 );


SDKMESH_SUBSET* pSubset = NULL;
D3D11_PRIMITIVE_TOPOLOGY PrimType;

//! context->PSSetSamplers( 0, 1, &samLinear );

for( UINT subset = 0; subset < mesh.GetNumSubsets( 0 ); ++subset )
{
// Get the subset
pSubset = mesh.GetSubset( 0, subset );

PrimType = CDXUTSDKMesh::GetPrimitiveType11( ( SDKMESH_PRIMITIVE_TYPE )pSubset->PrimitiveType );
context->IASetPrimitiveTopology( PrimType );


// TODO: D3D11 - material loading

ID3D11ShaderResourceView* pDiffuseRV = mesh.GetMaterial( pSubset->MaterialID )->pDiffuseRV11;

context->PSSetShaderResources( 0, 1, &pDiffuseRV );

context->DrawIndexed( ( UINT )pSubset->IndexCount, 0, ( UINT )pSubset->VertexStart );
}
}
};[/source]

I have also noticed that in the sample, there was a different vertex layout, so I have changed my shader's class code to (the code will be executed once, in shader's class constructor, before mesh creating):


[source lang="cpp"]
...
const D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};

UINT numElements = ARRAYSIZE( layout );

// Create the input layout
hr = device->CreateInputLayout( layout, numElements, pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), &*vertexLayout );
pVSBlob->Release();

// Set the input layout
context->IASetInputLayout( *vertexLayout );
...
[/source]

The compilation works. But during the execution of code I get error:

Access violation reading location 0x00000000

In SDKmish.h near:

[source lang="cpp"]if (bSRGB) {
// This is a workaround so that we can load linearly, but sample in SRGB. Right now, we can't load
// as linear since D3DX will try to do conversion on load. Loading as TYPELESS doesn't work either, and
// loading as typed _UNORM doesn't allow us to create an SRGB view.

// on d3d11 featuer levels this is just a copy, but on 10L9 we must use a cpu side copy with 2 staging resources.
ID3D11Texture2D* unormStaging = NULL;
ID3D11Texture2D* srgbStaging = NULL;

D3D11_TEXTURE2D_DESC CopyDesc;
pRes->GetDesc( &CopyDesc );

pLoadInfo->BindFlags = 0;
pLoadInfo->CpuAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
pLoadInfo->Depth = 0;
pLoadInfo->Filter = D3DX11_FILTER_LINEAR;
pLoadInfo->FirstMipLevel = 0;
pLoadInfo->Format = CopyDesc.Format;
pLoadInfo->Height = CopyDesc.Height;
pLoadInfo->MipFilter = D3DX11_FILTER_LINEAR;
pLoadInfo->MiscFlags = CopyDesc.MiscFlags;
pLoadInfo->Usage = D3D11_USAGE_STAGING;
pLoadInfo->Width = CopyDesc.Width;

CopyDesc.BindFlags = 0;
CopyDesc.Usage = D3D11_USAGE_STAGING;
CopyDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
CopyDesc.Format = MAKE_SRGB(CopyDesc.Format);

hr = D3DX11CreateTextureFromFile( pDevice, pSrcFile, pLoadInfo, pPump, ( ID3D11Resource** )&unormStaging, NULL );
DXUT_SetDebugName( unormStaging, "CDXUTResourceCache" );

hr = pDevice->CreateTexture2D(&CopyDesc, NULL, &srgbStaging);
DXUT_SetDebugName( srgbStaging, "CDXUTResourceCache" );
pContext->CopyResource( srgbStaging, unormStaging );
ID3D11Texture2D* srgbGPU;

pRes->GetDesc( &CopyDesc );
CopyDesc.Format = MAKE_SRGB(CopyDesc.Format);
hr = pDevice->CreateTexture2D(&CopyDesc, NULL, &srgbGPU);
pContext->CopyResource( srgbGPU, srgbStaging );

SAFE_RELEASE(pRes);
SAFE_RELEASE(srgbStaging);
SAFE_RELEASE(unormStaging);
pRes = srgbGPU;
}[/source]


Precisely in the line:
[source lang="cpp"]
pContext->CopyResource( srgbStaging, unormStaging );[/source]


When I comment few lines of that function and something in my code (I now can't remember what line were that) I get the mesh in the window, but without textures. So I guess it's something with textures? I have the tiny model and texture in the proper folder, I have also set vertex layout like I have posted above.

What else should I do?

Share this post


Link to post
Share on other sites
Advertisement
Please consider checking HREULT values for method Create and others.
Maybe you would pass a cannonical path instead of its short form.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!