DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2004
    Posts
    20

    Unhappy transfer data from dialog to viewclass causes crash, need help!

    Hi there!

    I have MFC app (doc/view). In that app I have a dialog with a combobox from which I want to transfer a selected item back to the main View Class where I have a VTK(Visualization toolkit) window. basically Selecting an item in the combobox should affect the object that Im displaying in my main View

    when I execute my application and select the "Dialog" and select a string in the combobox it crashes and points at the member in the View class that I want to change.
    Below is the code where I change a variable in the View method SetScalars.

    I was wondering if it had to do with that my dialog is modal so that it cant overwrite my view class members , because that seems to be the problem.
    John, that line "alot of functions and members.... " are just VTK (vizualization toolkit) stuff.


    Code:
    void CStressesDialog::OnDropDownSelchange() 
    {
    	
    	int idx = m_DropDown.GetCurSel();
    	if( idx < 0 ) return;
    	CWnd* pParent = GetParent();
    	CVtkSDIView* pView =  (CVtkSDIView*)pParent;
    	pView = (CVtkSDIView*)pParent;
    	CString str;
    	m_DropDown.GetLBText( idx,str );
    	pView->SetScalars(str);
    	
    }

    This is what causes the crash somehow this->str_select = s; where str_select is an Cstring.

    Code:
    void CVtkSDIView::SetScalars(CString s)
    {
    this->str_select = s;
    
    //VTK STUFF IN THIS FUNCTION..
    
    this->filereader->SetScalarsName(str_select);	
    this->filereader->Update();
    this->lut->SetTableRange(this->filereader->GetOutput()->GetScalarRange());
    this->lut->Build();
    this->band->GenerateValues(15,this->filereader->GetOutput()->GetScalarRange());
    this->band->Update();
    this->pMapper->SetScalarRange(this->filereader->GetOutput()->GetScalarRange());
    this->pMapper->Update();
    this->renWin->Render();
    this->iren->Start();
    
    }


    Thanks for your help!

    /regards

    peter

  2. #2
    Join Date
    Dec 2003
    Posts
    3,366
    the debugger will also say why it crashed... can you post this? probably, its a pointer problem, which would read "the app tried to write memory 0x000000" or the like.

  3. #3
    Join Date
    Nov 2003
    Posts
    4,118
    is str_select in a valid state when you call the function? The crash you're witnessing may be caused by a previous bug that is deteted only when you try to assign that string. Also, notice that you're passing a string argument by value. This isn't necessarily a bug but it's uncommon and ineffcient. Instead, you should pass it by reference. Finally, is pParent a kosher pointer? Make sure that it has been allocated properly before you use.
    Danny Kalev

  4. #4
    Join Date
    Sep 2004
    Posts
    20

    Unhappy

    Hi there,

    Jonin I get the following debug message when it crashes:

    "Unhandled exception at 0x0041cdc0 in vtksdi.exe: 0xC0000005: Access violation reading location 0x00000001."



    Danny, what do you mean by a valid state? Its just declered as Cstring str_select in the header file. And then I use it in the setScalars method that I call from the dialog class. The Pparent pointer is also just declered and just like I showed in the previous message. I dont know what you mean by a kosher pointer, how should I allocate the pointer? BTW I changed the method so I now pass by reference instead of value.



    void CVtkSDIView::SetScalars(CString & s)
    {
    this->str_select = s;
    ....

    Regards

    Peter

  5. #5
    Join Date
    Nov 2003
    Posts
    4,118
    Declaring a pointer such as pParent isn\t enough. At some point you need to make it point to an object either by using operator new or assigning it manually. The error you're getting (Access Violation) is a strong hint that the pointer isn't kosher, e.g., it could be a danfling pointer, a NULL pointer, etc. Make sure that you allocated it before accessing it and that you didn't delete it by accident.

    In particular, check these lines:

    CWnd* pParent = GetParent();
    CVtkSDIView* pView = (CVtkSDIView*)pParent;

    pView = (CVtkSDIView*)pParent;

    Try to remove the explicit cast from each assignment expression e.g.,

    CVtkSDIView* pView = pParent;

    If it doesn't compile, then you probably are trying to do something illegal here. Also, check the value of pParent after the CWnd* pParent = GetParent();
    expression. Is the pointer NULL by chance? In short, check every assignment expression to a pointer to ensure that it succeeded before you move on.

    Last edited by Danny; 11-15-2004 at 05:14 AM.
    Danny Kalev

  6. #6
    Join Date
    Sep 2004
    Posts
    20

    Question

    Hi again,

    When I removed the type casting i got compilation error, that the parent wasn't a CvtkSDIView object. If I did an ASSERT test I got an assertion error on the following l
    ASSERT(pParent->IsKindOf(RUNTIME_CLASS(CVtkSDIView)));

    But when I used AfxGetMainWnd() it worked:
    Code:
    void CStresses2Dlg::OnDropDownSelchange() 
    {
    	
    	int idx = m_DropDown.GetCurSel();
    	if( idx < 0 ) return;
    	
    
    	CString str;
    	m_DropDown.GetLBText( idx,str );
    	CFrameWnd* wnd = (CFrameWnd*) AfxGetMainWnd();
    	if(wnd)
    	m_pView = (CVtkSDIView*) wnd->GetActiveView();
    	m_pView->SetScalars(str);
    	
    }
    It now interacts good and the different results are displayed correctly but when I exit the application I get the following error

    Unhandled exception at 0x77e1347b in vtksdi.exe: 0xC0000005: Access violation reading location 0x00000000.

    and the breakpoint points at a line in wincore.cpp
    where the it returns CallWindowProc

    Code:
    ////////////////////////////////////////////////////////////////////////////
    // Default CWnd implementation
    
    LRESULT CWnd::DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
    {
    	if (m_pfnSuper != NULL)
    		return ::CallWindowProc(m_pfnSuper, m_hWnd, nMsg, wParam, lParam);
    
    	WNDPROC pfnWndProc;
    	if ((pfnWndProc = *GetSuperWndProcAddr()) == NULL)
    		return ::DefWindowProc(m_hWnd, nMsg, wParam, lParam);
    	else
    	/*BREAKPOINT*/ return ::CallWindowProc(pfnWndProc, m_hWnd, nMsg, wParam, lParam);
    }

  7. #7
    Join Date
    Dec 2003
    Posts
    3,366
    most likely you free memory twice, possibly by manually freeing something that is also automatically freed. Not sure what from your snips.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links