Author Topic: Freeze() Thaw() errors  (Read 6334 times)

grv575

  • Guest
Freeze() Thaw() errors
« on: September 05, 2005, 06:13:39 am »
I compiled wxwidgets 2.6.1 nonunicode debug
It gives me a call to Thaw() without prior Freeze().

And:
wxSmith/.../propgrid.cpp:9793
Code
            //
            // Only create editor for non-disabled non-caption
            if ( p->GetParentingType() <= 0 && !(p->m_flags & wxPG_PROP_DISABLED) )
            {
            // do this for non-caption items
...
                    m_wndPrimary->Freeze();
...
            }
            else
            {
                // wxGTK atleast seems to need this (wxMSW not)
                SetFocus();
            }
...
            m_wndPrimary->Thaw();

So the Freeze() is guarded by an the if ( p->...) statement which does not guard the Thaw().  So for some values in that if statement, a Thaw() can occur without prior Freeze()

there's also bad freeze/thaw guarding starting @ line13842 of the same file:
Code
starting here...:
    unsigned char orig_frozen = 1;

*****
This one is glaring and not in one of the plugins (I've not compiled wxSmith so that wasn't what threw the debug messagebox which wx gave):

src\sdk\cbproject.cpp:483
Code
                Manager::Get()->GetAppWindow()->Thaw();

There is NO Freeze() located in that file...

*****

I also don't understand this choice:
Code
wxPropertyGrid::Freeze()
{
    m_frozen = 1;                                     // marked frozen
    wxScrolledWindow::Freeze();                // frozen
...

wxPropertyGrid::Thaw()
{
    m_frozen = 0;                                   // marked unfrozen
    wxScrolledWindow::Thaw();               // unfrozen

it's marked unfrozen before it actually is...shouldn't those two lines in the Thaw() function be reversed? (so that it unfreezes, then marks the control as in an unfrozen state....?)

Other Freeze()/Thaw() calls look good.

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Freeze() Thaw() errors
« Reply #1 on: September 05, 2005, 07:07:15 am »
the marking has practically no harmful effect before the actual freezes, because it's a memory modification. No function calls, and no events triggered. Anyway I think that Freeze() or Thaw() is atomic, so no harmful effects either.

Also, you might want to ask the people who actually wrote wxPropertyGrid - it's a third-party class, byo just used it for his property editor.

grv575

  • Guest
Re: Freeze() Thaw() errors
« Reply #2 on: September 05, 2005, 07:14:32 am »
OK, but the cbproject.cpp:483 thaw() is troublesome.

I found the cause of the assertion failures using gdb.
sdk\projectmanager.cpp:227
in
Code
void ProjectManager::BuildTree(wxWindow* parent)
uses
Code
UnfreezeTree(true);

which _forces_ a thaw without ever freezing anything.

gdb backtrace:
Code
Continuing.
gdb: child_resume.SetThreadContext: thread 9912.0x24e0
ContinueDebugEvent (cpid=9912, ctid=9440, DBG_CONTINUE);
gdb: kernel event for pid=9912 tid=9440 code=OUTPUT_DEBUG_STRING_EVENT)
warning: 00:47:06: ../../src/msw/window.cpp(1337): assert "m_frozenness > 0" failed: Thaw() without matching Freeze()

...

Program received signal SIGTRAP, Trace/breakpoint trap.
0x7c901231 in ntdll!DbgUiConnectToDbg () from ntdll.dll
(gdb) bt
#0  0x7c901231 in ntdll!DbgUiConnectToDbg () from ntdll.dll
#1  0x10002479 in wxTrap () at ../../src/common/appbase.cpp:593
#2  0x1000289d in DoShowAssertDialog (msg=@0x22f380)
    at ../../src/common/appbase.cpp:692
#3  0x100023fd in wxAppTraitsBase::ShowAssertDialog (this=0x1ba2b90,
    msg=@0x22f380) at ../../src/common/appbase.cpp:550
#4  0x101714a8 in wxGUIAppTraitsBase::ShowAssertDialog (this=0x1ba2b90,
    msg=@0x22f380) at ../../src/common/appcmn.cpp:530
#5  0x10002a7c in ShowAssertDialog (
    szFile=0x1048a756 "../../src/msw/window.cpp", nLine=1337,
    szCond=0x1048a975 "m_frozenness > 0",
    szMsg=0x1048a954 "Thaw() without matching Freeze()", traits=0x1ba2b90)
    at ../../src/common/appbase.cpp:846
#6  0x100021dd in wxAppConsole::OnAssert (this=0x558f908,
    file=0x1048a756 "../../src/msw/window.cpp", line=1337,
    cond=0x1048a975 "m_frozenness > 0",
    msg=0x1048a954 "Thaw() without matching Freeze()")
    at ../../src/common/appbase.cpp:461
