Skip to main content
gamedev.net
🔒 Locked

CComPtr and ID3D10InputLayout pointer

Started by jwein 2 replies 900+ views
Original Post
jwein
jwein
Hello, I am studying the CComPtr class but when I try to use it in the D3D10Effect class of my engine it doesn't draw anything on the screen. Here's my code:


header file:
class D3DEffect : public Effect{	public:		// Constructor		D3DEffect( const std::string &filename, CComPtr <ID3D10Device> device, CComPtr <ID3D10InputLayout> inputlayout );		// Destructor		~D3DEffect();		// Selects the effect		void Use();		// Gets the effect		void* GetEffect();		// Sets the matrix		void SetMatrix( const std::string &name, Matrix4D &matrix );	private:		// Declares a DX10 Effect		CComPtr <ID3D10Effect> effect;};

source file:
D3DEffect::D3DEffect( const std::string& filename, CComPtr <ID3D10Device> device, CComPtr<ID3D10InputLayout> inputlayout ){	HRESULT hr;	// Clears the memory	ZeroMemory( &effect, sizeof( ID3D10Effect ) );	// Creates the effect	hr = D3DX10CreateEffectFromFile( filename.c_str(), NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS,										NULL, device, NULL, NULL, &effect, NULL, NULL );	// Checks if the effect has been created	if( FAILED( hr ) ) MessageBox( NULL, _T( "Cannot create the effect!" ), _T( "Essence" ), NULL );	D3D10_PASS_DESC passDesc;	// Gets the correct pass descriptor	effect->GetTechniqueByIndex( 0 )->GetPassByIndex( 0 )->GetDesc( &passDesc );	D3D10_INPUT_ELEMENT_DESC layout[] =	{		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },		{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, sizeof(float) * 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }	};	UINT elements = sizeof( layout ) / sizeof( layout[0] );	// Crea il layout per la definizione del vertice	hr = device->CreateInputLayout( layout, elements, passDesc.pIAInputSignature,										passDesc.IAInputSignatureSize, &inputlayout );	if( FAILED( hr ) ) MessageBox( NULL, _T( "Cannot create the effect!" ), _T( "Essence" ), NULL );	device->IASetInputLayout( inputlayout );}D3DEffect::~D3DEffect(){}and so on...

The problem is caused by the "CComPtr inputlayout" parameter: if I change it to "ID3D10InputLayout *inputlayout" the engine draws the meshes even if I use CComPtr for the other DirectX objects.

Could you tell I am wrong?
PS: Other comments regarding the code style are welcome.
Thank you!
DieterVW
DieterVW
Looks like you can create the input layout, but the parameter passed in is passed by value, so after the layout is created, it's not passed back out of the function - so its lifetime ends with the method ends.
jwein
jwein
I don't understand the problem, If I use a normal pointer it works. I think the problem is here...
hr = device->CreateInputLayout( layout, elements, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &inputlayout );

...but I don't know why. I think it's related in some ways with the & operator.
Anyone knows how to solve it? Thanks.
littlekid
littlekid
Perhaps you don't have to pass in the "CComPtr inputlayout" in the argument for the constructor, since you are not passing by reference.

Furthermore, I think as DieterVW said your InputLayout interface gets destroyed when it leaves the Constructor scope. You cannot release the layout until you are done using it. e.g. at the end of the program. This is because, DX10 and 11 uses weak referencing and require user to ensure a valid interface at all times, when it is being set into the pipeline.

DX10: http://msdn.microsoft.com/en-us/library/bb173589(VS.85).aspx
DX11: http://msdn.microsoft.com/en-us/library/ff476454(VS.85).aspx

regards

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.