Sign in to follow this  

DX11 D3D11CreateDeviceAndSwapChain doesnt seem to assign addresses to Swap Chain or Device?

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

Hello Everyone,

I'm very new to DirectX, so I'm having a hard time figuring out a problem in the code I'm looking at now. When I run the following code, it compiles, but when I close the window I get a message saying "Unhandled exception at 0x012f1873 in Window2.exe: 0xC0000005: Access violation reading location 0x00000000." When I went through debugging, my SwapChain, Device, and DeviceContext were all 0x00000000. That message pops up on SwapChain->Release() (I'm assuming it'd come up on the other two as well if it got to them).

I sent the code to a friend of mine, who compiled and ran it without any problem... the pointers all had valid memory addresses. We have the same version of the DirectX sdk. Originally I was compiling in Visual Studio 2010, but I just tried again with 2008 (which is what he was working with) and I got the same problem.

I noticed when D3D11CreateDeviceAndSwapChain was called, I got three messages in the debugger saying "First-chance exception at 0x7588b727 in Window2.exe: Microsoft C++ exception: _com_error at memory location 0x0034f388..", with a different address each time. Not sure if that has anything to do with it, just throwing it out there in case :)

Here's the code, any ideas why the pointers aren't being assigned to?

[code]
//..........................................................................................................//
//............................................Includes......................................................//
//..........................................................................................................//

//Windows Includes
#include <Windows.h>
#include <WindowsX.h>

//DirectX Includes
#include <D3D11.h>
#include <D3DX11.h>
#include <D3DX10.h>

//..........................................................................................................//
//............................................Pragmas.......................................................//
//..........................................................................................................//

//DirectX libraries
#pragma comment (lib, "D3D11.lib")
#pragma comment (lib, "D3DX11.lib")
#pragma comment (lib, "D3DX10.lib")

//..........................................................................................................//
//............................................Globals.......................................................//
//..........................................................................................................//

//DirectX Globals
IDXGISwapChain* SwapChain;
ID3D11Device* Device;
ID3D11DeviceContext* DeviceContext;

//..........................................................................................................//
//......................................Function Protoytypes................................................//
//..........................................................................................................//

//Windows functions
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

//DirectX functions
void InitD3D(HWND hWnd);
void CleanD3D();

//..........................................................................................................//
//.....................................Function Definitions.................................................//
//..........................................................................................................//

////////////////////////////////////////////
//WinMain: The entry point for our program//
////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
//Variable Declarations
HWND hWnd;
WNDCLASSEX wc;

//Set up Window Class
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hInstance = hInstance;
wc.lpfnWndProc = WinProc;
wc.lpszClassName = L"WindowClass1";
wc.style = CS_VREDRAW | CS_HREDRAW;
RegisterClassEx(&wc);

//Create and show window
RECT rect = {0, 0, 600, 400};
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, false);
hWnd = CreateWindowEx(NULL, L"WindowClass1", L"Window Title", WS_OVERLAPPEDWINDOW, 300, 300, rect.right - rect.left,
rect.bottom - rect.top, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);

//Initialize DirectX 3D
InitD3D(hWnd);

//Game Loop
MSG msg;
while(true)
{
//Respond to user input if provided
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if (msg.message == WM_QUIT)
break;
}
//Go about rest of game's business here
}

//Release DirectX 3D
CleanD3D();

//Return msg's wParam when finished
return msg.wParam;
}

/////////////////////////////////////
//WinProc: Respond to user messages//
/////////////////////////////////////
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case(WM_DESTROY):
PostQuitMessage(0);
return 0;
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
}

//////////////////////////////////
//InitD3D: Initialize DirectX 3D//
//////////////////////////////////
void InitD3D(HWND hWnd)
{
//Variable Declarations
DXGI_SWAP_CHAIN_DESC SwapChainDesc;

//Setup Swap Chain Description
ZeroMemory(&SwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
SwapChainDesc.BufferCount = 1;
SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
SwapChainDesc.OutputWindow = hWnd;
SwapChainDesc.SampleDesc.Count = 4;
SwapChainDesc.Windowed = true;

//Create Device and Swap Chain from description above
D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, &SwapChainDesc,
&SwapChain, &Device, NULL, &DeviceContext);
}