#7  0x10002533 in wxOnAssert (szFile=0x1048a756 "../../src/msw/window.cpp",
    nLine=1337, szCond=0x1048a975 "m_frozenness > 0",
    szMsg=0x1048a954 "Thaw() without matching Freeze()")
    at ../../src/common/appbase.cpp:649
#8  0x100024a8 in wxAssert (cond=0,
---Type <return> to continue, or q <return> to quit---
    szFile=0x1048a756 "../../src/msw/window.cpp", nLine=1337,
    szCond=0x1048a975 "m_frozenness > 0",
    szMsg=0x1048a954 "Thaw() without matching Freeze()")
    at ../../src/common/appbase.cpp:616
#9  0x10100dae in wxWindow::Thaw (this=0x56cceb8)
    at ../../src/msw/window.cpp:1337
#10 0x6055ffe9 in ProjectManager::UnfreezeTree (this=0x56cc9c0, force=true)
    at sdk/projectmanager.cpp:947
#11 0x60559be7 in ProjectManager::BuildTree (this=0x56cc9c0, parent=0x56ccbb0)
    at sdk/projectmanager.cpp:249
#12 0x605594b0 in ProjectManager::InitPane (this=0x56cc9c0)
    at sdk/projectmanager.cpp:222
#13 0x60558f73 in ProjectManager::ProjectManager (this=0x56cc9c0,
    parent=0x570ea68) at sdk/projectmanager.cpp:195
#14 0x605586e8 in ProjectManager::Get (parent=0x570ea68)
    at sdk/projectmanager.cpp:61
#15 0x6052bec2 in Manager::GetProjectManager (this=0x44effe8)
    at sdk/manager.cpp:289
#16 0x00416096 in MainFrame::CreateMenubar (this=0x44cfcc0) at src/main.cpp:544
#17 0x00415707 in MainFrame::CreateIDE (this=0x44cfcc0) at src/main.cpp:468
#18 0x0041325b in MainFrame::MainFrame (this=0x44cfcc0, lang=@0x558f95c,
    parent=0x0) at src/main.cpp:372
#19 0x004024a7 in CodeBlocksApp::InitFrame (this=0x558f908) at src/app.cpp:176
---Type <return> to continue, or q <return> to quit---
#20 0x0040346c in CodeBlocksApp::OnInit (this=0x558f908) at src/app.cpp:301
#21 0x004ad934 in wxAppConsole::CallOnInit (this=0x558f908)
    at C:/Devel/wxWidgets-2.6.1/include/wx/app.h:87
#22 0x1003d7ab in wxEntryReal (argc=@0x22fe8c, argv=0x1b9efd8)
    at ../../src/common/init.cpp:401
#23 0x100aa9f8 in wxEntry (argc=@0x22fe8c, argv=0x1b9efd8)
    at ../../src/msw/main.cpp:247
#24 0x100aabbc in wxEntry (hInstance=0x400000, nCmdShow=10)
    at ../../src/msw/main.cpp:299
#25 0x0040131a in WinMain (hInstance=0x400000, hPrevInstance=0x0,
    lpCmdLine=0x251f07 "", nCmdShow=10) at src/app.cpp:297
#26 0x004aa12a in main () at C:/Devel/wxWidgets-2.6.1/include/wx/gdicmn.h:389

Note as well at line 951:
in
Code
void ProjectManager::RebuildTree()
{
    FreezeTree();
...
            project->BuildTree(m_pTree, m_TreeRoot, m_TreeCategorize, m_TreeUseFolders, m_pFileGroups);      /// THIS UNFREEZES THE TREE!!!
...
       UnfreezeTree();
}
So that BuildTree() call interspersed will unfreeze the tree (m_pTree) frozen by the FreezeTree() so that UnfreezeTree() gives another gdb stacktrace like the one above (same assertion failure).  (BuildTree contains that UnfreezeTree(true) call above...).
This should probably be sorted out...
« Last Edit: September 05, 2005, 07:32:56 am by grv575 »

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Freeze() Thaw() errors
« Reply #3 on: September 05, 2005, 07:46:03 am »
Well, I really don't know why that unfreezetree(true) is there...  there isn't any mysterious / magical purpose for doing things not as they should be done... (translation: it's probably a mistake! :P )

So, if you can post the fixes for that code, we're all ears! :)

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Freeze() Thaw() errors
« Reply #4 on: September 05, 2005, 08:54:14 am »
Don't mess with Thaw()'s !

I discovered the hard way that Freeze()/Thaw() behaves differently in wx 2.4 and 2.6. The way it is setup now works fine.
If you remove that stray Thaw(), you 'll have the desktop corruption bug.
Besides, Thaw() is harmless. A stray Freeze() should worry you...
Be patient!
This bug will be fixed soon...