Jump to content

  • Log In with Google      Sign In   
  • Create Account


DirectX - Access Violations ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
19 replies to this topic

#1 -Felix-   Members   -  Reputation: 100

Like
0Likes
Like

Posted 24 February 2011 - 12:24 PM

Hey guys,


im posting here because i encountered a problem that i cannot fix :/

Ive been following this tutorial in order to get a bit familiar with realtime rendering etc. However, after running my code i got some Access-Violations during runtime. I even copied&pasted the code from the website, since i thought that i might have something wrong that i simply dont see, but the result is the same.

Okay, let me post the code first and then the errors.

Code
Spoiler


The errors i get after running the programm for ~ 3 sec :

Untreated exception at 0x663c11c2 in DCX11_2.exe: 0xC0000005: Accesviolation reading at position 0x00000198.


Below( i dont know what it is, the lable says " auto" ) there are 2 things listed :

D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST 4 int

and

devcon 0x00ca66f0 ID3D11DeviceContext * ( in red ) .


The last call on the Call stack :

> DCX11_2.exe!RenderFrame() line 201 + 0x19 Bytes


Which is nothing else than the function

devcon->Draw(3, 0);

in RenderFrame().

One thing that doesnt "feel" right to me, is the "Shaders.hlsl"-thing. I had to use Pixel and Vertexshader in order to render ( as the tutorial says) and were given the Shader-code by the tutorial :
struct VOut
{
	float4 position : SV_POSITION;
	float4 color : COLOR;
};

VOut VShader(float4 position : POSITION, float4 color : COLOR)
{
	VOut output;

	output.position = position;
	output.color = color;

	return output;
}


float4 PShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
{
	return color;
}


I have no idea how to read this code, the tutorial says that it's going to teach how to in the next step.
I saved this code as "Shaders.hlsl" under .../Documents/visual studios 2010/Projects/MyProjectName/MyProjectName

I don't know if these Shaders are the problem. I absolutely have no idea how to deal with Acces-violation errors, they're a total mystery for me.

At this point i would like to thank you for reading through all this and i hope that someone of you guys knows how to fix this.

Thanks in advance !

Regards
-Felix-

Sponsor:

#2 Buckeye   Crossbones+   -  Reputation: 4079

Like
1Likes
Like

Posted 24 February 2011 - 12:47 PM

The particular tutorials you link to are very poor with regard to learning proper programming practice. To start with, every DirectX and windows function provides some indication of success or failure. It doesn't appear that you (or the ill-formed code on directxtutorial.com) check for any errors. Check the documentation for the function calls you make and look for return values or error indications indicating whether the function fails or succeeds. Questions for you to answer by adding error-checking code: does your window get registered? Does your window get created? Do your device and swapchain get created successfully? etc., etc.

Have you worked through the examples in the SDK? Take a look at how that code is setup, how errors are detected, etc.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#3 -Felix-   Members   -  Reputation: 100

Like
0Likes
Like

Posted 24 February 2011 - 12:55 PM

Hmmm. the tutorials on the site i linked to seemed very HQ to me, since everything is explained etc. However, i will do what you told me to and try to add some message boxes, to check whether or not functions got executed correctly.

I doubt that i understand anything in the SDK examples, because i guess they use tons of COM-Objects that i dont have a clue of. But i will try, eventually googeling for things that i dont know.

#4 Buckeye   Crossbones+   -  Reputation: 4079

Like
0Likes
Like

Posted 24 February 2011 - 01:03 PM

the tutorials on the site i linked to seemed very HQ to me

How high quality can code be that doesn't work? I'm not saying the processes described there aren't useful. However, there's an underlying assumption there that the code will never produce errors. In my opinion, that's a very poor style of programming to be teaching anyone, particularly if it's directed at beginners.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#5 -Felix-   Members   -  Reputation: 100

Like
0Likes
Like

Posted 24 February 2011 - 01:38 PM

Edit : Hold it, wrong language. Second.


