Sign in to follow this  
Magnar Harestad

DirectX Tutorial.com - App crashes

Recommended Posts

Hi,
I've tried to use the code example from DirectX Tutorial.com to create a basic triangle in a DirectX win32 application.

Project built in Visual Studio, library paths fixed etc. Tried to change driver specification from HARDWARE to REFENCE, didn't solve crash issue.

Tutorial code I tried to use was: [url="http://www.directxtutorial.com/Tutorial11/B-A/BA5.aspx#still"]http://www.directxtu.../BA5.aspx#still[/url]

Picture of crash:
[url="http://www.harestad.info/pictures/DirectX3d_Crash.jpg"]http://www.harestad....ctX3d_Crash.jpg[/url]

I also had to add #include <StdAfx.h> at start of project, otherwise the build would not work in Visual Studio.
Which wasn't mentioned in the code example on the tutorial place. When I add it, build goes ok, but a Error comes that says it cannot find it.
1 IntelliSense: cannot open source file "StdAfx.h" c:\users\administratör\documents\visual studio 2010\projects\directx_test\directx_test\directx_test.cpp 2 2 DirectX_Test

[font=Consolas][size=1][font=Consolas][size=1]1>------ Build started: Project: DirectX_Test, Configuration: Debug Win32 ------[/size][/font][/size][/font]
[font=Consolas][size=1][font=Consolas][size=1]1> DirectX_Test.cpp[/size][/font][/size][/font]
[font=Consolas][size=1][font=Consolas][size=1]1> DirectX_Test.vcxproj -> C:\Users\Administratör\documents\visual studio 2010\Projects\DirectX_Test\Debug\DirectX_Test.exe[/size][/font][/size][/font]
[font=Consolas][size=1][font=Consolas][size=1]========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========[/size][/font][/size][/font]

Anyone able to figure out why my application after build doesn't work?

And why I need to put that include of StdAfx.h - that Visual Studio cannot even find?

Cheers Magnar

Share this post


Link to post
Share on other sites
I might add to say that all examples before the triangle is to be drawn works fine. So the first example of the "white screen" works. Also the "blue screen" example works. But not the example where it draws the triangle.

Share this post


Link to post
Share on other sites
[quote name='Tom KQT' timestamp='1335510796' post='4935315']
And what does the error message say? I don't think many people here will understand it.
[/quote]
Clearly it says the same thing all app crashes say under Windows: DirectX_Test.exe has stopped working, Windows is searching for a solution to the problem (or something along those lines). So it doesn't actually say anything about the issue itself.

You should be putting a breakpoint in your application's entry and stepping until you encounter the crash (or just spam printf's everywhere), it's probably not DirectX that's failing here but StdAfx.h, since you said previous examples work.

If it is DirectX failing then it might be worthwhile turning on the debug layer and looking at the output via some tool like DebugView (but I think you need to install the SDK for that to work).

Share this post


Link to post
Share on other sites
Hi again,
It seems to be a issue on the shader load.

On the last line of the code in the text-cut below is where the debugger crashes.

[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]// this function loads and prepares the shaders[/color][/size][/font][/color][/size][/font][/color][/size][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] InitPipeline()[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]
[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]// load and compile the two shaders[/color][/size][/font][/color][/size][/font][/color][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]ID3D10Blob *VS, *PS;[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]D3DX11CompileFromFile(L[/size][/font][/size][/font]
[font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"shaders.hlsl"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"], 0, 0, [/size][/font][/size][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"VShader"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"], [/size][/font][/size][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"vs_5_0"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"], 0, 0, 0, &VS, 0, 0);[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]D3DX11CompileFromFile(L[/size][/font][/size][/font]
[font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"shaders.hlsl"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"], 0, 0, [/size][/font][/size][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"PShader"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"], [/size][/font][/size][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"ps_5_0"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"], 0, 0, 0, &PS, 0, 0);[/size][/font][/size][/font]
[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]// encapsulate both shaders into shader objects[/color][/size][/font][/color][/size][/font][/color][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]The Debugger error is:[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]Unhandled exception at 0x771115de in DirectX_Test.exe 0xc0000005: Access violation reading location 0x00000000.[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]The shaders.hlsl file is part of the project together with the cpp file. And the shaders file includes the code that is on the tutorial webpage. [/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]Why is it crashing on the dev->CreateVertexShader line?[/size][/font][/size][/font]

Share this post


Link to post
Share on other sites
[quote name='Bacterius' timestamp='1335512761' post='4935317']
You should be putting a breakpoint in your application's entry and stepping until you encounter the crash (or just spam printf's everywhere), it's probably not DirectX that's failing here but StdAfx.h, since you said previous examples work.
[/quote]

I also had to put in #include <StdAfx.h> on the other examples (the white screen and the blue screen), and both of those examples worked. So I kind of think that the StdAfx.h is just needed for Visual Studio itself to easier rebuild the headers etc. And that part works fine.

The problems seems to me to be either the load of the shaders.hlsl file doesn't work as intended, or there is something else that does work with the shader function invoked. Very strange, though?

Share this post


Link to post
Share on other sites
Ah, I see. Then it isn't StdAfx.h, but something related to shader code. My guess is the vertex shader is not created (compilation fails), which causes VS to remain uninitialized, which will cause an access violation upon creating the shader. Can you post your shader code? And also print out the value D3DX11CompileFromFile returns? This will tell us whether compilation actually succeeded (it's important to print out every return value from all directx functions when debugging an application, since calls will fail silently and then cause the rest of your program to crash in random places.

Share this post


Link to post
Share on other sites
This is the shader code. And, to be honest, this is straight off from the tutorial.

[font="Consolas"][size="2"][font="Consolas"][size="2"]struct VOut[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]float4 position : SV_POSITION;[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]float4 color : COLOR;[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]};[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]VOut VShader(float4 position : POSITION, float4 color : COLOR)[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]VOut output;[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]output.position = position;[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]output.color = color;[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]return output;[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]?[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]float4 PShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]return color;[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

Share this post


Link to post
Share on other sites
No clue. This should work AFAICT. Please create the D3D device with the Debug flag (installing the DirectX SDK if needed), then install DebugView, run the code with it, and look at the output. If DirectX is having trouble compiling your shader, the debug layer will tell you what's wrong in detail. This is strange though.

Out of interest, what's your hardware? And what are your current D3D11 settings (if you've installed the SDK, you can look those up in the control panel). And are you compiling this code in 32-bit or 64-bit mode?

Share this post


Link to post
Share on other sites
Can you post the code for your input layout creation and structure?

Do your verticies contain a color vector?

Check out [url="http://www.rastertek.com/"]http://www.rastertek.com/[/url] he has some tutorials which I think I better than the tutorials you are referencing.

Share this post


Link to post
Share on other sites
That's the problem with directxtutorial and why it is shunned here. No error checking.

I'm pretty sure that D3DX11CompileFromFile is failing. Check the result code everything you call, never assume that it'll work. Are the .hlsl files in the main project folder?

The crash is a NULL pointer access in the line the debugger showed you.

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