Author Topic: crash: codeblocks wx2.6.1 unicode  (Read 15270 times)

Offline grv575

  • Official tester
  • Regular
  • ***
  • Posts: 381
crash: codeblocks wx2.6.1 unicode
« on: August 23, 2005, 07:05:41 pm »
Crash on exiting codeblocks.  rpt file attached.  Crashes in processing wx event to resize the splitter.  If I comment out
sdk\xtra_classes.cpp:
Code
void wxSplitPanel::RefreshSplitter(int idtop,int idbottom,int sashPosition)
{
/*
    wxWindow *topwin = m_splitter->FindWindowById(idtop);
    wxWindow *bottomwin = m_splitter->FindWindowById(idbottom);
    int oldsash = m_splitter->GetSashPosition();
    m_splitter->Freeze();
    if(topwin && topwin->IsShown() && bottomwin && bottomwin->IsShown())
    {
        m_splitter->SplitHorizontally(topwin,bottomwin);
    }
    else
    {
        wxWindow* thewin = 0;
        if (topwin && topwin->IsShown())
            thewin = topwin;
        else if (bottomwin && bottomwin->IsShown())
            thewin = bottomwin;
        m_splitter->Initialize(thewin);
    }
    if (sashPosition)
    {
        m_splitter->SetSashPosition(sashPosition);
    }
    else
    {
        if (!m_SplitterConfig.IsEmpty())
            m_splitter->SetSashPosition(ConfigManager::Get()->Read(m_SplitterConfig, (long int)150));
        else
            m_splitter->SetSashPosition(oldsash);
    }
    m_splitter->Thaw();
    *////
}

then no crash on exit.  The splitter of course doesn't refresh, but hopefully this isolates it somewhat.  Thinking that a refresh event gets queued and then the application thread exits, while wx dll tries to process event on nonexistant splitter.  Maybe debug code can be added to that method above to check for nulls.


[attachment deleted by admin]

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: crash: codeblocks wx2.6.1 unicode
« Reply #1 on: August 23, 2005, 07:18:00 pm »
Hmmmm makes me wonder.

Try enabling the new "crash protection" option on environment settings.

Offline grv575

  • Official tester
  • Regular
  • ***
  • Posts: 381
Re: crash: codeblocks wx2.6.1 unicode
« Reply #2 on: August 23, 2005, 07:19:13 pm »
OK, something wrong with the logic involving topwin and bottomwin.  Maybe a conditional breakpoint on m_splitter->Initialize(thewin); when topwin==0 or bottomwin==0.  Not positive.  The following works without crashing though (might not be correct desired code however).  Changes marked ///:

Code
void wxSplitPanel::RefreshSplitter(int idtop,int idbottom,int sashPosition)
{
    wxWindow *topwin = m_splitter->FindWindowById(idtop);
    wxWindow *bottomwin = m_splitter->FindWindowById(idbottom);
   
    if (!topwin || !bottomwin)///
        return;///
   
    int oldsash = m_splitter->GetSashPosition();
    m_splitter->Freeze();
    if(topwin && topwin->IsShown() && bottomwin && bottomwin->IsShown())
    {
        m_splitter->SplitHorizontally(topwin,bottomwin);
    }
    else
    {
        wxWindow* thewin = 0;
        if (topwin && topwin->IsShown())
            thewin = topwin;
        else if (bottomwin && bottomwin->IsShown())
            thewin = bottomwin;
        m_splitter->Initialize(thewin);
    }
    if (sashPosition)
    {
        m_splitter->SetSashPosition(sashPosition);
    }
    else
    {
        if (!m_SplitterConfig.IsEmpty())
            m_splitter->SetSashPosition(ConfigManager::Get()->Read(m_SplitterConfig, (long int)150));
        else
            m_splitter->SetSashPosition(oldsash);
    }
    m_splitter->Thaw();
}

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: crash: codeblocks wx2.6.1 unicode
« Reply #3 on: August 23, 2005, 07:21:41 pm »
I think that should be

Code
if(!topwin && !bottomwin) return;

Anyway did you check out my post regarding the "crash protection" option?

Offline grv575

  • Official tester
  • Regular
  • ***
  • Posts: 381
Re: crash: codeblocks wx2.6.1 unicode
« Reply #4 on: August 23, 2005, 07:30:21 pm »
What does crash protection do?  Didn't prevent a crash btw.  Same rpt backtrace as well.

yeah !topwin && !bottomwin looks right.  problem is that having either of those lines (|| or &&) prevents it from crashing if the splitter is on
the Projects tab, but if the splitter is on the Watches tab, I still get the crash.

edit: actually it can still crash even with the !top/bottomwindow stuff.  looks event related.  but definately no crashes if I comment out the contents of RefreshSplitter.
« Last Edit: August 23, 2005, 07:48:22 pm by grv575 »

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: crash: codeblocks wx2.6.1 unicode
« Reply #5 on: August 23, 2005, 07:57:20 pm »
The "crash protection" avoids crashes by avoiding objects from being deleted twice. how does it work? Simple, it skips the wxYield() in message manager :lol:.
It happened to me that I would get crashes in an event handler, but that event happened to be triggered BEFORE exiting C::B. Other events deleted the object in the middle of the call, and it would wreak havoc. It costed me many hours to figure out what was going on...

That was the reason to add the switch. Crashes due to mishandled events shouldn't concern us, since they could be fixed by enabling the option (yes, the UI becomes a bit staggering but that's a separate problem). If you get a crash with the "crash protection" enabled, it means the problem is not in the events, but something else.

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: crash: codeblocks wx2.6.1 unicode
« Reply #6 on: August 23, 2005, 08:06:21 pm »
yeah !topwin && !bottomwin looks right.  problem is that having either of those lines (|| or &&) prevents it from crashing if the splitter is on
the Projects tab, but if the splitter is on the Watches tab, I still get the crash.