//////////////////////////////////////////////////////
//CleanD3D: Release memory for Swap Chain and Device//
//////////////////////////////////////////////////////
void CleanD3D()
{
SwapChain->Release();
Device->Release();
DeviceContext->Release();
}
[/code]

Share this post


Link to post
Share on other sites
Check the HRESULT returned by D3D11CreateDeviceAndSwapChain in case it is failing, Also passing D3D11_CREATE_DEVICE_DEBUG to the flags parameter may give more information in the output about what is going wrong

Share this post


Link to post
Share on other sites
[quote name='LegendInStone' timestamp='1306696166' post='4817207']
Check the HRESULT returned by D3D11CreateDeviceAndSwapChain in case it is failing, Also passing D3D11_CREATE_DEVICE_DEBUG to the flags parameter may give more information in the output about what is going wrong
[/quote]

Thanks! Looks like the SampleDesc.Count was too high for my computer, turning it down from 4 to 1 got it working.

Share this post


Link to post
Share on other sites

This topic is 2394 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.

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  

  • Forum Statistics

    • Total Topics
      628740
    • Total Posts
      2984472
  • Similar Content

    • By GreenGodDiary
      Having some issues with a geometry shader in a very basic DX app.
      We have an assignment where we are supposed to render a rotating textured quad, and in the geometry shader duplicate this quad and offset it by its normal. Very basic stuff essentially.
      My issue is that the duplicated quad, when rendered in front of the original quad, seems to fail the Z test and thus the original quad is rendered on top of it.
      Whats even weirder is that this only happens for one of the triangles in the duplicated quad, against one of the original quads triangles.

      Here's a video to show you what happens: Video (ignore the stretched textures)

      Here's my GS: (VS is simple passthrough shader and PS is just as basic)
      struct VS_OUT { float4 Pos : SV_POSITION; float2 UV : TEXCOORD; }; struct VS_IN { float4 Pos : POSITION; float2 UV : TEXCOORD; }; cbuffer cbPerObject : register(b0) { float4x4 WVP; }; [maxvertexcount(6)] void main( triangle VS_IN input[3], inout TriangleStream< VS_OUT > output ) { //Calculate normal float4 faceEdgeA = input[1].Pos - input[0].Pos; float4 faceEdgeB = input[2].Pos - input[0].Pos; float3 faceNormal = normalize(cross(faceEdgeA.xyz, faceEdgeB.xyz)); //Input triangle, transformed for (uint i = 0; i < 3; i++) { VS_OUT element; VS_IN vert = input[i]; element.Pos = mul(vert.Pos, WVP); element.UV = vert.UV; output.Append(element); } output.RestartStrip(); for (uint j = 0; j < 3; j++) { VS_OUT element; VS_IN vert = input[j]; element.Pos = mul(vert.Pos + float4(faceNormal, 0.0f), WVP); element.Pos.xyz; element.UV = vert.UV; output.Append(element); } }  
      I havent used geometry shaders much so im not 100% on what happens behind the scenes.
      Any tips appreciated! 
    • By mister345
      Hi, I'm building a game engine using DirectX11 in c++.
      I need a basic physics engine to handle collisions and motion, and no time to write my own.
      What is the easiest solution for this? Bullet and PhysX both seem too complicated and would still require writing my own wrapper classes, it seems. 
      I found this thing called PAL - physics abstraction layer that can support bullet, physx, etc, but it's so old and no info on how to download or install it.
      The simpler the better. Please let me know, thanks!
    • By Hexaa
      I try to draw lines with different thicknesses using the geometry shader approach from here:
      https://forum.libcinder.org/topic/smooth-thick-lines-using-geometry-shader
      It seems to work great on my development machine (some Intel HD). However, if I try it on my target (Nvidia NVS 300, yes it's old) I get different results. See the attached images. There
      seem to be gaps in my sine signal that the NVS 300 device creates, the intel does what I want and expect in the other picture.
      It's a shame, because I just can't figure out why. I expect it to be the same. I get no Error in the debug output, with enabled native debugging. I disabled culling with CullMode.None. Could it be some z-fighting? I have little clue about it but I tested to play around with the RasterizerStateDescription and DepthBias properties with no success, no change at all. Maybe I miss something there?
      I develop the application with SharpDX btw.
      Any clues or help is very welcome
       


    • By Beny Benz
      Hi,
      I'm currently trying to write a shader which shoud compute a fast fourier transform of some data, manipulating the transformed data, do an inverse FFT an then displaying the result as vertex offset and color. I use Unity3d and HLSL as shader language. One of the main problems is that the data should not be passed from CPU to GPU for every frame if possible. My original plan was to use a vertex shader and do the fft there, but I fail to find out how to store changing data betwen shader calls/passes. I found a technique called ping-ponging which seems to be based on writing and exchangeing render targets, but I couldn't find an example for HLSL as a vertex shader yet.
      I found https://social.msdn.microsoft.com/Forums/en-US/c79a3701-d028-41d9-ad74-a2b3b3958383/how-to-render-to-multiple-render-targets-in-hlsl?forum=xnaframework
      which seem to use COLOR0 and COLOR1 as such render targets.
      Is it even possible to do such calculations on the gpu only? (/in this shader stage?, because I need the result of the calculation to modify the vertex offsets there)
      I also saw the use of compute shaders in simmilar projects (ocean wave simulation), do they realy copy data between CPU / GPU for every frame?
      How does this ping-ponging / rendertarget switching technique work in HLSL?
      Have you seen an example of usage?
      Any answer would be helpfull.
      Thank you
      appswert
    • By ADDMX
      Hi
      Just a simple question about compute shaders (CS5, DX11).
      Do the atomic operations (InterlockedAdd in my case) should work without any issues on RWByteAddressBuffer and be globaly coherent ?
      I'v come back from CUDA world and commited fairly simple kernel that does some job, the pseudo-code is as follows:
      (both kernels use that same RWByteAddressBuffer)
      first kernel does some job and sets Result[0] = 0;
      (using Result.Store(0, 0))
      I'v checked with debugger, and indeed the value stored at dword 0 is 0
      now my second kernel
      RWByteAddressBuffer Result;  [numthreads(8, 8, 8)] void main() {     for (int i = 0; i < 5; i++)     {         uint4 v0 = DoSomeCalculations1();         uint4 v1 = DoSomeCalculations2();         uint4 v2 = DoSomeCalculations3();                  if (v0.w == 0 && v1.w == 0 && v2.w)             continue;         //    increment counter by 3, and get it previous value         // this should basically allocate space for 3 uint4 values in buffer         uint prev;         Result.InterlockedAdd(0, 3, prev);                  // this fills the buffer with 3 uint4 values (+1 is here as the first 16 bytes is occupied by DrawInstancedIndirect data)         Result.Store4((prev+0+1)*16, v0);         Result.Store4((prev+1+1)*16, v1);         Result.Store4((prev+2+1)*16, v2);     } } Now I invoke it with Dispatch(4,4,4)
      Now I use DrawInstancedIndirect to draw the buffer, but ocassionaly there is missed triangle here and there for a frame, as if the atomic counter does not work as expected
      do I need any additional synchronization there ?
      I'v tried 'AllMemoryBarrierWithGroupSync' at the end of kernel, but without effect.
      If I do not use atomic counter, and istead just output empty vertices (that will transform into degenerated triangles) the all is OK - as if I'm missing some form of synchronization, but I do not see such a thing in DX11.
      I'v tested on both old and new nvidia hardware (680M and 1080, the behaviour is that same).
       
  • Popular Now