Author Topic: ThreadSearch-plugin causes a crash when right-clicking preview on Linux  (Read 4862 times)

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
This happens on 32-bit and 64-bit Linux (at least for me) when I right-click into the preview-window to open the context-menu.
The PreviewWindow is a cbStyledTextCtrl, but as first parameter it gets a wxPanel* not an EditorBase*, so every ContextMenuEvent is skipped, because the dynamic_cast in cbStyledTextCtrl's OnContextmenu will never be true.
I put a static int in cbStyledTextCtrl::OnContextMenu to count how often we come to it after pressing the right mouse button and send it's value to the Debug Log C::B crashes after about 22750 with a segmentation fault.
I think it's because of a buffer overflow in wxEvents Hashtable.
On Windows it works correctly.

Here is a patch that makes the plugin behave the same on Windows and Linux.

In both OSes the event is skipped exactly one time with this patch and the context-menu pops up.

Tested on Linux and W2K.
Code
--- codeblocks-1.0svn.orig/src/plugins/contrib/ThreadSearch/ThreadSearchView.h 2008-01-23 12:50:35.000000000 +0100
+++ codeblocks-1.0svn.work/src/plugins/contrib/ThreadSearch/ThreadSearchView.h       2008-02-02 11:10:59.000000000 +0100
@@ -228,7 +228,6 @@

        void OnMarginClick(wxScintillaEvent& event);
        void OnContextMenu(wxContextMenuEvent& event);
-       void OnMouseRightUp(wxMouseEvent& event);
     void OnLoggerClick      (const wxString& file, long line);  // Called by ThreadSearchLoggerBase derived instance^M
                                                                                                                                // when user clicks on a search result
     void OnLoggerDoubleClick(const wxString& file, long line);  // Called by ThreadSearchLoggerBase derived instance^M
--- codeblocks-1.0svn.orig/src/plugins/contrib/ThreadSearch/ThreadSearchView.cpp       2008-01-28 22:16:25.000000000 +0100
+++ codeblocks-1.0svn.work/src/plugins/contrib/ThreadSearch/ThreadSearchView.cpp     2008-02-02 11:11:37.000000000 +0100
@@ -81,10 +81,6 @@
                        (wxObjectEventFunction) (wxEventFunction) (wxContextMenuEventFunction)
                        &ThreadSearchView::OnContextMenu);

-       Connect(id, wxEVT_RIGHT_UP,
-                       (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction)
-                       &ThreadSearchView::OnMouseRightUp);
-
        Connect(idTxtSearchDirPath, wxEVT_COMMAND_TEXT_UPDATED,
                        (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
                        &ThreadSearchView::OnTxtSearchDirPathTextEvent);
@@ -113,10 +109,6 @@
                        (wxObjectEventFunction) (wxEventFunction) (wxContextMenuEventFunction)
                        &ThreadSearchView::OnContextMenu);

-       Disconnect(id, wxEVT_RIGHT_UP,
-                       (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction)
-                       &ThreadSearchView::OnMouseRightUp);
-
        Disconnect(idTxtSearchDirPath, wxEVT_COMMAND_TEXT_UPDATED,
                        (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
                        &ThreadSearchView::OnTxtSearchDirPathTextEvent);
@@ -520,17 +512,10 @@

 void ThreadSearchView::OnContextMenu(wxContextMenuEvent& event)
 {
-       // Default cbStyledTextCtrl contextual menu
-       m_pSearchPreview->ProcessEvent(event);
+    event.StopPropagation();
 }


-void ThreadSearchView::OnMouseRightUp(wxMouseEvent& event)
-{
-       // Default cbStyledTextCtrl contextual menu
-       m_pSearchPreview->ProcessEvent(event);
-}
-

 void ThreadSearchView::AddExpressionToSearchCombos(const wxString& expression)
 {

There are two dos/windows line-endings in the ThreadSearchView.h part, so it might not apply correctly when copied from here, but it's just one line two delete (in header).
« Last Edit: February 02, 2008, 01:00:15 pm by jens »

Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: ThreadSearch-plugin causes a crash when right-clicking preview on Linux
« Reply #1 on: February 02, 2008, 03:40:15 pm »
Thanks Jens, I'll look at it and apply today or tomorrow.

Dje

Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: ThreadSearch-plugin causes a crash when right-clicking preview on Linux
« Reply #2 on: February 03, 2008, 12:40:05 am »
Applied !
Thanks again Jens  :D !