ID3D10DEVICE Pointer passing

Started by
6 comments, last by Guthur 15 years, 5 months ago
This is quite a newb question but is it possible to pass a pointer to ID3D10DEVICEPointer to another class. For seem reason my implementation doesn't work. ID3D10Device was created in the containing class for this but i seem to get nothing but issues trying to use the passed device. If i create the buffers in the containing class and then assign them directing it all works fine. Thanks,

int DXBufferManager::CreateBuffers(ID3D10Device** pDevice)
{
	HRESULT hr = 0;
	hr = this->CreateVertexBuffer( VB_SIZE, m_pVertexBuffer, pDevice );
	if( hr == S_OK ) hr = this->CreateVertexBuffer( TB_SIZE, m_pTransformBuffer, pDevice );
	if( hr == S_OK ) hr = this->CreateIndexBuffer( IB_SIZE, m_pIndexBuffer, pDevice );
	return 0;
}



int DXBufferManager::CreateVertexBuffer(unsigned int byteWidth, ID3D10Buffer** ppVertexBuffer, ID3D10Device** pDevice)
{
	HRESULT hr = 0;

	D3D10_BUFFER_DESC bd;
	bd.Usage = D3D10_USAGE_DYNAMIC;
	bd.ByteWidth = byteWidth;
	bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
	bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
	bd.MiscFlags = 0;

	hr = ((ID3D10Device*)*pDevice)->CreateBuffer( &bd, 0, ppVertexBuffer );
	return hr;
}


Innovation not reiterationIf at any point I look as if I know what I'm doing don't worry it was probably an accident.
Advertisement
Why are you passing an ID3D10Device**? Those are typically used when you want to output a value from your method, and not when you want to pass a value in.

You probably want to pass in an ID3D10Device*.

I'd recommend you brush up on some of the C++ basics, as you'll find things much, much simpler once you do.
Sirob Yes.» - status: Work-O-Rama.
Also, if you want to check if a call succeeded, don't use hr == S_OK, as the result isn't always S_OK even when the call succeeds.

Use the SUCCEEDED(hr) macro (or FAILED(hr)).
Sirob Yes.» - status: Work-O-Rama.
I thought that for directX Objects a alot of the time you had to pass a pointer to the pointer, in this case just the address of the D3DDevice pointer i created in the containing class. I was assuming it was something to do with reference counting or something, a COM thing i thought. If it was straight C++ i wouldn't have as much a problem of understanding.
Innovation not reiterationIf at any point I look as if I know what I'm doing don't worry it was probably an accident.
Just double checked and it really seems there would be no way it would work if i just passed the ID3D10Device*, it looks like a valid pointer in debug but the minute you call a function like pDevice->CreateBuffer( &bd, 0, ppVertexBuffer ); it causes an unhandled exception.
Innovation not reiterationIf at any point I look as if I know what I'm doing don't worry it was probably an accident.
Take a look at what the tutorials do.

As for the access violation calling any method on the device pointer, make sure the CreateDevice call isn't failing.
Sirob Yes.» - status: Work-O-Rama.
If i was doing what the tutorials were doing then i would not be having a Buffer management class now would i ;)

I know there is no problem when i create the buffers in the containing Visualisation Class, the Device is most certainly valid, I have been tweaking my already running render pipe :).

I am assumed that by your tone you are sure this should be possible with no problem. I can get away with creating the Buffers in the visualisation class before passing them to the manager but it would be nice to create them in the manager class.
Innovation not reiterationIf at any point I look as if I know what I'm doing don't worry it was probably an accident.
sirob: Ya thanks i did need a slap around the head there it was my pointers :$, doh so easy to get oneself in a muddle on which address is which.

It ended up the Device was a red herring it was the buffer pointer :p
Innovation not reiterationIf at any point I look as if I know what I'm doing don't worry it was probably an accident.

This topic is closed to new replies.

Advertisement