Author Topic: annoying crash when debugging CC's auto-suggestion  (Read 44622 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
annoying crash when debugging CC's auto-suggestion
« on: December 31, 2012, 10:21:54 am »
Debug C::B under C::B using gdb, then set a bp in the function: int CodeCompletion::CodeComplete() (around line 2061 of codecompletion.cpp), then run several steps (or step int some functions like MarkItemsByAI()), then continue running will cause the debugee C::B crash in the line
Code
 ed->GetControl()->AutoCompShow(pos - start, final);

I debugged some time, and find that the above line try to pop-up the autocompletion window. But when the debugee C::B stops at a bp which is before call the function AutoCompShow(), there will be a window switch. I mean, the debugee C::B will receive a KillFocus event.

What I see the crash backtrace is:
Code
[debug]#0  0x61a08afa in wxSCIListBoxWin::GetLB (this=0x0) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\PlatWX.cpp:1043
[debug]#1  0x619eb809 in GETLB (win=0x0) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\PlatWX.cpp:1218
[debug]#2  0x618e2f70 in ListBoxImpl::Length (this=0x3dbf1d8) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\PlatWX.cpp:1414
[debug]#3  0x6198e9e8 in AutoComplete::Select (this=0x1c20fb0, word=0x3ea8d84 "ac") at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\scintilla\src\AutoComplete.cxx:148
[debug]#4  0x61978e76 in ScintillaBase::AutoCompleteMoveToCurrentWord (this=0x1c205c0) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\scintilla\src\ScintillaBase.cxx:300
[debug]#5  0x61978d14 in ScintillaBase::AutoCompleteStart (this=0x1c205c0, lenEntered=2, list=0x3ddd290 "accB?1\naccess(): int __cdecl?13\naccumulate?40\nacos(): double __cdecl?13\nacosf(): float __cdecl?13\nacosh(): double __cdecl?13\nacoshf(): float __cdecl?13\nacoshl(): long double __cdecl?13\nacosl(): long d"...) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\scintilla\src\ScintillaBase.cxx:277
[debug]#6  0x6197a491 in ScintillaBase::WndProc (this=0x1c205c0, iMessage=2100, wParam=2, lParam=64869008) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\scintilla\src\ScintillaBase.cxx:666
[debug]#7  0x618def3f in ScintillaWX::WndProc (this=0x1c205c0, iMessage=2100, wParam=2, lParam=64869008) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\ScintillaWX.cpp:883
[debug]#8  0x618d02b9 in wxScintilla::SendMsg (this=0x3d9ef40, msg=2100, wp=2, lp=64869008) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\wxscintilla.cpp:270
[debug]#9  0x618d21e3 in wxScintilla::AutoCompShow (this=0x3d9ef40, lenEntered=2, itemList="accB?1\naccess(): int __cdecl?13\naccumulate?40\nacos(): double __cdecl?13\nacosf(): float __cdecl?13\nacosh(): double __cdecl?13\nacoshf(): float __cdecl?13\nacoshl(): long double __cdecl?13\nacosl(): long d"...) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\wxscintilla.cpp:1203
[debug]#10 0x65e8d7a7 in CodeCompletion::CodeComplete (this=0x39c6180) at E:\code\cb\cleantrunk\src\plugins\codecompletion\codecompletion.cpp:2240
[debug]#11 0x65e976b3 in CodeCompletion::DoCodeComplete (this=0x39c6180) at E:\code\cb\cleantrunk\src\plugins\codecompletion\codecompletion.cpp:4127
[debug]#12 0x65e910d5 in CodeCompletion::EditorEventHook (this=0x39c6180, editor=0x3c8f0a8, event=...) at E:\code\cb\cleantrunk\src\plugins\codecompletion\codecompletion.cpp:2947
[debug]#13 0x65f29c7d in EditorHooks::HookFunctor<CodeCompletion>::Call (this=0x3bf1540, editor=0x3c8f0a8, event=...) at E:\code\cb\cleantrunk\src\include\editor_hooks.h:49
[debug]#14 0x6189a021 in EditorHooks::CallHooks (editor=0x3c8f0a8, event=...) at E:\code\cb\cleantrunk\src\sdk\editor_hooks.cpp:69
[debug]#15 0x6183b03d in cbEditor::OnScintillaEvent (this=0x3c8f0a8, event=...) at E:\code\cb\cleantrunk\src\sdk\cbeditor.cpp:3280
[debug]#16 0x6183a335 in cbEditor::OnEditorCharAdded (this=0x3c8f0a8, event=...) at E:\code\cb\cleantrunk\src\sdk\cbeditor.cpp:3037
[debug]#17 0x00e7ff27 in wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () from E:\code\cb\cleantrunk\src\devel\wxmsw28u_gcc_custom.dll

It crash at the function:
Code
inline wxSCIListBoxWin* GETLBW(WindowID win) {
    return ((wxSCIListBoxWin*)win);
}

