DirectX Tutorial.com - App crashes

Started by
9 comments, last by Endurion 11 years, 12 months ago
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: http://www.directxtu.../BA5.aspx#still

Picture of crash:
http://www.harestad....ctX3d_Crash.jpg

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 ------[/font][/font]
[font=Consolas][size=1][font=Consolas][size=1]1> DirectX_Test.cpp[/font][/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[/font][/font]
[font=Consolas][size=1][font=Consolas][size=1]========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========[/font][/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
Advertisement
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.
And what does the error message say? I don't think many people here will understand it.

And what does the error message say? I don't think many people here will understand it.

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).

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

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[/font][/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] InitPipeline()[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/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[/font][/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]ID3D10Blob *VS, *PS;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]D3DX11CompileFromFile(L[/font][/font]
[font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"shaders.hlsl"[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"], 0, 0, [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"VShader"[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"], [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"vs_5_0"[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"], 0, 0, 0, &VS, 0, 0);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]D3DX11CompileFromFile(L[/font][/font]
[font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"shaders.hlsl"[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"], 0, 0, [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"PShader"[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"], [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"ps_5_0"[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"], 0, 0, 0, &PS, 0, 0);[/font][/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[/font][/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);[/font][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]The Debugger error is:[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]Unhandled exception at 0x771115de in DirectX_Test.exe 0xc0000005: Access violation reading location 0x00000000.[/font][/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. [/font][/font]

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

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.


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?
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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

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[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]float4 position : SV_POSITION;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]float4 color : COLOR;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]};[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]VOut VShader(float4 position : POSITION, float4 color : COLOR)[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]VOut output;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]output.position = position;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]output.color = color;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]return output;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]?[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]float4 PShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]return color;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]
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?

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Can you post the code for your input layout creation and structure?

Do your verticies contain a color vector?

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

Brendon Glanzer

This topic is closed to new replies.

Advertisement