CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2010
    Posts
    907

    std::vector with value feeefeee question

    Hello gurus,
    Somewhere in my application,
    there is a std::vector<IDirect3DTexture9*> mTex; COM object
    It is declared along with other elements in the same class
    When I run my program,
    mTex seems to turn into feeefeee so there is an assertion on me.
    I have searched thru my project. And found that no one has deleted the object
    Others objects have remained intact. Except mTex seems going out of scope (I guess).
    Tidy() was called
    Are there any good methods that I can pin down the cause of this variable gone out of scope?

    HEAP[MDI.exe]: Invalid address specified to RtlValidateHeap( 00330000, 05CAE590 )

    Any good ideas that I can fix this problem?
    Thanks a lot
    Jack

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: std::vector with value feeefeee question

    Quote Originally Posted by lucky6969b View Post
    Hello gurus,
    Somewhere in my application,
    there is a std::vector<IDirect3DTexture9*> mTex; COM object
    It is declared along with other elements in the same class
    When I run my program,
    mTex seems to turn into feeefeee so there is an assertion on me.
    I have searched thru my project. And found that no one has deleted the object
    How did you determine that no one deleted the object? If you're just looking at code to determine this, then that is not enough -- you need to run your program and monitor all memory allocations and deallocations to see what is happening.
    Others objects have remained intact. Except mTex seems going out of scope (I guess).
    So maybe the object that this member belongs to is invalid.
    Are there any good methods that I can pin down the cause of this variable gone out of scope?
    It is a member of a class, so put a breakpoint in the destructor of the class. When that breakpoint is hit, the object is being destroyed.
    Any good ideas that I can fix this problem?
    Debug the program, determine the cause, and fix the problem.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Dec 2010
    Posts
    907

    Re: std::vector with value feeefeee question

    Thanks Paul, I am checking the destructor now by setting breakpoints on it.
    Hope that the bug will surface soon
    Jack

  4. #4
    Join Date
    Dec 2010
    Posts
    907

    Re: std::vector with value feeefeee question

    The assertions were quite random
    Code:
    CMesh::CMesh()
    {
    	m_dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL | D3DFVF_TEX1;
    	m_method = D3DNONINDEXED;
    	m_dwCullMode = D3DCULL_CCW;
    
    	m_pmcSelectedMesh = NULL;
    	m_pframeSelected = NULL;
    	m_pdeHead = NULL;
    	m_pdeSelected = NULL;
    
    	m_pStaticMesh = NULL;
    	mMtrl.clear();
    	mTex.clear();    // feeefeee
    }
    
    CMesh::~CMesh()
    {
    }
    Code:
    t.LoadSkinMesh(m_pDevice, _T("\\data\\truck.dat"));
    	//LorryMesh[1].LoadSkinMesh(m_pDevice, _T("\\data\\truck.dat"));
    	//LorryMesh[2].LoadSkinMesh(m_pDevice, _T("\\data\\truck.dat"));
    	//LorryMesh[3].LoadSkinMesh(m_pDevice, _T("\\data\\truck.dat"));
    	LorryMesh.clear();
    	LorryMesh.push_back(t);
    	LorryMesh.push_back(t);
    	LorryMesh.push_back(t);
    	LorryMesh.push_back(t);
    
    
    	D3DXVECTOR3 pos;
    	LorryObj.clear();
    
    	for (int i = 0; i < NO_TRUCK; i++)
    	{
    		OBJECTINFO oi;
    		D3DXMATRIX matr[4];
    		D3DXMATRIX matt[4];
     		pos.x = m_TruckPos[i].mat._41;
    		pos.y = m_TruckPos[i].mat._43;
    		pos.z = m_TruckPos[i].mat._42+100.0f;
    
    		oi.vStartPos = pos;
    		oi.fSpeed = 20.0f;
    	    //m_LorryInfo[i].fSpeed = 20.0f;
    		m_LorryInfo.push_back(oi);
    
    		CTruck ct;
    		ct.Create (m_pDevice, &LorryMesh[i]);
    		ct.SetSize(0.1f);
    		ct.SetPos(m_LorryInfo[i].vStartPos);
    		ct.SetRot(D3DXVECTOR3(3.14,0,0)); // not in own axis
    		ct.SetRotationMatrix(m_TruckPos[i].mat);
    		LorryObj.push_back(ct);
    	
    	}
    After lorryobj received its second ct, it started to crash... very weird
    Thanks
    Jack

  5. #5
    Join Date
    Dec 2010
    Posts
    907

    Re: std::vector with value feeefeee question

    Some stack traces:
    Code:
     	ntdll.dll!7715fadc() 	
     	[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]	
     	ntdll.dll!7712272c() 	
     	ntdll.dll!770ee1ef() 	
     	ntdll.dll!77144f35() 	
     	KernelBase.dll!74ed468e() 	
     	msvcr90d.dll!_CrtIsValidHeapPointer(const void * pUserData=0x05b7e5b0)  Line 2103	C++
     	msvcr90d.dll!_free_dbg_nolock(void * pUserData=0x05b7e5b0, int nBlockUse=1)  Line 1317 + 0x9 bytes	C++
     	msvcr90d.dll!_free_dbg(void * pUserData=0x05b7e5b0, int nBlockUse=1)  Line 1258 + 0xd bytes	C++
     	mfc90d.dll!ATL::CCRTAllocator::Free(void * p=0x05b7e5b0)  Line 248 + 0xc bytes	C++
     	MDI.exe!std::allocator<IDirect3DTexture9 *>::deallocate(IDirect3DTexture9 * * _Ptr=0x05b7e5b0, unsigned int __formal=50)  Line 140 + 0x9 bytes	C++
     	MDI.exe!std::vector<IDirect3DTexture9 *,std::allocator<IDirect3DTexture9 *> >::_Tidy()  Line 1134	C++
     	MDI.exe!std::vector<IDirect3DTexture9 *,std::allocator<IDirect3DTexture9 *> >::~vector<IDirect3DTexture9 *,std::allocator<IDirect3DTexture9 *> >()  Line 560	C++
    >	MDI.exe!CMesh::~CMesh()  Line 172 + 0xe bytes	C++
     	MDI.exe!CObjects::~CObjects()  Line 44 + 0x44 bytes	C++
     	MDI.exe!CVehicle::~CVehicle()  Line 201 + 0x1d bytes	C++
     	MDI.exe!CTruck::~CTruck()  Line 209 + 0x1d bytes	C++
     	MDI.exe!Mythos::CRendererDX9::Create(HWND__ * const hWnd=0x00261c12, const unsigned long u32Flags=3, const unsigned long u32Width=1000, const unsigned long u32Height=1000)  Line 343 + 0xf bytes	C++
     	MDI.exe!CMDIApp::InitInstance()  Line 105 + 0x31 bytes	C++
     	mfc90d.dll!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x009661c1, int nCmdShow=1)  Line 37 + 0xd bytes	C++
     	MDI.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x009661c1, int nCmdShow=1)  Line 34	C++
     	MDI.exe!__tmainCRTStartup()  Line 578 + 0x35 bytes	C
     	MDI.exe!WinMainCRTStartup()  Line 403	C
     	kernel32.dll!754c3677() 	
     	ntdll.dll!770c9d72() 	
     	ntdll.dll!770c9d45() 	
     	MDI.exe!D3DX::jinit_c_main_controller()  + 0x19e bytes	C++
     	558bf875()

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: std::vector with value feeefeee question

    Quote Originally Posted by lucky6969b View Post
    After lorryobj received its second ct, it started to crash... very weird
    What is CTruck? What are the members of CTruck?

    An object to be placed in a vector must be safely copyable and assignable. If the CTruck class does not have proper or invalid copy-semantics, it cannot be placed in a vector (in addition to many other things).

    In other words:
    Code:
    void foo()
    {
       CTruck c1;
       // assume that c1 has data
       CTruck c2 = c1;
       CTruck c3;
       c3 = c1;
    }
    If this shows any side effects at runtime, CTruck is not eligible to be placed in a vector or any value-based container.

    Secondly, runtime issues cannot be solved by just looking at snippets of code. We have no idea when, where, or how any of this code is called, or know any of the types used (such as CTruck), or the values of these items.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: std::vector with value feeefeee question

    Quote Originally Posted by lucky6969b View Post
    Some stack traces:
    That won't do any good.

    More than likely, you are mismanaging pointers, dynamically allocated memory, or holding onto resources that are already disposed of but you have no indication that they have been disposed of.

    Regards,

    Paul McKenzie

  8. #8
    Join Date
    Dec 2010
    Posts
    907

    Re: std::vector with value feeefeee question

    I have noticed one thing. The std::vector object is disposed of by the CRT Free function.
    is it supposed to be like that?
    because I've googled and someone said if the allocator and deallocator are not of the same type. Such errors would occcur
    What is your opinion?
    Thanks
    Jack

  9. #9
    Join Date
    Apr 1999
    Posts
    27,449

    Re: std::vector with value feeefeee question

    Quote Originally Posted by lucky6969b View Post
    I have noticed one thing. The std::vector object is disposed of by the CRT Free function.
    is it supposed to be like that?
    When the vector goes out of scope, the vector is destroyed. If that vector was declared as a member of a class, and that object goes out of scope, then the vector is destroyed. That is how C++ works.
    Code:
    #include <vector>
    
    class foo
    {
       std::vector<int> iv;
    };
    
    int main()
    {
       foo f;
    }
    When main() exits, the f object goes out of scope, causing the iv vector to go out of scope, thus the destructor is called.
    because I've googled and someone said if the allocator and deallocator are not of the same type. Such errors would occcur
    What is your opinion?
    What you cannot do is pass vectors from one external module to another (for example, a DLL to an application) without many issues. Are you doing that? If not, then the allocator/deallocator theory isn't worth pursuing.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured