From pointers and references

Started by
9 comments, last by NightCreature83 11 years, 9 months ago
Hello, I've got some problems with pointers and references in c++.
So what I want to do is:


//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

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
Advertisement
The code you posted shouldn't even compile. Can you post the actual code you're using that causes a crash?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

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
if(calcLodLevelz(&vertexBuffer))
{
// do stuff
}
[/font][/font][/font][/font][/font][/font]
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.
What is the actual error message of the crash?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This FAQ 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!

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

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]
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 here are the return codes you can get from D3D calls.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

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.
I managed to find the problem, its pretty wierd anyway.
The line which draws the buffer I fill here is:

d3d11DevCon->DrawIndexed(numIndices, 0, 0 );

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.

This topic is closed to new replies.

Advertisement