That's because the crash is in wxSplitterWindow, _NOT_ SplitPanel. They're different classes, and the watches tab doesn't use splitpanel.

Mind explaining further (a screenshot before exiting perhaps) how to reproduce the bug? I also need a stack trace with the crash protection enabled. Those stacked idle events in the original report don't look good at all...
« Last Edit: August 23, 2005, 08:08:30 pm by rickg22 »

Offline grv575

  • Official tester
  • Regular
  • ***
  • Posts: 381
Re: crash: codeblocks wx2.6.1 unicode
« Reply #7 on: August 24, 2005, 02:32:08 am »
Screen right before file->close then crash after 1-2 seconds.  Enable crash protection, exit, reload, exit - that's what's in this .rpt log.

Btw, same exact behavior with all plugins disabled & code completion disabled.

[attachment deleted by admin]

Offline grv575

  • Official tester
  • Regular
  • ***
  • Posts: 381
Re: crash: codeblocks wx2.6.1 unicode
« Reply #8 on: August 24, 2005, 04:10:46 am »
Isolated it to this line:

sdk\xtra_classes.cpp:56

            m_splitter->SetSashPosition(ConfigManager::Get()->Read(m_SplitterConfig, (long int)150));

With that commented out, it does not crash at all.
Maybe m_SplitterConfig is no longer valid and it's reading from memory no longer in the address space.

Edit: breakpoint on line 56 right before the crash.  GDB backtrace attached.

[attachment deleted by admin]
« Last Edit: August 24, 2005, 04:30:18 am by grv575 »

Offline grv575

  • Official tester
  • Regular
  • ***
  • Posts: 381
Re: crash: codeblocks wx2.6.1 unicode
« Reply #9 on: August 24, 2005, 05:23:07 am »
More info:

1 - the crash happens before the destructor - wxSplitPanel::~wxSplitPanel() is called
this (original code) crashes:
            m_splitter->SetSashPosition(ConfigManager::Get()->Read(m_SplitterConfig, (long int)150));
this does not:
            ConfigManager::Get()->Read(m_SplitterConfig, (long int)150);
this does:
            if (m_splitter)
                            m_splitter->SetSashPosition((long int)307); // hard code value

so it can read the config registry key fine (editor/opened_files_tree_height = 307), but setting the sashposition crashes (even though the wxSplitter is not null).

Code
wxSplitterWindow::SetSashPosition

void SetSashPosition(int position, const bool redraw = TRUE)

Sets the sash position.

Parameters

position

            The sash position in pixels.

redraw

            If TRUE, resizes the panes and redraws the sash and border.

Remarks

Does not currently check for an out-of-range value.

still debugging, but I don't see why it sets the sash position on openfiletree() refresh from the registry on _every_ refresh?
shouldn't this be changed when it is created (splithorizontally(width, height, sashposfromregistry))?

« Last Edit: August 24, 2005, 05:49:48 am by grv575 »

Offline grv575

  • Official tester
  • Regular
  • ***
  • Posts: 381
Re: crash: codeblocks wx2.6.1 unicode
« Reply #10 on: August 24, 2005, 05:44:25 am »
See if this is correct code (attached).  Works for me without crashes.  Someone on the wxWidgets mailing list hinted at the new wxSplitter being buggy and to set the sash pos in the splithorizontally() function:

bool SplitHorizontally(wxWindow* window1, wxWindow* window2, int sashPosition = 0)

http://lists.wxwidgets.org/archive/wxPython-users/msg04394.html

Have not tested on linux yet.

Btw: with current version of the code, you can try to hardcode it as  m_splitter->SetSashPosition((long int)307);
and then play with resizing the window and moving the Projects tab horizontal seperator.  It crashes sometimes, not others (depends if resized sashpos > registry value or current sash pos or something once exiting).  Looks like it has something to do with this comment in the docs:

wxSplitterWindow::SetSashPosition
...
Remarks

Does not currently check for an out-of-range value.

But I have no idea what that means.
 :?

[attachment deleted by admin]
« Last Edit: August 24, 2005, 06:02:20 am by grv575 »

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: crash: codeblocks wx2.6.1 unicode
« Reply #11 on: August 24, 2005, 08:11:12 pm »
No wonder the bug didn't happen in 2.4.2...  please send me a personal message about it, since there's no way (AFAIK) to mark threads as important. I forget things often :(


Offline David Perfors

  • Developer
  • Lives here!
  • *****
  • Posts: 560
Re: crash: codeblocks wx2.6.1 unicode
« Reply #12 on: August 24, 2005, 11:11:36 pm »
I forget things often :(
I think that has something todo with you're age :P
OS: winXP
Compiler: mingw
IDE: Code::Blocks SVN WX: 2.8.4 Wish list: faster code completion, easier debugging, refactoring

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: crash: codeblocks wx2.6.1 unicode
« Reply #13 on: August 25, 2005, 12:47:47 am »
I forget things often :(
I think that has something todo with you're age :P
:shock:

Offline grv575

  • Official tester
  • Regular
  • ***
  • Posts: 381
Re: crash: codeblocks wx2.6.1 unicode
« Reply #14 on: August 27, 2005, 08:42:18 pm »
OK CVS HEAD doesn't have this crash.  So might not be worth looking into at this point.  (CVS HEAD unicode built according to: http://forums.codeblocks.org/index.php/topic,811.0.html)