Edit 2 : Okay :P
To the "Wrong-ness" of the code : I doubt that it's actually WRONG, i guess i set something up uncorrectly. However, ure right about the thing that you should check for errors. But i can't see to find any better resource to learn DirectX from.

So, i checked all the functions that LET me check them ( that do not have a void return type). They usually return S_OK if they suceeded. All of those functions seem to have worked ( at leat my MessageBoxes tell me that ). But i cant find a way to check whether or not CreateVertexShader and CreatePixelShader succeded. According to MSDN their return type should be "D3D_OK" if they succeded. But if i check that, using this constant, my compiler tells me that he does not know this identifier. So i dont know how to check those two functions, though i guess that they worked anyways.

#6 Buckeye   Crossbones+   -  Reputation: 4079

Like
0Likes
Like

Posted 24 February 2011 - 02:12 PM

According to MSDN their return type should be "D3D_OK" if they succeded. But if i check that, using this constant, my compiler tells me that he does not know this identifier

It's semantics, but don't confuse return type with return value. The return type is HRESULT. With regard to D3D_OK, be sure to check the documentation for the DirectX version you're using. D3D_OK is defined for Dx9. There are other return codes for other versions of DirectX.

i checked all the functions that LET me check them ( that do not have a void return type)

Check the documentation for the function. Just because it returns void doesn't mean there's no indication for possible errors.

Any in particular that're giving you problems?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#7 Aardvajk   Crossbones+   -  Reputation: 5852

Like
1Likes
Like

Posted 24 February 2011 - 02:16 PM

HRESULT h=Whatever();

if(FAILED(h)) WeHaveAProblem();

D3D return codes use archane bitwise stuff. Be a cool kid and use FAILED() a lot.

Anyway, that being as it may, enable the DirectX debug mode from your DirectX control panel (it's in your start menu if you've installed the SDK) then absorb what it tells you.

#8 -Felix-   Members   -  Reputation: 100

Like
0Likes
Like

Posted 24 February 2011 - 04:21 PM

Oh, yea. return type != return value, i actually knew that :P At least i hope i did ... Anyway, im using Dx11, so it's probably the wrong one. By saying "check the docu", do you mean the MSDN-docu or the actual docu-file comming with the SDK ?
However, i used the macro Aardvajk posted and it seems like those two functions failed ( CreateVertexShader and CreatePixelShader). However, im having a freaking hard time of getting the Error-Code in a MessageBox via GetLastError. MessageBox requires a string as 2nd argument, so i tried itoa(GetLastError(),buffer,10), but it told be something about the POSIX would not be right. Wow, im seriously failing atm... I'll better try this tomrrow, won't get any results in my current status :P





#9 Buckeye   Crossbones+   -  Reputation: 4079

Like
0Likes
Like

Posted 24 February 2011 - 04:37 PM

do you mean the MSDN-docu or the actual docu-file comming with the SDK ?

If you have the latest SDK, the MSDN documentation and the SDK documentation should be the same.

With DirectX functions. you don't use GetLastError. You already have the error in the return code. Take a look at DXGetErrorDescription or DXGetErrorString.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#10 -Felix-   Members   -  Reputation: 100

Like
0Likes
Like

Posted 25 February 2011 - 10:26 AM

Ahhh okay, thanks for those two functions. I used them with those two functions who failed and the error message is : " E_INVALIDARG". Some arguement seems to be invalid ?

#11 Buckeye   Crossbones+   -  Reputation: 4079

Like
0Likes
Like

Posted 25 February 2011 - 11:37 AM

Ahhh okay, thanks for those two functions. I used them with those two functions who failed and the error message is : " E_INVALIDARG". Some arguement seems to be invalid ?

If you're coding things correctly, it sounds like it. You don't mention what you're checking or which functions in particular you're checking. If they're the CreateVertexShader calls, have you checked that CompileFromFile calls are successful?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#12 -Felix-   Members   -  Reputation: 100

Like
0Likes
Like

Posted 25 February 2011 - 05:12 PM

Yes. i checked them and they seem to work just fine. Doesnt make much sense that CreateVertexShader does not work, when CompileFromFile DID work. Weird.

