Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - GdiPlus Registering Race Condition
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

GdiPlus Registering Race Condition

 Post Reply Post Reply
Author
Message
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1059
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post Topic: GdiPlus Registering Race Condition
    Posted: 03 September 2018 at 6:07am
Hello,

when creating two different CXTPMarkupContexts both call in their constructor the function CXTPMarkupDrawingContext::Register(TRUE). As this leads to a registering of the CXTPSingleton CXTPGdiPlus 2x sometimes an assertion will be caused, when we got a bad timing.

Can anyone please help me solve this issue by fixing the race condition or telling me if I've used these classes in a wrong way and how to use them correctly?

Thanks for the help in advance.
Martin

Product: Xtreme Toolkit v 15.3.1, new Projects v 18.5.0
Platform: Windows 8.1 (64bit)
Language: VC+
Back to Top
agontarenko View Drop Down
Admin Group
Admin Group


Joined: 25 March 2016
Status: Offline
Points: 100
Post Options Post Options   Thanks (0) Thanks(0)   Quote agontarenko Quote  Post ReplyReply Direct Link To This Post Posted: 05 September 2018 at 3:56am
Hello Martin, how I can reproduce it with our samples?

Regards,
Artem Gontarenko
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1059
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post Posted: 05 September 2018 at 5:27am
Hello,

the easiest way would be to implement a sample that uses multithreading and do something like the following all the time until you get into the race condition:

  CSampleMarkupView* Wnd_ = new CSampleMarkupView(); //Calls CXTPMarkupDrawingContext::Register(TRUE) -> calls CXTPGdiPlus::Register(TRUE)
  // with ASSERT(m_nGdiplusToken == 0 && m_hModule == 0) (XTPGdiPlus.cpp Line 61)
 
  delete Wnd_; //Calls CXTPMarkupDrawingContext::Register(FALSE) -> calls CXTPGdiPlus::Register(FALSE)
  /*
    XTPGdiPlus.cpp Line 75ff:
      m_nCount--;

      if (m_nCount != 0)
      return;
      -----------------> if another thread that wants to call CXTPMarkupDrawingContext::Register(TRUE) interrupts our thread we got an assertion (ASSERT(m_nGdiplusToken == 0 && m_hModule == 0)) in XTPGdiPlus.cpp Line 61

      if (m_hModule)
      {
        // Termination of background thread, which is causing the shutdown problem.
        gdiplusStartupOutput.NotificationUnhook(m_nGdiplusToken);
        GdiplusShutdown(m_nGdiplusToken);
        FreeLibrary(m_hModule);
      }
      m_hModule = NULL;
      m_nGdiplusToken = 0;
   */


using:
class CSampleMarkupView : public CWnd, CXTPMarkupContext {
public:
  CSampleMarkupView() : CWnd(), CXTPMarkupContext() {}
  virtual ~CSampleMarkupView() {}
};

Best regards

Martin

Product: Xtreme Toolkit v 15.3.1, new Projects v 18.5.0
Platform: Windows 8.1 (64bit)
Language: VC+
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1059
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post Posted: 05 September 2018 at 6:34am
Fixed it.
Thanks for the help! :)
Martin

Product: Xtreme Toolkit v 15.3.1, new Projects v 18.5.0
Platform: Windows 8.1 (64bit)
Language: VC+
Back to Top
Marco1 View Drop Down
Senior Member
Senior Member


Joined: 16 January 2004
Location: Germany
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote Marco1 Quote  Post ReplyReply Direct Link To This Post Posted: 10 September 2018 at 1:21pm
Was this problem related to your program?
Product: XTP 18.3.0 on VS 2017
Platform: VS 2017 / Windows 10 (64bit)
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1059
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post Posted: 10 September 2018 at 1:23pm
Yes!

It's been my fault...
Martin

Product: Xtreme Toolkit v 15.3.1, new Projects v 18.5.0
Platform: Windows 8.1 (64bit)
Language: VC+
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0.078 seconds.