Sign in to follow this  

ID3D10DEVICE Pointer passing

This topic is 3317 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 3317 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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