Print Page | Close Window

Crash inside OnEndHook

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Skin Framework
Forum Description: Topics Related to Codejock Skin Framework
URL: http://forum.codejock.com/forum_posts.asp?TID=6291
Printed Date: 22 November 2024 at 1:23am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Crash inside OnEndHook
Posted By: JohnCrenshaw
Subject: Crash inside OnEndHook
Date 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



Replies:
Posted By: Oleg
Date 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


Posted By: JohnCrenshaw
Date 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.


Posted By: JohnCrenshaw
Date 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.


Posted By: JohnCrenshaw
Date 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.



Posted By: SUNGGI
Date 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;
}
 



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net