Jump to content
  • Advertisement
Sign in to follow this  
CodaKiller

*sigh* Need assistance with this...

This topic is 3612 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

Well I was trying to create a texture from memory but I'm getting an access violation on CreateShaderResourceView, here is my source:
DWORD* pSrcData = 0;
RECT rect;
// ...Set pSrcData and the rect to my image.


	ID3D10Resource * pTexture;
	D3DX10_IMAGE_LOAD_INFO info;
	info.Width = (rect.right - rect.left);
	info.Height = (rect.bottom - rect.top);
	info.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	info.Usage = D3D10_USAGE_DEFAULT;
	info.MipLevels = 1;
	info.Depth = 1;
	info.CpuAccessFlags = 0;
	info.BindFlags = D3D10_BIND_SHADER_RESOURCE;
	info.MiscFlags = 0;
	info.Filter = 0;
	info.FirstMipLevel = 1;
	info.MipFilter = 0;
	info.pSrcInfo = 0;
	D3DX10CreateTextureFromMemory( g_d3dDevice, pSrcData, (4 * info.Width) * info.Height, &info, NULL, &pTexture, NULL);
	D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc;
	ID3D10Texture2D *pTexture2D = (ID3D10Texture2D*)pTexture;
	srvDesc.Format = info.Format;
	srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
	srvDesc.Texture2D.MostDetailedMip = info.MipLevels;
	ID3D10ShaderResourceView *pSRView = NULL;
	g_d3dDevice->CreateShaderResourceView( pTexture, &srvDesc, &pSRView );


Share this post


Link to post
Share on other sites
Advertisement
Help us to help you

Reverse the roles here - if you were reading your own post here, how do you go about analysing a piece of static code for a rather arbitrary runtime error?

  • What is the exact error message?
  • What is the state of all relevant variables? How did these get in their state? What does their state at the time of the error say about the path/flow of the application prior to the error?
  • What do the debug runtimes say?
  • Any compiler warnings?
  • Have you copied this code from anywhere? Do you have any working/correct examples to cross-reference yours with? If so, what are the differences?
  • What's your hypothesis? Why do you think it isn't working?



Cheers,
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
Help us to help you

Reverse the roles here - if you were reading your own post here, how do you go about analysing a piece of static code for a rather arbitrary runtime error?

  • What is the exact error message?
  • What is the state of all relevant variables? How did these get in their state? What does their state at the time of the error say about the path/flow of the application prior to the error?
  • What do the debug runtimes say?
  • Any compiler warnings?
  • Have you copied this code from anywhere? Do you have any working/correct examples to cross-reference yours with? If so, what are the differences?
  • What's your hypothesis? Why do you think it isn't working?



Cheers,
Jack


Quote:
What is the exact error message?


"First-chance exception at 0x76bbcd2e in Engine.exe: 0xC0000005: Access violation reading location 0xcccccccc."

All the variables are from a lua script and there is a really complex way that they are sized to the window but here they are at the time of error:

Text->rect.left = 102
Text->rect.top = 307
Text->rect.right = 307
Text->rect.bottom = 364

And there is no way I can be sure what is in pSrcData.

Quote:
What do the debug runtimes say?


If your talking about directx debug output then they are doing nothing.

Quote:
Any compiler warnings?


No, it's clean.

Quote:
Have you copied this code from anywhere? Do you have any working/correct examples to cross-reference yours with? If so, what are the differences?


No I came up with it, so there is a lot of room for mistakes...

Quote:
What's your hypothesis? Why do you think it isn't working?


I really have no idea... Maybe it's the way I created the data, so I'll show how I did that and the whole reason I'm doing this is to render GDI text to a DirectX sprite.

Source:


HDC hDC = CreateCompatibleDC(NULL);
DWORD* pSrcData = 0;
BITMAPINFO bmi = { sizeof( BITMAPINFOHEADER ), (Text->rect.right - Text->rect.left), (Text->rect.bottom - Text->rect.top), 1, 32, BI_RGB, 0, 0, 0, 0, 0};
HBITMAP hTempBmp = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS, (void**)&pSrcData, NULL, 0 );
HFONT NewFont = CreateFont( (int) ( ( ( WindowRect.bottom - WindowRect.top ) * ( RenderTarget->bottom - RenderTarget->top )) * Text->size), 0, 0, 0,
(FW_BOLD * lua_toboolean(L, 5)), lua_toboolean(L, 6), 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, 0, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, lua_tostring(L, 3) );
HBRUSH NewBrush = CreateSolidBrush(RGB(255, 0, 0));
SelectObject(hDC, NewFont);
SelectObject(hDC, NewBrush);
DrawText(hDC, Text->text.c_str(), 4, &Text->rect, DT_LEFT | DT_WORDBREAK);
GdiFlush();
DeleteObject(NewBrush);
DeleteObject(NewFont);
ReleaseDC(NULL, hDC);
ID3D10Resource * pTexture;
D3DX10_IMAGE_LOAD_INFO info;
info.Width = (Text->rect.right - Text->rect.left);
info.Height = (Text->rect.bottom - Text->rect.top);
info.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
info.Usage = D3D10_USAGE_DEFAULT;
info.MipLevels = 1;
info.Depth = 1;
info.CpuAccessFlags = 0;
info.BindFlags = D3D10_BIND_SHADER_RESOURCE;
info.MiscFlags = 0;
info.Filter = 0;
info.FirstMipLevel = 1;
info.MipFilter = 0;
info.pSrcInfo = 0;
D3DX10CreateTextureFromMemory( g_d3dDevice, pSrcData, (4 * info.Width) * info.Height, &info, NULL, &pTexture, NULL);
D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc;
ID3D10Texture2D *pTexture2D = (ID3D10Texture2D*)pTexture;
srvDesc.Format = info.Format;
srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MostDetailedMip = info.MipLevels;
ID3D10ShaderResourceView *pSRView = NULL;
g_d3dDevice->CreateShaderResourceView( pTexture, &srvDesc, &pSRView );