#13 Erik Rufelt   Crossbones+   -  Reputation: 3176

Like
0Likes
Like

Posted 25 February 2011 - 05:31 PM

Check your feature levels. If you compile for vs_5_0 for example, you need a feature level 11 device, while vs_4_0 requires 10.0, and for lower levels there's vs_4_0_level_9_1 and vs_4_0_level_9_3. If you create your device with the D3D11_CREATE_DEVICE_DEBUG flag and run your app with the debugger, you will see debug output that will most likely tell you why the shader couldn't be created.

#14 Aardvajk   Crossbones+   -  Reputation: 5852

Like
0Likes
Like

Posted 26 February 2011 - 01:17 AM

WHAT DOES THE FRICKING DEBUG RUNTIME SAY IF YOU ENABLE IT?

Sorry to shout, but get easily frustrated.

#15 ankhd   Members   -  Reputation: 1186

Like
0Likes
Like

Posted 26 February 2011 - 06:27 AM

get the books introduction to 3d game programming with directx 9.0c
a shaders approach by Frand d. Luna

and or the directx 10 book with the same name , he may even have dx 11 book now.

#16 mhagain   Crossbones+   -  Reputation: 7603

Like
0Likes
Like

Posted 26 February 2011 - 08:05 AM

WHAT DOES THE FRICKING DEBUG RUNTIME SAY IF YOU ENABLE IT?

Sorry to shout, but get easily frustrated.


This. Switch on the debug runtime and run your program. Use the tools you have, they are there to help you solve problems like this.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#17 -Felix-   Members   -  Reputation: 100

Like
0Likes
Like

Posted 26 February 2011 - 11:05 AM

Okay okay. I tried to do what you told be, but i actually failed.

I used the D3D11_CREATE_DEVICE_DEBUG flag with the D3D11CreateDeviceAndSwapChain() function, but using this flag makes the function-call fail. So i looked up what else i should do in order to make the function work with this flag, but i cannot see any folder named "DirectX Utilities" in my DirectX SDK-folder ( the tutorial i found wanted me to change something using the DirectX Control pannel, but there simply IS none in my SDK-folder). So, if i call the function with the DEBUG-flag, i get an error-code as return-value that means this : " Attempted to create a device with the debug layer enabled and the layer is not installed."

#18 Erik Rufelt   Crossbones+   -  Reputation: 3176

Like
0Likes
Like

Posted 26 February 2011 - 11:30 AM

Uninstall any old SDK and download and re-install the newest: http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=3021d52b-514e-41d3-ad02-438a3ba730ba
Then try again.

The control panel should be in "...\Microsoft DirectX SDK (June 2010)\Utilities\bin\x86\dxcpl.exe" or x64 for 64-bit. You shouldn't need it for D3D11 as you can use the flag when creating the device instead.

Maybe you need to make sure you're an administrator on the computer, but not sure about that...

And update your graphics drivers while you're at it, not just from Windows Update but directly from the Nvidia/AMD/Intel sites.

#19 -Felix-   Members   -  Reputation: 100

Like
0Likes
Like

Posted 26 February 2011 - 11:53 AM

This is exactly the one i have installed and the exact same link where i downloaded it from. However, i'll download and install it again, because the "Ultility"-subfolder simply doesnt exist in my DirectX-SDK folder.
However, i was using DirectX11, so according to you, it should work without any further settings and by only using the DEBUG-Flag when creating the Device etc ? But it doesnt, hmm.


Im also currently downloading the latest drivers for my graphic card, thank you for that hint. But what's the use of it ?

#20 Infinity95   Members   -  Reputation: 272

Like
0Likes
Like

Posted 03 February 2012 - 01:50 PM

The reason this doesn't work is because you are using HLSL Shader Model 5 but your graphics card most likely doesn't support it. Try using vs_4_0 and ps_4_0

Edit: Sorry for digging up this thread. Didn't see the date.

"Errare humanum est, sed in errare perseverare diabolicum."





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS