afxwin2.inl line 265

Intrebari legate de programarea cu biblioteci precum MFC, ATL, WTL si GDI+.
mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

afxwin2.inl line 265

Post by mesajflaviu » 21 Feb 2014, 18:19

De cateva zile nu scap de o eroare (assertion). Am o aplicatie MDI, si dintr-un dialogbar, deschid cate un document ... daca ceva nu merge bine, aduc un dialog modal, care imi spune ce ii baiu ... dar, dupa acest dialog modal, am eroarea:

Code: Select all

Debug assertion failed !
File Afxwin2.inl, line 265
iar acolo am:

Code: Select all

_AFXWIN_INLINE CWnd* CWnd::GetParent() const
	{ ASSERT(::IsWindow(m_hWnd)); return CWnd::FromHandle(::GetParent(m_hWnd)); }
v-ati mai intalnit cu aceasta eroare ? Nu am putut afla nici macar sursa ei ... orice hint ar fi binevenit !



User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: afxwin2.inl line 265

Post by Ovidiu Cucu » 21 Feb 2014, 19:02

mesajflaviu wrote: v-ati mai intalnit cu aceasta eroare ?
Desigur... :)
Daca ASSERT(::IsWindow(m_hWnd)) da failure, spune ca handle-ul ferestrei (m_hWnd) nu este un handle la o fereastra valida.
In cazul tau inseamna ca apelezi GetParent fie inainte ca acea fereastra sa fie creata, fie dupa ce a fost distrusa.

E posibil sa fi facut ceva de genul:

Code: Select all

    CMyDialog dlg;
    dlg.DoModal();

    dlg.GetParent(); // Shows "Debug Assertion Failed!" message box.
Acel ASSERT te trage de maneca pentru ca la iesirea din DoModal, fereastra (dialogul) este distrus, deci nu mai ai ce parinte sa obtii dupa...
mesajflaviu wrote: Nu am putut afla nici macar sursa ei ... orice hint ar fi binevenit !
Hint: dupa ce apesi butonelul "Retry" ca sa vezi unde-i ASSERT-ul, da o fuga pe Call Stack si vezi de unde se-mpute treaba.

mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: afxwin2.inl line 265

Post by mesajflaviu » 28 Feb 2014, 11:12

Nu, nu mai folosesc obiectul dlg dupa apelul DoModal, iar call stack-ul ma duce la aceeasi linie:

Code: Select all

CWnd::GetParent() line 265 + 46 bytes
mai trebuie sa sap ...

Culmea e ca nu folosesc nicaieri GetParent().

mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: afxwin2.inl line 265

Post by mesajflaviu » 28 Feb 2014, 14:08

Cred ca am dat de o urma:
in program, folosesc un dialog modal, CMyMessageBox : public CDialog, pe post de message box :

Code: Select all

	CMyMessageBox MsgBox;
	MsgBox.SetMessage(sDocMessage);

.............
	UINT uRet = MsgBox.DoModal();
asa crapa, cu eroarea de mai sus ... insa, daca pun:

Code: Select all

	UINT uRet = AfxMessageBox(sDocMessage, MB_ICONERROR | MB_ABORTRETRYIGNORE, 0);
totul merge OK ... codul in CMyMessageBox este cam asa:

Code: Select all

void CMyMessageBox::OnCancel() 
{
	// TODO: Add extra cleanup here

	CDialog::OnCancel();
}

void CMyMessageBox::OnButtonNexti() 
{
	// TODO: Add your control notification handler code here

	EndDialog(IDRETRY);
}

void CMyMessageBox::OnButtonNextv() 
{
	// TODO: Add your control notification handler code here

	EndDialog(IDIGNORE);
}
ciudat ...

User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: afxwin2.inl line 265

Post by Ovidiu Cucu » 28 Feb 2014, 15:07

mesajflaviu wrote: Nu, nu mai folosesc obiectul dlg dupa apelul DoModal, iar call stack-ul ma duce la aceeasi linie:

Code: Select all