[Edited by - CodaKiller on December 2, 2008 1:55:21 PM]

Share this post


Link to post
Share on other sites
"First-chance exception at 0x76bbcd2e in Engine.exe: 0xC0000005: Access violation reading location 0xcccccccc."

That sounds almost certainly like an uninitialised pointer variable. Are you using an IDE (such as Visual Studio)? If so then you should be able to do a debug run and see on what line the program crashes. Then, you can look in the "Autos" window and see if any pointer variables have the value 0xcccccccc.

Share this post


Link to post
Share on other sites
Quote:
Original post by Jaywalk
"First-chance exception at 0x76bbcd2e in Engine.exe: 0xC0000005: Access violation reading location 0xcccccccc."

That sounds almost certainly like an uninitialised pointer variable. Are you using an IDE (such as Visual Studio)? If so then you should be able to do a debug run and see on what line the program crashes. Then, you can look in the "Autos" window and see if any pointer variables have the value 0xcccccccc.


The value that is creating the error is pTexture and as stated before it crashes on CreateShaderResourceView so clearly the texture was created wrong.

Share this post


Link to post
Share on other sites
Aha!
Where I got the little bit about CreateShaderResourceView, they had a small error in defining the desc.



D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = desc.Format;
srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MostDetailedMip = 0; // I deleted this because I didn't see the point, now I realize this was an error.
srvDesc.Texture2D.MostDetailedMip = desc.MipLevels;


D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = desc.Format;
srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = TextureDesc.MipLevels;




I present the final product:


RECT rect;
rect.left = 0; rect.top = 0; rect.right = (Text->rect.right - Text->rect.left); rect.bottom = (Text->rect.bottom - Text->rect.top);
HDC hDC = CreateCompatibleDC(NULL);
DWORD* pSrcData = 0;
BITMAPINFO bmi = { sizeof( BITMAPINFOHEADER ), rect.right, rect.bottom, 1, 32, BI_RGB, 0, 0, 0, 0, 0};
HBITMAP hTempBmp = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS, (void**)&pSrcData, NULL, 0 );
HBITMAP hOldBmp = (HBITMAP)SelectObject(hDC, hTempBmp );
HFONT NewFont = CreateFont( (int) ( ( ( WindowRect.bottom - WindowRect.top ) * ( RenderTarget->bottom - RenderTarget->top )) * Text->size), 0, 0, 0,
(FW_BOLD * lua_toboolean(L, 5)), lua_toboolean(L, 6), 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, 0, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, lua_tostring(L, 3) );
HBRUSH NewBrush = CreateSolidBrush(RGB(255, 0, 0));
SelectObject(hDC, NewFont);
SelectObject(hDC, NewBrush);
DrawText(hDC, Text->text.c_str(), Text->text.size(), &rect, DT_LEFT | DT_WORDBREAK);
GdiFlush();
DeleteObject(NewBrush);
DeleteObject(NewFont);
ReleaseDC(NULL, hDC);
D3D10_SUBRESOURCE_DATA data;
data.pSysMem = pSrcData;
data.SysMemPitch = 4 * (Text->rect.right - Text->rect.left);
data.SysMemSlicePitch = 0;
ID3D10Texture2D* Texture;
D3D10_TEXTURE2D_DESC TextureDesc;
ZeroMemory( &TextureDesc, sizeof( TextureDesc ) );
TextureDesc.Width = (Text->rect.right - Text->rect.left);
TextureDesc.Height = (Text->rect.bottom - Text->rect.top);
TextureDesc.MipLevels = 1;
TextureDesc.ArraySize = 1;
TextureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
TextureDesc.SampleDesc.Count = 1;
TextureDesc.SampleDesc.Quality = 0;
TextureDesc.Usage = D3D10_USAGE_DEFAULT;
TextureDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
TextureDesc.CPUAccessFlags = 0;
TextureDesc.MiscFlags = 0;
g_d3dDevice->CreateTexture2D( &TextureDesc, &data, &Texture );
D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = TextureDesc.Format;
srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = TextureDesc.MipLevels;
ID3D10ShaderResourceView *srvTexture = NULL;
g_d3dDevice->CreateShaderResourceView( Texture, &srvDesc, &srvTexture );
Texture->Release();



Now I only have one more problem, the GDI is giving me a upside down image, how can I flip it vertically?

[Edited by - CodaKiller on December 2, 2008 4:04:03 PM]

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!