Crash inside OnEndHook |
Post Reply |
Author | |
JohnCrenshaw
Groupie Joined: 08 September 2006 Status: Offline Points: 65 |
Post Options
Thanks(0)
Posted: 31 January 2007 at 7:00pm |
Inside of the toolkit are the two following functions, which have abbreviated here to highlight the problem:
void CXTPSkinObject::OnBeginHook(...){ InternalAddRef(); ...
m_arrDescriptors.AddHead(...);
} void CXTPSkinObject::OnEndHook(){ m_arrDescriptors.RemoveHead(); InternalRelease(); } In several places inside the toolkit, constructions like the following are used:
pSkinObject->OnBeginHook(...);
BOOL bResult = pSkinObject->OnHookDefWindowProc(...);
pSkinObject->OnEndHook();
The basic idea of this is that something is added to a stack, the message is processed, and that something is then removed from the stack. It should, in theory, be impossible to reach a state where OnEndHook is called, and there is nothing in the stack, however, I am getting into such a state.
I have a background worker thread that watches the mouse, and moves windows around based on what the mouse does. This gives us capture level control without having to capture the mouse. I suspect that when this second thread moves things around, and messages are therefore processed, it creates a situation where this problem can happen. I was wondering if anyone is familiar with the issue and knows what to do about it.
Also, probably related, is a painting problem that pops up randomly when these windows are being moved by the second thread. Newly revealed portions of the window do not always paint, this seems to only be an issue when the windows are skinned.
I AM running 10.4.2
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hello,
yes, we agree that multithreading still have problems. :( try to add
XTPSkinManager()->SetAutoApplyNewThreads(FALSE) to remove sknning of second thread.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
JohnCrenshaw
Groupie Joined: 08 September 2006 Status: Offline Points: 65 |
Post Options
Thanks(0)
|
I already called SetAutoApplyNewThreads(false) before begging for help. Somehow, just the fact that the second thread exists is a problem without it having to be skinned.
For what it is worth, the crash happens far more readily if I use a call to SetWindowPos rather than a MoveWindow/ShowWindow combo.
|
|
JohnCrenshaw
Groupie Joined: 08 September 2006 Status: Offline Points: 65 |
Post Options
Thanks(0)
|
OK, wierd, it just crashed in both threads. The second thread was inside the skin framework even though it shouldn't be skinned.
|
|
JohnCrenshaw
Groupie Joined: 08 September 2006 Status: Offline Points: 65 |
Post Options
Thanks(0)
|
I did the following and it fixed this:
BOOL CAppBarMngr::InitInstance(){ // unhook the window from the skin XTPSkinManager()->Remove(m_pMainWnd->m_hWnd); return TRUE;} It would still be best if the multithread issues could be fixed. It looks to me like a mutex around the m_arrDescriptors.AddHead(des); and m_arrDescriptors.RemoveHead(); functions would probably do it. |
|
SUNGGI
Newbie Joined: 03 February 2006 Status: Offline Points: 2 |
Post Options
Thanks(0)
|
Hello,
Use CriticalSection like this :
Add CriticalSection in CXTPSkinObject Class
static CCriticalSection CS_Skin;
//////////////////////////////////////////////////////////
XTPSkinObject.cpp
//////////////////////////////////////////////////////////
CCriticalSection CXTPSkinObject::CS_Skin;
void CXTPSkinObject::OnBeginHook(UINT nMessage, XTPSkinDefaultProc defProc, PROC defProcAddr, LPVOID defProcPrevWndFunc) { CS_Skin.Lock(); InternalAddRef(); DEFWINDOW_DESCRIPTIOR des;
des.defProc = defProc;
des.nMessage = nMessage; des.defProcAddr = defProcAddr; des.lpPrev = defProcPrevWndFunc; m_arrDescriptors.AddHead(des);
CS_Skin.Unlock(); } void CXTPSkinObject::OnEndHook() { CS_Skin.Lock(); m_arrDescriptors.RemoveHead(); InternalRelease(); CS_Skin.Unlock(); } ////////////////////////////////////////////////////////////////
XTPSkinManagerApiHook.cpp
////////////////////////////////////////////////////////////////
BOOL CXTPSkinManagerApiHook::CallHookDefWindowProc(HWND hWnd, PROC pfnOrig, XTPSkinDefaultProc defProc, LPVOID lpPrev, UINT nMessage, WPARAM& wParam, LPARAM& lParam, LRESULT& lResult) { if (!XTPSkinManager()->IsEnabled()) return FALSE; CXTPSkinObject* pSkinObject = XTPSkinManager()->Lookup(hWnd);
if (!pSkinObject || pSkinObject->m_bCustomDraw)
return FALSE; CXTPSkinObject::CS_Skin.Lock();
if (!pSkinObject->m_arrDescriptors.IsEmpty()) { if (nMessage == pSkinObject->m_arrDescriptors.GetHead().nMessage) { CXTPSkinObject::CS_Skin.Unlock(); return FALSE; } } CXTPSkinObject::CS_Skin.Unlock(); if (defProc == xtpSkinDefaultCallWindowProc && pSkinObject->IsDefWindowProcAvail(nMessage))
{ BOOL bAvail = FALSE; WNDPROC lpWndProc = (WNDPROC)lpPrev; if (IsSystemWindowModule(lpWndProc, &bAvail) || !bAvail)
{ lpWndProc = 0; } if (lpWndProc != 0 && (!XTPSkinManager()->IsWin9x() ||
((DWORD_PTR)lpWndProc < (DWORD_PTR)0x70000000))) { return FALSE; } } MSG& curMsg = AfxGetThreadState()->m_lastSentMsg;
MSG oldMsg = curMsg; curMsg.hwnd = hWnd; curMsg.message = nMessage; curMsg.wParam = wParam; curMsg.lParam = lParam; pSkinObject->OnBeginHook(nMessage, defProc, pfnOrig, lpPrev);
BOOL bResult = pSkinObject->OnHookDefWindowProc(nMessage, wParam ,lParam, lResult);
pSkinObject->OnEndHook();
curMsg = oldMsg;
if (bResult)
return TRUE; return FALSE;
} |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |