   [Solved]D3D10 Create Buffer access violation
  I'm experimenting with direct 3d 10 for the first time and have run into a very odd problem.  Everything was going fine until I tried to create a vertex buffer using:hr = pD3DDevice->CreateBuffer(&vbDesc,&init,&vBuffer);The code builds and runs but then breaks at the line above with the following error:First-chance exception at 0x6832d877 in RTRTEpoch2.exe: 0xC0000005: Access violation reading location 0x00000000.The odd thing is that the only parameter that is 0x00000000 is the vBuffer parameter, which I thought was supposed to be?  I can see the data in the other two parameters fine.Can anyone help with this?Thanks in advance.[Edited by - Tim Ingham-Dempster on June 24, 2009 9:48:24 AM]
Quote:Original post by Tim Ingham-DempsterThe odd thing is that the only parameter that is 0x00000000 is the vBuffer parameter, which I thought was supposed to be?  I can see the data in the other two parameters fine.Can anyone help with this?pD3DDevice is null.   ;  It can't be 0x00000...are you sure are you passing a pointer to pointer?   ;  pD3DDevice doesn't seem to be null, it has an address when I mouse over it in debug, and I've already created an effect and an Input Layout with it by this point.   ;  vBuffer is declared as:ID3D10Buffer* vBuffer;and I set it to NULL in the constructor of the window class.   ;  Hmm, interesting. Have you tried logging the values to a file or the debug output in case the debugger is wrong?Are any of those variables members of classes? If so, is the this pointer valid?   ;  Some of the parameters were in the mesh class, but I moved them into the function with the CreateBuffer call in case this was the problem.  I'm not sure how to log the debug output into a file.  I'm using VS2008 so I expected it to be fairly reliable for debugging.  What would be the best way to double check it?   ;  One thing you could try is enabling the debug runtimes. Just pass the D3D10_CREATE_DEVICE_DEBUG flag to D3D10CreateDevice().That should get you some more error messages in the debug output.   ;  It is because you are passing the address of NULL. Just pass NULL if you are interested in validating the parameters. Here's a little test program that mimics the above:#include <iostream>using namespace std;void funcTest( int** ptr ) {    if( ptr == NULL )   cout << "Yes, it is NULL" << endl;}int main( int argc, char** argv ) {    int* ptr = NULL;    funcTest( &ptr );    return 0;}You're retrieving the address that holds 0x00000000, therefore it will not be NULL, thus fooling D3D10; furthermore, D3D10 tries to write to this address, resulting in your access violation. Change your function call to this:hr = pD3DDevice->CreateBuffer(&vbDesc,&init,NULL);You could do this as well:hr = pD3DDevice->CreateBuffer(&vbDesc,&init,(ID3D10Buffer**)vb);But that just overcomplicates things when you could use the above. ;)   ;  Ok, it works when I pass NULL instead of &vBuffer, but that still doesn't create a vertex buffer.  Does this suggest something that I should change to create the buffer?  Also, I've output the address of the three parameters, plus pD3DDevice to a text file and they all have values assigned to them.   