Jump to content

  • Log In with Google      Sign In   
  • Create Account


From pointers and references


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
10 replies to this topic

#1 gnomgrol   Members   -  Reputation: 584

Like
0Likes
Like

Posted 23 July 2012 - 11:33 AM

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

Edited by gnomgrol, 24 July 2012 - 01:45 AM.


Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 15164

Like
0Likes
Like

Posted 23 July 2012 - 12:12 PM

The code you posted shouldn't even compile. Can you post the actual code you're using that causes a crash?

#3 Captacha   Members   -  Reputation: 141

Like
0Likes
Like

Posted 23 July 2012 - 12:46 PM

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 calcLodLevelz to ID3D11Buffer **BufferIn. After doing those two things call the calcLOD the same and it should work. I'm also assuming that by the ... in your calcLOD function you're leaving something out. This last part is just a suggestion but I'm assuming you pass wentFine through an if statment to see if it works. If I am correct, then you can just put

if(calcLodLevelz(&vertexBuffer))

{

// do stuff

}



#4 gnomgrol   Members   -  Reputation: 584

Like
0Likes
Like

Posted 23 July 2012 - 12:59 PM

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, 23 July 2012 - 01:05 PM.


#5 ApochPiQ   Moderators   -  Reputation: 15164

Like
2Likes
Like

Posted 23 July 2012 - 02:00 PM

What is the actual error message of the crash?

#6 ApochPiQ   Moderators   -  Reputation: 15164

Like
0Likes
Like

Posted 23 July 2012 - 03:27 PM

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!

#7 Captacha   Members   -  Reputation: 141

Like
0Likes
Like

Posted 23 July 2012 - 05:39 PM

I think it would help alot if you posted the code inside the calcLodLevelz function.
EDIT: Nvm that, but can you post your updated code.

Edited by Captacha, 23 July 2012 - 05:41 PM.


#8 NightCreature83   Crossbones+   -  Reputation: 2752

Like
0Likes
Like

Posted 24 July 2012 - 01:33 AM

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, Mad Max

#9 gnomgrol   Members   -  Reputation: 584

Like
0Likes
Like

Posted 24 July 2012 - 01:42 AM

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, 24 July 2012 - 02:17 AM.


#10 gnomgrol   Members   -  Reputation: 584

Like
0Likes
Like

Posted 24 July 2012 - 02:30 AM

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.

#11 NightCreature83   Crossbones+   -  Reputation: 2752

Like
0Likes
Like

Posted 24 July 2012 - 02:30 AM

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.


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
Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max




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