Sign in to follow this  
Anand Baumunk

From pointers and references

Recommended Posts

Hello, I've got some problems with pointers and references in c++.
So what I want to do is:

[CODE]
//in class.h:
ID3D11Buffer* vertexBuffer;
//and the definition:
void calcLodLevel(ID3D11Buffer **vertexBufferIn);


//in class.cpp
void chunk::calcLodLevel(ID3D11Buffer **vertexBufferIn){
...
d3d11Device->CreateBuffer( &vertexBufferDesc, &vertexBufferData, vertexBufferIn);
}


//and in the init() of the class:
calcLodLevel(&vertexBuffer);

//Updated with Captacha's suggestion, keeps crashing the graphicdriver
[/CODE]
There really isn't more code

I just want to fill the buffer I pass into the function with the CreateBuffer D3D11 function, which takes a reference.

Well, not much stuff. But it causes my graphic driver to crash.


Can you tell me what I'm doing wrong?(My basic c++ sucks thought)
Thanks Edited by gnomgrol

Share this post


Link to post
Share on other sites
I haven't used DirectX in a while, but I'm decent in C++. First make sure you're initializing vertexBuffer somewhere. Second, change parameter 1 of [font=courier new,courier,monospace]calcLodLevelz[/font] to [font=courier new,courier,monospace]ID3D11Buffer **BufferIn[font=arial,helvetica,sans-serif]. After doing those two things call the [font=courier new,courier,monospace]calcLOD[font=arial,helvetica,sans-serif] the same and it should work. [/font][/font]I'm also assuming that by the ... in your [font=courier new,courier,monospace]calcLOD[font=arial,helvetica,sans-serif] function you're leaving something out. This last part is just a suggestion but I'm assuming you pass [font=courier new,courier,monospace]wentFine[font=arial,helvetica,sans-serif] through an if statment to see if it works. If I am correct, then you can just put[CODE]
if(calcLodLevelz(&vertexBuffer))
{
// do stuff
}
[/CODE][/font][/font][/font][/font][/font][/font]

Share this post


Link to post
Share on other sites
So if I try how you suggested, I get the 'ID3D11Buffer ***' in 'ID3D11Buffer **' error, because CreateBuffer(&vertexBufferIn) takes an ID3D11Buffer **.
When I remove the & to make it compile, it keeps crashing. Edited by gnomgrol

Share this post


Link to post
Share on other sites
[url="http://www.gamedev.net/blog/355/entry-2254834-oh-noes-my-code-is-teh-crash/"]This FAQ[/url] is a new addition, so you're off the hook for not reading it (since I literally just posted it!) - but please read it now and follow the guidelines for posting crash help requests.


Thanks!

Share this post


Link to post
Share on other sites
I think it would help alot if you posted the code inside the [font=courier new,courier,monospace]calcLodLevelz [font=arial,helvetica,sans-serif]function.[/font][/font]
[font=courier new,courier,monospace][font=arial,helvetica,sans-serif]EDIT: Nvm that, but can you post your updated code.[/font][/font] Edited by Captacha

Share this post


Link to post
Share on other sites
If you haven't turned the debug runtime of DX on yet do that now, go into your DX SDK folder in the start menu and launch "DirectX Control Panel". Then in the "Direct3D 10.x/11" tab hit "Edit list ..." in that list add your executable with the full path. After that untick "Mute all Messages" and tick all the boxes under "Message Severity". Also tick "Application Controlled" under "Debug Layer"

Create your Direct3D device with the debug layer, the D3D runtime will now inform you in your debuggers output window about what it is doing. Fix all the errors you are getting often it is a good idea to fix all the warnings as well. If you are getting to many messages you can turn off the "info" section in the panel.

Now back to your code make sure that you add error handling on all calls you make on a D3D device they return an HRESULT for a reason these functions can fail. The HRESULT will tell you why it failed as well you can use "DirectX Error Lookup" to translate these error codes into something you can understand. Then open the documentation and read the "remarks" and "return values" sections on the function you are calling, this will contain the infomation in most cases why the function failed with that error code, also the debug runtime with all messages on will often give you this information and sometimes. If a function returns E_INVALIDARG one of the arguments to the function is wrong, btw [url="http://msdn.microsoft.com/en-us/library/ff476174(v=vs.85).aspx"]here[/url] are the return codes you can get from D3D calls.

Share this post


Link to post
Share on other sites
I think you guys misunderstood me a little. I can't post any errormessage, because as soon as I compile the programm and it reaches this lines in code, my graphicdriver completly shuts down. Then it restarts with a message similar to: "Your graphicdriver has been restarted after a fatal error". I dont get any further information about it, it is NOT a compiler error, the code compiles fine.

I'll try NightCreatures suggestion as soon as I'm back home.
Checking the HRESULT of CreateBuffer (and everything else) gives just S_OK.

@ApochPiQ: Thanks for your FAQ, I read it. But it isn't really new to me, I already tried everthing of this.
The crash appears clearly because I need to pass the reference of a pointer to an ID3D11Buffer object.
I check all return values, everthing wents fine. But as soon as I try to draw the VertexBuffer I created there, it crashes my graphicdriver, which prevents me from any further investigation. Edited by gnomgrol

Share this post


Link to post
Share on other sites
I managed to find the problem, its pretty wierd anyway.
The line which draws the buffer I fill here is:
[CODE]
d3d11DevCon->DrawIndexed(numIndices, 0, 0 );
[/CODE]
Well, the numIndices was something around 10 to short. That usually only causes a few points not to be drawn, but as soon as I fixed this, it runs fine.
Thats dx11 now, but maybe someone can tell me why this is the case? I've done this mistake a few times before, and there it only caused some points to miss in the final draw.

Share this post


Link to post
Share on other sites
[quote name='gnomgrol' timestamp='1343115761' post='4962525']
I think you guys misunderstood me a little. I can't post any errormessage, because as soon as I compile the programm and it reaches this lines in code, my graphicdriver completly shuts down. Then it restarts with a message similar to: "Your graphicdriver has been restarted after a fatal error". I dont get any further information about it, it is NOT a compiler error, the code compiles fine.

I'll try NightCreatures suggestion as soon as I'm back home.
Checking the HRESULT of CreateBuffer (and everything else) gives just S_OK.
[/quote]

Even if your graphics driver crashes this shouldn't clear your debuggers output window, so the runtime message should still be available. Also make sure that the size of the data you pass into the buffer is the same as the size specified in the bufferdescriptor, I had this crash on me in a drawcall(callstack indicated a problem in the driver) when the sizes didn't match

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