Problem mit den Effects11.lib



  • Moin moin zusammen,

    ich habe gerade ein nerviges Problem mit meiner Effects11d.lib und Effects11.lib da ich von Visual Studio 2010 auf die 2012 Version gewechselt habe und somit sich ja auch das Toolset ändert. Die beiden .lib habe ich frisch mit VS2012 gebuildet und die alten ersetzt, doch leider hat das anscheinend nicht ganz funktioniert da ich keine Objekte wie z.B.

    ID3D11ShaderResourceView*
    

    erstellen kann. Woran kann das liegen und gibt es beim Builden der libs irgendwas spezielles zu beachten was ich ev. vergessen haben könnte?



  • Was heißt "nicht erstellen kann"? Unreferenzierte Funktionen? Vielleicht hast du die Zielplattform vertauscht (x86 <-> x64).



  • Okay, habe mich vermutlich auch ein wenig falscha ausgedrückt.
    Ich kann ID3D11ShaderResourceView* instanzieren aber nicht darauf zugreifen, wenn ich es mir in VS anschauen möchte -> unable to read memory -> später wenn ich es brauche wirft mir VS eine Access Violation um die Ohren. Zielplatform sollte eigentlich stimmen.



  • Sicher, dass richtig instanziert wird? Hast du mal überprüft, ob ein gültiger Zeiger zurückgegeben wird bzw. was der Fehler-Code aussagt?



  • Ich bin mir ziemlich siche denn der selbe Code hat ja schon mal funktioniert, nur unter Visual Studio 2010. Das einzigste was ich gemacht habe ist der Klasse CSprite einige Member Variabeln, Getter und Setter entnommen und diese in eine neue Klasse Names CObject gepackt habe und CSprite das nun vererbt bekommt. Aber ich denke nicht das es an der Vererbung liegt oder?

    Beim NULL setzten des Zeigers im Constructor kann ich bereits den Speicher nicht mehr lesen -> Unable to read memory...
    Einen richtigen Fehlercode gibt es nicht, erst als ich den Pointer in einer Funktion von DirectX brauche bekomme ich diese Meldung von VS:

    Unhandled exception at 0x00D774A8 in Engine.exe: 0xC0000005: Access violation reading location 0x00000000.

    Inzwischen vermute ich das es nicht direkt an der Effects11.lib liegt...

    Edit:
    So, der aktuelle Code um den es geht.

    #ifndef __OBJECT_H__
        #define __OBJECT_H__
    
        #include "../DX11Core/DX11Util.h"
    
        class CObject
        {
        public:
                CObject();
                ~CObject(){}
    
                void SetStatus( STRING _status )                { m_status = _status; }
                void SetTag( STRING _tag )                      { m_tag = _tag; }
                void SetPosition( float _x, float _y, float _z ){ SetPosition( XMFLOAT3( _x, _y, _z ) ); }
                void SetPosition( XMFLOAT3 _pos )               { m_position = _pos; }
                void SetRotation( float _rot )                  { m_fRotation = _rot; }
                void SetScale( float _x, float _y )             { SetScale( XMFLOAT3( _x, _y, 1 ) ); }
                void SetScale( XMFLOAT3 _scale )                { m_scale = _scale; }
                void SetAlpha( float _alpha )                   { m_fAlpha = Clamp( _alpha, 0.0f, 1.0f ); }
                void SetActive( bool _active )                  { m_bActive = _active; }
    
                XMFLOAT3&       GetPosition()                   { return m_position; }
                STRING          GetStatus()                     { return m_status; }
                STRING          GetTag()                        { return m_tag; }
                float           GetXPosition()                  { return m_position.x; }
                float           GetYPosition()                  { return m_position.y; }
                float           GetZPosition()                  { return m_position.z; }
                float           GetRotation()                   { return m_fRotation; }
                XMFLOAT3&       GetScale()                      { return m_scale; }
                float           GetXScale()                     { return m_scale.x; }
                float           GetYScale()                     { return m_scale.y; }
                bool            IsActive()                      { return m_bActive; }
    
        protected:
                XMFLOAT3        m_position;
                STRING          m_tag;
                STRING          m_status;
                float           m_fRotation;
                XMFLOAT3        m_scale;
                float           m_fAlpha;
                bool            m_bActive;
        };
    
        #endif // __OBJECT_H__
    
    #ifndef __SPRITE_H__
        #define __SPRITE_H__
    
        #include "Object.h"
        #include "../DX11Core/DX11Core.h"
        #include "../DX11Core/GraphicHelper.h"
    
        struct Vertex
        {
                XMFLOAT3 Pos;
                XMFLOAT2 Tex;
        };
    
        class CSprite : public CObject
        {
        public:
                CSprite( STRING _filename );
                ~CSprite()
                {
                        RELEASE_COM( m_pVertices );
                        RELEASE_COM( m_pTextureSampler );
                        RELEASE_COM( m_pTextureSRV );
                }
    
                int Initialize();
                int Update( const float _dt );
                void Render();
    
        #pragma region Getter & Setter
    
                void SetTexture( STRING _filename );
                void SetFrameCount( int _framecount ) { m_nFrameCount = _framecount; }
                void SetFrame( int _frameidx )
                {
                        if( _frameidx >= 0 && _frameidx < m_nFrameCount )
                        {
                                m_nActualFrame = _frameidx;
                        }
                        BuildVertices();
                }
                void SetPosition( XMFLOAT3& _pos )
                {
                        m_position = _pos;
                        m_position.x -= ( theDXCore->GetClientWidth() / 2 );
                        m_position.y *= -1.0f;
                        m_position.y += ( theDXCore->GetClientHeight() / 2 );
                }
    
                float           GetLeftBounding() const         { return ( m_position.x + m_fBoundingLeft ); }
                float           GetRightBounding() const        { return ( m_position.x + m_fBoundingRight ); }
                float           GetTopBounding() const          { return ( m_position.y + m_fBoundingTop ); }
                float           GetBottomBounding() const       { return ( m_position.y + m_fBoundingBottom ); }
                int             GetFrameIdx() const             { return m_nActualFrame; }
                XMMATRIX        GetWorldMatrix() const;
                Vertex          GetVertex( int _i) const        { return tempVertex[_i]; }
    
        #pragma endregion
    
        private:
                void BuildVertices();
    
                int             m_nFrameCount;
                int             m_nActualFrame;
                float           m_fFrameDT;
                float           m_fActualFrameDT;
    
                float           m_fBoundingLeft;
                float           m_fBoundingRight;
                float           m_fBoundingTop;
                float           m_fBoundingBottom;
    
                Vertex tempVertex[6];
    
                ID3D11Buffer*                           m_pVertices;
                ID3D11ShaderResourceView*               m_pTextureSRV;
                ID3D11SamplerState*                     m_pTextureSampler;
                ID3DX11EffectMatrixVariable*            m_pFXWorld;
                ID3DX11EffectShaderResourceVariable*    m_pFXTexture;
                ID3DX11EffectSamplerVariable*           m_pFXTextureSampler;
        };
    
        #endif //__SPRITE_H__
    

    Die Access Violation wird in Zeile 69 geworfen aber selbst mein CreateSRV() (Zeile 16) im Constructor funktioniert nicht weil keine Ahnung, es wird kein Fehler ausgegeben und eine Access Violation wie in Zeile 69 fehlt auch aber "Unable to read memory" wenn ich sehen möchte was drinnen steht...

    #include "Sprite.h"
    #include "SpriteManager.h"
    
    CSprite::CSprite( STRING _filename )
    	: m_nFrameCount( 1 )
    	, m_nActualFrame( 0 )
    	, m_pTextureSRV( 00 )
    	, m_pTextureSampler( 00 )
    	, m_pVertices( 00 )
    	, m_pFXWorld( 00 )
    	, m_pFXTexture( 00 )
    	, m_pFXTextureSampler( 00 )
    	, m_fFrameDT( 1000.0f )
    	, m_fActualFrameDT( 0.0f )
    {
    	GraphicHelper::CreateSRV( m_pTextureSRV, _filename );
    
    	this->Initialize();
    }
    
    int CSprite::Initialize()
    {
    	D3D11_SAMPLER_DESC samplerDesc = {};
    	samplerDesc.AddressU = samplerDesc.AddressV = samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
    	samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
    	samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
    	//	samplerDesc.Filter = D3D11_FILTER_ANISOTROPIC;
    	//	samplerDesc.MaxAnisotropy = 4;
    	samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
    	HR( theDevice->CreateSamplerState( &samplerDesc, &m_pTextureSampler ) );
    
    	BuildVertices( );
    
    	D3D11_SAMPLER_DESC colorMapDesc = {};
    	colorMapDesc.AddressU = colorMapDesc.AddressV = colorMapDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
    	colorMapDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
    	colorMapDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
    	//	colorMapDesc.Filter = D3D11_FILTER_ANISOTROPIC;
    	//	colorMapDesc.MaxAnisotropy = 4;
    	colorMapDesc.MaxLOD = D3D11_FLOAT32_MAX;
    	HR( theDevice->CreateSamplerState( &colorMapDesc, &m_pTextureSampler ) );
    
    	m_pFXWorld			= theSpriteManager->GetFX()->GetVariableByName( "gWorld" )->AsMatrix();
    	m_pFXTexture		= theSpriteManager->GetFX()->GetVariableByName( "gTexture" )->AsShaderResource();
    	m_pFXTextureSampler	= theSpriteManager->GetFX()->GetVariableByName( "gTextureSampler" )->AsSampler();
    
    	return 0;
    }
    
    void CSprite::SetTexture( STRING _filename )
    {
    	GraphicHelper::CreateSRV( m_pTextureSRV, _filename );
    }
    
    XMMATRIX CSprite::GetWorldMatrix() const
    {
    	XMMATRIX translation = XMMatrixTranslation( m_position.x, m_position.y, m_position.z );
    	XMMATRIX rotationZ = XMMatrixRotationZ( m_fRotation );
    	XMMATRIX scale = XMMatrixScaling( m_scale.x, m_scale.y, 1.0f );
    
    	return scale * rotationZ * translation;
    }
    
    void CSprite::BuildVertices()
    {
    	RELEASE_COM( m_pVertices );
    
    	ID3D11Resource* pcolorTex = 00;
    	m_pTextureSRV->GetResource( &pcolorTex );
    
    	D3D11_TEXTURE2D_DESC colorTexDesc = {};
    	( reinterpret_cast<ID3D11Texture2D*>( pcolorTex ) )->GetDesc( &colorTexDesc );
    	pcolorTex->Release();
    
    	colorTexDesc.Width /= m_nFrameCount;
    	// Calculate corners for uneven boundings
    	float left = -(float)(int)( colorTexDesc.Width * 0.5f );
    	float right = (float)((int)( colorTexDesc.Width * 0.5f ) );
    	if( colorTexDesc.Width % 2 == 1 ) right += 1.0f;
    	m_fBoundingLeft = left;
    	m_fBoundingRight = right;
    
    	float top = (float)(int)( colorTexDesc.Height * 0.5f );
    	float bottom = -(float)(int)( colorTexDesc.Height * 0.5f );
    	if( colorTexDesc.Height % 2 == 1 ) bottom -= 1.0f;
    	m_fBoundingTop = top;
    	m_fBoundingBottom = bottom;
    
    	float FrameWidth = 1.0f / m_nFrameCount;
    	// Create Vertexbuffer
    
    	Vertex vertices[] =
    	{
    		{ XMFLOAT3( right, top, 1.0f ),    XMFLOAT2( FrameWidth * ( m_nActualFrame + 1 ), 0.0f ) },
    		{ XMFLOAT3( right, bottom, 1.0f ), XMFLOAT2( FrameWidth * ( m_nActualFrame + 1 ), 1.0f ) },
    		{ XMFLOAT3( left, bottom, 1.0f ),  XMFLOAT2( FrameWidth * ( m_nActualFrame     ), 1.0f ) },
    
    		{ XMFLOAT3( left, bottom, 1.0f ),  XMFLOAT2( FrameWidth * ( m_nActualFrame     ), 1.0f ) },
    		{ XMFLOAT3( left, top, 1.0f ),     XMFLOAT2( FrameWidth * ( m_nActualFrame     ), 0.0f ) },
    		{ XMFLOAT3( right, top, 1.0f ),    XMFLOAT2( FrameWidth * ( m_nActualFrame + 1 ), 0.0f ) },
    	};
    
    	D3D11_BUFFER_DESC vdesc = {};
    	vdesc.Usage = D3D11_USAGE_IMMUTABLE;
    	vdesc.ByteWidth = sizeof( Vertex ) * ARRAYSIZE( vertices );
    	vdesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    	D3D11_SUBRESOURCE_DATA vdata = {};
    	vdata.pSysMem = vertices;
    	HR( theDevice->CreateBuffer( &vdesc, &vdata, &m_pVertices ) );
    
    	memcpy( &tempVertex, vertices, sizeof( vertices ) );
    }
    
    int CSprite::Update( const float _dt )
    {
    	m_fActualFrameDT -= _dt;
    	if( m_fActualFrameDT < 0.0f )
    	{
    		m_fActualFrameDT = m_fFrameDT;
    
    		int i = m_nActualFrame + 1;
    		if( i >= m_nFrameCount ) i = 0;
    
    		SetFrame( i );
    	}
    
    	return ERROR_SUCCESS;
    }
    
    void CSprite::Render()
    {
    	UINT stride = sizeof( Vertex );
    	UINT offset = 0;
    	theContext->IASetVertexBuffers( 0, 1, &m_pVertices, &stride, &offset );
    	XMMATRIX world = GetWorldMatrix();
    	m_pFXWorld->SetMatrix( reinterpret_cast<float*>( &world ) );
    	m_pFXTexture->SetResource( m_pTextureSRV );
    	m_pFXTextureSampler->SetSampler( 0, m_pTextureSampler );
    
    	D3DX11_TECHNIQUE_DESC techDesc = {};
    	theSpriteManager->GetFXTech()->GetDesc( &techDesc );
    
    	for( UINT p = 0; p < techDesc.Passes; ++p )
    	{
    		theSpriteManager->GetFXTech()->GetPassByIndex( p )->Apply( 0, theContext );
    
    		theContext->Draw( 6, 0 );
    	}
    }
    


  • Der Fehler klingt doch offensichtlich:
    Es findet eine Speicherzugriffsverletzung (0xC0000005) statt, weil ein Nullzeiger (location 0x00000000) wie ein Zeiger auf eine erstellte Instanz behandelt wird. Deine CSprite::BuildVertices Funktion ist allein schon unsicher, weil sie nicht prüft, ob sie m_pTextureSRV überhaupt verwenden kann. Und GraphicHelper::CreateSRV verändert m_pTextureSRV wahrscheinlich auch nicht, weil nur der Zeigerwert übergeben und dessen Kopie in jener Funktion verändert wird, nicht aber im Ursprung.



  • Sorry für die verspätete Antworte...

    Ups, darauf habe ich gar nicht geachtet, irgendwie habe ich den Wald vor lauter Bäumen nicht mehr gesehen 😕 Auf jeden Fall danke für deine Antwort.


Anmelden zum Antworten