inline wxListView* GETLB(WindowID win) {
    return GETLBW(win)->GetLB();
}

.....
int ListBoxImpl::Length()
{
    return GETLB(wid)->GetItemCount();
}
But the "wid" is currently 0. I found the reason is, when a KillFocus is received, it will finally let the auto-completion canceled. So

Code
void Window::Destroy()
{
    if (wid) {
        Show(false);
        GETWIN(wid)->Destroy();
    }
    wid = 0;
}
will be called.

The interesting thing is: If you set two bps in the switch statement below(one for each case), you will see firstly it entered a SCI_AUTOCSHOW, and later a SCI_AUTOCCANCEL.

Code
sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
switch (iMessage) {
case SCI_AUTOCSHOW:
listType = 0;
AutoCompleteStart(wParam, reinterpret_cast<const char *>(lParam));
break;

case SCI_AUTOCCANCEL:
ac.Cancel();
break;

My question is: how to solve this issue? Thanks.

(Another question is: how to build C::B which can link to a debug version of wxWidgets library, so that I can see/track the messages more clearly, currently, gdb's bt command always stop at [debug]#17 0x00e7ff27 in wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () from E:\code\cb\cleantrunk\src\devel\wxmsw28u_gcc_custom.dll)



If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: annoying crash when debugging CC's auto-suggestion
« Reply #1 on: December 31, 2012, 10:35:09 am »
My question is: how to solve this issue? Thanks.
I don't know, you're the cc master here.

(Another question is: how to build C::B which can link to a debug version of wxWidgets library, so that I can see/track the messages more clearly, currently, gdb's bt command always stop at [debug]#17 0x00e7ff27 in wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () from E:\code\cb\cleantrunk\src\devel\wxmsw28u_gcc_custom.dll)
Build options->Custom variables and probably you should define some wxdebug macros...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: annoying crash when debugging CC's auto-suggestion
« Reply #2 on: December 31, 2012, 11:38:19 am »
My question is: how to solve this issue? Thanks.
If it's a misuse on our side, fix it here, if it is an issue in the wxScintilla-code (it's based on wxSTC) it can be fixed there and a bug-report filed against wxWidgets bug-tracker, if it is a problem with Scintilla itself, it should be fixed there and a bug-report shoukld be filed against Scintilla.

Offline p2rkw

  • Almost regular
  • **
  • Posts: 142
Re: annoying crash when debugging CC's auto-suggestion
« Reply #3 on: January 04, 2013, 04:29:31 pm »
@ollydbg:
Can you test this patch?
Code
Index: src/sdk/wxscintilla/src/PlatWX.cpp
===================================================================
--- src/sdk/wxscintilla/src/PlatWX.cpp (wersja 8739)
+++ src/sdk/wxscintilla/src/PlatWX.cpp (kopia robocza)
@@ -1286,7 +1286,21 @@
     lineHeight =  lineHeight_;
     unicodeMode = unicodeMode_;
     maxStrWidth = 0;
-    wid = new wxSCIListBoxWin (GETWIN(parent.GetID()), ctrlID, location_);
+   
+/* C::B begin */
+    if(wid == 0)
+    {
+        wid = new wxSCIListBoxWin (GETWIN(parent.GetID()), ctrlID, location_);
+    }
+    else if(GETLBW(wid)->GetParent() != GETWIN(parent.GetID()))
+    {
+        GETLBW(wid)->Reparent(GETWIN(parent.GetID()));
+    }
+    GETLBW(wid)->SetPosition(wxPoint(location_.x,location_.y));
+    GETLBW(wid)->SetId(ctrlID);
+    GETLB(wid)->SetId(ctrlID);
+/* C::B end */
+   
     if (imgList != NULL)
         GETLB(wid)->SetImageList(imgList, wxIMAGE_LIST_SMALL);
     /* C::B begin */
Index: src/sdk/wxscintilla/src/scintilla/src/AutoComplete.cxx
===================================================================
--- src/sdk/wxscintilla/src/scintilla/src/AutoComplete.cxx (wersja 8739)
+++ src/sdk/wxscintilla/src/scintilla/src/AutoComplete.cxx (kopia robocza)
@@ -57,9 +57,11 @@
 void AutoComplete::Start(Window &parent, int ctrlID,
  int position, Point location, int startLen_,
  int lineHeight, bool unicodeMode, int technology) {
- if (active) {
- Cancel();
- }
+/* C::B begin */
+// if (active) {
+// Cancel();
+// }
+/* C::B end */
  lb->Create(parent, ctrlID, location, lineHeight, unicodeMode, technology);
  lb->Clear();
  active = true;
@@ -124,7 +126,10 @@
 void AutoComplete::Cancel() {
  if (lb->Created()) {
  lb->Clear();
- lb->Destroy();
+/* C::B begin */
+ //lb->Destroy();
+ lb->Show(false);
+/* C::B end */
  active = false;
  }
 }
It hides autocomplete window instead of deleting it. It should improve performance. And with this patch applied dynamic filtering will be possible.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: annoying crash when debugging CC's auto-suggestion
« Reply #4 on: January 04, 2013, 04:53:21 pm »
And with this patch applied dynamic filtering will be possible.
Maybe no one noticed, but I thought I would mention, the trunk already uses a little dynamic filtering.  If you type:
Code
#include <wx/aui
as soon as the next directory is entered:
Code
#include <wx/aui/
the listing is refined.  Assuming auto-launch characters is set to 3 (and you are going for cbStyledTextCtrl),
Code
cbS
will launch the box, and typing auto-launch + 4 more:
Code
cbStyle
causes the listing to be refined.
That said, the filtering is currently forced to re-build the box, so there are brief pauses when it disappears, then reappears.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: annoying crash when debugging CC's auto-suggestion
« Reply #5 on: January 04, 2013, 06:06:06 pm »
Can you test this patch?
Where in this patch is the window finally being destroyed? Shouldn't this be done in the destructor, at least?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline p2rkw

  • Almost regular
  • **
  • Posts: 142
Re: annoying crash when debugging CC's auto-suggestion
« Reply #6 on: January 04, 2013, 06:38:13 pm »
Quote
That said, the filtering is currently forced to re-build the box, so there are brief pauses when it disappears, then reappears.
With patch from my previous post autocomplete window is recreated only when its have to be shown in another window (i.e when user opens another file)

Quote
will launch the box, and typing auto-launch + 4 more:
That's true, but list will be refreshed only once, my proposition is:
Code
Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp (wersja 8739)
+++ src/plugins/codecompletion/codecompletion.cpp (kopia robocza)
@@ -1619,7 +1807,7 @@
         }
 
         // code completion
-        else if (   (autoCC && !control->AutoCompActive()) // not already active autocompletion
+        else if (   (autoCC && (((pos - wordStartPos) % m_CCAutoLaunchChars) == 0))  // Refresh box every m_CCAutoLaunchChars letters
                  || (prevChar == _T('"')) // #include "
                  || (prevChar == _T('<')) // #include <
                  || (ch == _T('.'))
@@ -1629,8 +1817,7 @@
                  || (   (ch == _T(':')) // ::
                      && (prevChar == _T(':')) )
                  || (   control->AutoCompActive() // refine listing:
-                     && (   ch == _T('/')         // for #include (reduce directories)
-                         || (pos - wordStartPos == m_CCAutoLaunchChars + 4)) ) // for more typed characters
+                     && (   ch == _T('/') ))        // for #include (reduce directories)
                                                                               )
         {
             int style = control->GetStyleAt(pos);
This approach refreshes box every 'm_CCAutoLaunchChars' typed characters.

Quote
Where in this patch is the window finally being destroyed?
AutoComplete::~AutoComplete() calls Window::Destroy() - window is destroyed there (see code at first post).

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: annoying crash when debugging CC's auto-suggestion
« Reply #7 on: January 04, 2013, 06:43:15 pm »
Why not:
Code
 else if (   (autoCC && (((pos - wordStartPos) >= m_CCAutoLaunchChars))
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: annoying crash when debugging CC's auto-suggestion
« Reply #8 on: January 04, 2013, 06:46:19 pm »
Quote
Where in this patch is the window finally being destroyed?
AutoComplete::~AutoComplete() calls Window::Destroy() - window is destroyed there (see code at first post).
OK then - I was just looking at the patch...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline p2rkw

  • Almost regular
  • **
  • Posts: 142
Re: annoying crash when debugging CC's auto-suggestion
« Reply #9 on: January 04, 2013, 08:48:41 pm »
@oBFusCATed: some of users may dislike that list is refreshed every single key press, especially those who type fast and have older machines :)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: annoying crash when debugging CC's auto-suggestion
« Reply #10 on: January 04, 2013, 09:04:00 pm »
Then we will put an option to disable it.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: annoying crash when debugging CC's auto-suggestion
« Reply #11 on: January 05, 2013, 01:43:48 am »
@p2rkw, shall I test the two patches together?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline p2rkw

  • Almost regular
  • **
  • Posts: 142
Re: annoying crash when debugging CC's auto-suggestion
« Reply #12 on: January 05, 2013, 02:01:06 am »
First patch should fix your problem ( but I couldn't reproduce it ). You can apply only this one.
Second one only improves dynamic filtering of autocomplete list by little bit. It's unrelated to your problem, but without first patch second one doesn't make sense.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: annoying crash when debugging CC's auto-suggestion
« Reply #13 on: January 05, 2013, 02:34:58 am »
First patch should fix your problem ( but I couldn't reproduce it ). You can apply only this one.
OK, I applied this one, and I have no crash when debugging/stepping in "int CodeCompletion::CodeComplete()". Thanks.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: annoying crash when debugging CC's auto-suggestion
« Reply #14 on: July 24, 2013, 11:27:52 am »
FYI:
Maybe, this is a related bug/patch: Incorrect Scintilla!AutoComplete.cxx patch
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.