CWnd::GetParent() line 265 + 46 bytes
mai trebuie sa sap ...
Desigur. :) Da clice si pe alte linii din call stack, nu numai pe ultima, pentru ca de aia se numeste "call stack".
mesajflaviu wrote:Culmea e ca nu folosesc nicaieri GetParent().
Tu, direct, poate ca nu, insa poate chemi ceva care la randul lui cheama GetParent. Tot bietul call stack iti poate arata.
mesajflaviu wrote:Cred ca am dat de o urma:
in program, folosesc un dialog modal, CMyMessageBox : public CDialog, pe post de message box :

Code: Select all

	CMyMessageBox MsgBox;
	MsgBox.SetMessage(sDocMessage);

.............
	UINT uRet = MsgBox.DoModal();
[...]
OK, insa nu ne-ai aratat ce face acel SetMessage. Banui vrea sa seteze textul la vreun copilas si-atuncea crapa.
Crapa pentru ca, si inainte de DoModal, dialogul nu este inca creat.

mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: afxwin2.inl line 265

Post by mesajflaviu » 28 Feb 2014, 15:31

Am comentat tot ce tine de obiectul MsgBox, si am lasat urmatoarele linii:

Code: Select all

	CFBMessageBox MsgBox;
	UINT uRet = MsgBox.DoModal();
tot crapa in acelasi mod ...

mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: afxwin2.inl line 265

Post by mesajflaviu » 28 Feb 2014, 15:34

Ce mi se pare ciudat, e ca merge cu:

Code: Select all

//	UINT uRet = MsgBox.DoModal();
	UINT uRet = MessageBox(sDocMessage, NULL, MB_ICONERROR | MB_ABORTRETRYIGNORE);

User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: afxwin2.inl line 265

Post by Ovidiu Cucu » 28 Feb 2014, 16:45

mesajflaviu wrote:Ce mi se pare ciudat, e ca merge cu:

Code: Select all

//	UINT uRet = MsgBox.DoModal();
	UINT uRet = MessageBox(sDocMessage, NULL, MB_ICONERROR | MB_ABORTRETRYIGNORE);
Pai nu-i nimic ciudat pentru ca-s doua lucruri diferite.
Primul e un obiect dintr-o clasa derivata din CDialog, in care nici Mama Omida n-ar fi ghicit ce se intampla daca n-ar fi vazut codul.
Al doilea e un apel la functia CWnd::MessageBox, care la randul ei cheama ::MessageBox din WinAPI, ceea ce-i alta mancare de peste.
Fa te rog o poza la Call Stack si pune-o aici, poate ne prindem...

mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: afxwin2.inl line 265

Post by mesajflaviu » 28 Feb 2014, 16:59

Tot ce imi listeaza call stack-ul e aici (se opreste la prima linie):

Code: Select all

CWnd::GetParent() line 265 + 46 bytes
CWnd::FilterToolTipMessage(tagMSG * 0x00457f10 {msg=0x00000100 wp=0x0000001b lp=0x00010001}) line 489 + 11 bytes
CWnd::_FilterToolTipMessage(tagMSG * 0x00457f10 {msg=0x00000100 wp=0x0000001b lp=0x00010001}, CWnd * 0x001e41e8 {CFBDlgBar hWnd=???}) line 348
CWnd::PreTranslateMessage(tagMSG * 0x00457f10 {msg=0x00000100 wp=0x0000001b lp=0x00010001}) line 1027
CControlBar::PreTranslateMessage(tagMSG * 0x00457f10 {msg=0x00000100 wp=0x0000001b lp=0x00010001}) line 351 + 12 bytes
CFBDlgBar::PreTranslateMessage(tagMSG * 0x00457f10 {msg=0x00000100 wp=0x0000001b lp=0x00010001}) line 187
CWnd::WalkPreTranslateTree(HWND__ * 0x00030408, tagMSG * 0x00457f10 {msg=0x00000100 wp=0x0000001b lp=0x00010001}) line 2667 + 18 bytes
CWinThread::PreTranslateMessage(tagMSG * 0x00457f10 {msg=0x00000100 wp=0x0000001b lp=0x00010001}) line 672 + 18 bytes
CWinThread::PumpMessage() line 848 + 30 bytes
CWinThread::Run() line 487 + 11 bytes
CWinApp::Run() line 400
AfxWinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x002426d8, int 1) line 49 + 11 bytes
WinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x002426d8, int 1) line 30
WinMainCRTStartup() line 330 + 54 bytes
KERNEL32! 77101174()
NTDLL! 77b5b3f5()
NTDLL! 77b5b3c8()
iar sursa CDialog este simpla:

Code: Select all

class CFBMessageBox : public CDialog
{
// Construction
public:
	CMyMessageBox(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
	//{{AFX_DATA(CMyMessageBox)
	enum { IDD = IDD_FBMESSAGEBOX_DIALOG };
	CStatic	m_StaticError;
	//}}AFX_DATA

	void EnableButtonNextItem(BOOL bEnable){m_bEnableNext = bEnable;}
	void EnableButtonNextValid(BOOL bEnable){m_bEnableValid = bEnable;}
	void SetMessage(CString sMessage){m_sMessage = sMessage;}


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMyMessageBox)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

protected:
	CString m_sMessage;
	BOOL m_bEnableNext, m_bEnableValid;

// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(CMyMessageBox)
	virtual BOOL OnInitDialog();
	virtual void OnCancel();
	afx_msg void OnButtonNexti();
	afx_msg void OnButtonNextv();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};
iar cpp-ul:

Code: Select all

CFBMessageBox::CFBMessageBox(CWnd* pParent /*=NULL*/)
	: CDialog(CFBMessageBox::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFBMessageBox)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

	m_bEnableNext = m_bEnableValid = TRUE;
}


void CFBMessageBox::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFBMessageBox)
	DDX_Control(pDX, IDC_STATIC_ERROR, m_StaticError);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFBMessageBox, CDialog)
	//{{AFX_MSG_MAP(CFBMessageBox)
	ON_BN_CLICKED(IDC_BUTTON_NEXTI, OnButtonNexti)
	ON_BN_CLICKED(IDC_BUTTON_NEXTV, OnButtonNextv)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFBMessageBox message handlers

BOOL CFBMessageBox::OnInitDialog() 
{
	CDialog::OnInitDialog();

	GetDlgItem(IDC_BUTTON_NEXTI)->EnableWindow(m_bEnableNext);
	GetDlgItem(IDC_BUTTON_NEXTV)->EnableWindow(m_bEnableValid);
	GetDlgItem(IDC_STATIC_MESSAGE)->SetWindowText(m_sMessage);

	if(NULL == m_StaticError.GetIcon())
		m_StaticError.SetIcon(::LoadIcon(NULL, IDI_ERROR));

	if(m_bEnableNext)
	{
		HWND hWndCtrl = ::GetDlgItem(m_hWnd, IDC_BUTTON_NEXTI);
		PostMessage(WM_NEXTDLGCTL, (WPARAM)hWndCtrl, (LPARAM)TRUE);
	}

	// TODO: Add extra initialization here

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CFBMessageBox::OnCancel() 
{
	// TODO: Add extra cleanup here

	CDialog::OnCancel();
}

void CFBMessageBox::OnButtonNexti() 
{
	// TODO: Add your control notification handler code here

	EndDialog(IDRETRY);
}

void CFBMessageBox::OnButtonNextv() 
{
	// TODO: Add your control notification handler code here

	EndDialog(IDIGNORE);
}
as pune intreg proiectul atasat aici, dar e cam marisor ...

mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: afxwin2.inl line 265

Post by mesajflaviu » 28 Feb 2014, 17:03


User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: afxwin2.inl line 265

Post by Ovidiu Cucu » 28 Feb 2014, 19:01

In asta te-ai uitat?
CFBDlgBar::PreTranslateMessage

mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: afxwin2.inl line 265

Post by mesajflaviu » 03 Mar 2014, 11:19

In CFBDlgBar am doar:

Code: Select all

BOOL CFBDlgBar::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class

	m_ToolTip.RelayEvent(pMsg);
	return CDialogBar::PreTranslateMessage(pMsg);
}

mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: afxwin2.inl line 265

Post by mesajflaviu » 03 Mar 2014, 13:14

O sa incerc sa fac o aplicatie de test, care sa reproduca acest comportament ciudat ...

mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: afxwin2.inl line 265

Post by mesajflaviu » 05 Mar 2014, 11:50

Cred ca am gasit unde e problema ... revin.

mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: afxwin2.inl line 265

Post by mesajflaviu » 05 Mar 2014, 15:54

Pana la urma problema era tot intr-un PreTranslateMessage, doar ca intr-un control folosit in dialogbar ...

Post Reply