Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Skin Framework
  New Posts New Posts RSS Feed - Crash inside OnEndHook
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Crash inside OnEndHook

 Post Reply Post Reply
Author
Message
JohnCrenshaw View Drop Down
Groupie
Groupie
Avatar

Joined: 08 September 2006
Status: Offline
Points: 65
Post Options Post Options   Thanks (0) Thanks(0)   Quote JohnCrenshaw Quote  Post ReplyReply Direct Link To This Post Topic: Crash inside OnEndHook
    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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 01 February 2007 at 1:31am
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
Back to Top
JohnCrenshaw View Drop Down
Groupie
Groupie
Avatar

Joined: 08 September 2006
Status: Offline
Points: 65
Post Options Post Options   Thanks (0) Thanks(0)   Quote JohnCrenshaw Quote  Post ReplyReply Direct Link To This Post Posted: 01 February 2007 at 10:14am
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.
Back to Top
JohnCrenshaw View Drop Down
Groupie
Groupie
Avatar

Joined: 08 September 2006
Status: Offline
Points: 65
Post Options Post Options   Thanks (0) Thanks(0)   Quote JohnCrenshaw Quote  Post ReplyReply Direct Link To This Post Posted: 01 February 2007 at 10:17am
OK, wierd, it just crashed in both threads. The second thread was inside the skin framework even though it shouldn't be skinned.
Back to Top
JohnCrenshaw View Drop Down
Groupie
Groupie
Avatar

Joined: 08 September 2006
Status: Offline
Points: 65
Post Options Post Options   Thanks (0) Thanks(0)   Quote JohnCrenshaw Quote  Post ReplyReply Direct Link To This Post Posted: 01 February 2007 at 11:50am
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.

Back to Top
SUNGGI View Drop Down
Newbie
Newbie


Joined: 03 February 2006
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote SUNGGI Quote  Post ReplyReply Direct Link To This Post Posted: 21 February 2007 at 12:21am
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;
}
 
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.187 seconds.