Author Topic: wxWidgets 3.1.2 Released  (Read 2929 times)

Offline Miguel Gimenez

  • Almost regular
  • **
  • Posts: 162
Re: wxWidgets 3.1.2 Released
« Reply #15 on: December 14, 2018, 02:04:04 pm »
Quote
If you set a breakpoint in PlatWX.cpp line 1883, you will see the window get destroyed when you hit the "#", later you will get the crash because wid is zero.

As I interpret this, when the autocomplete window is shown the editor loses focus and then the OnKillFocus event is fired, killing the autocomplete window. May be this window claims focus in wx312 while it didn't in wx311.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5161
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: wxWidgets 3.1.2 Released
« Reply #16 on: December 15, 2018, 09:44:01 am »
Quote
If you set a breakpoint in PlatWX.cpp line 1883, you will see the window get destroyed when you hit the "#", later you will get the crash because wid is zero.

As I interpret this, when the autocomplete window is shown the editor loses focus and then the OnKillFocus event is fired, killing the autocomplete window. May be this window claims focus in wx312 while it didn't in wx311.
Yes, I agree with you. I think there are some code in PlatWX.cpp, such as listbox, when get focus event, it just reset the focus to its parent window, it looks like this refocus does not happen in cb build against wx3.1.2.
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 Miguel Gimenez

  • Almost regular
  • **
  • Posts: 162
Re: wxWidgets 3.1.2 Released
« Reply #17 on: December 15, 2018, 12:03:17 pm »
I can't test until monday, but it can be related to this wxWidgets commit:

https://github.com/wxWidgets/wxWidgets/commit/79a37a2a65d8bde315bcd863838f21c72912840a

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11394
    • Travis build status
Re: wxWidgets 3.1.2 Released
« Reply #18 on: December 15, 2018, 12:32:11 pm »
Can someone reproduce this in the stc sample of wxwidgets and report this on the wx devs?
I cannot reproduce this on linux.
(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 Miguel Gimenez

  • Almost regular
  • **
  • Posts: 162
Re: wxWidgets 3.1.2 Released
« Reply #19 on: December 15, 2018, 08:51:16 pm »
Quote
Can someone reproduce this in the stc sample of wxwidgets

I have just tested the stc sample; it has code highlighting but no code completion, so there is no popup window when typing. The popup menu associated to the right button works OK.

Offline Miguel Gimenez

  • Almost regular
  • **
  • Posts: 162
Re: wxWidgets 3.1.2 Released
« Reply #20 on: December 18, 2018, 07:44:04 pm »
The wxPopupWindow used in Code Completion was reimplemented under MSW with heavy changes, see:

https://github.com/wxWidgets/wxWidgets/commit/56c419116838045f23f046112960d4e42f98f80d#diff-ae8d87556bfe1b32c101c69c2fb1cec4

This changes include moving focus back and forth; these must be triggering the KillFocus event which destroys the popup.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11394
    • Travis build status
Re: wxWidgets 3.1.2 Released
« Reply #21 on: December 18, 2018, 08:41:51 pm »
Someone needs to report this to wx devs. I intend to do some testing in the next days, but I'm not sure that my windows would start up. So if someone can modify the stc sample to reproduce the problem it will be best.

It seems this is a critical issue, so moving forward with wx 3.1.2 is blocked by this. Interesting why codelite is not affected...
(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 New Pagodi

  • Multiple posting newcomer
  • *
  • Posts: 23
Re: wxWidgets 3.1.2 Released
« Reply #22 on: December 18, 2018, 11:55:06 pm »
I don't know if this is helpful or not, but here's a patch to add a very rudimentary type of autocompletion to the wxWidgets stc sample.  It doesn't show the crash under discussion, so it might not be helpful at all.

Code: [Select]
diff --git a/samples/stc/edit.cpp b/samples/stc/edit.cpp
index 7e7f412ec2..c16b1aae2b 100644
--- a/samples/stc/edit.cpp
+++ b/samples/stc/edit.cpp
@@ -60,6 +60,21 @@ const int ANNOTATION_STYLE = wxSTC_STYLE_LASTPREDEFINED + 1;
 // Edit
 //----------------------------------------------------------------------------
 
+static char * pound_xpm[] = {
+"10 10 2 1",
+" c None",
+". c #BD08F9",
+"  ..  ..  ",
+"  ..  ..  ",
+"..........",
+"..........",
+"  ..  ..  ",
+"  ..  ..  ",
+"..........",
+"..........",
+"  ..  ..  ",
+"  ..  ..  "};
+
 wxBEGIN_EVENT_TABLE (Edit, wxStyledTextCtrl)
     // common
     EVT_SIZE (                         Edit::OnSize)
@@ -177,6 +192,10 @@ Edit::Edit (wxWindow *parent, wxWindowID id,
     CmdKeyClear (wxSTC_KEY_TAB, 0); // this is done by the menu accelerator key
     SetLayoutCache (wxSTC_CACHE_PAGE);
     UsePopUp(wxSTC_POPUP_ALL);
+   
+    wxImage::AddHandler(new wxXPMHandler);
+    wxBitmap b(pound_xpm);
+    RegisterImage(0, b);
 }
 
 Edit::~Edit () {}
@@ -483,6 +502,13 @@ void Edit::OnCharAdded (wxStyledTextEvent &event) {
         SetLineIndentation (currentLine, lineInd);
         GotoPos(PositionFromLine (currentLine) + lineInd);
     }
+    else if (chr == '#') {
+        wxString s = "define?0 elif?0 elifdef?0 elifndef?0 else?0 endif?0 "
+                      "error?0 if?0 ifdef?0 ifndef?0 include?0 line?0 line?0 "
+                      "pragma?0 undef?0";
+       
+        AutoCompShow(0,s);
+    }
 }
 
 

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11394
    • Travis build status
Re: wxWidgets 3.1.2 Released
« Reply #23 on: December 19, 2018, 02:19:50 am »
Strange. I guess we're doing something 'advanced'...
(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: 5161
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: wxWidgets 3.1.2 Released
« Reply #24 on: December 19, 2018, 06:12:23 am »
There are many code in the file: sdk\wxscintilla\src\PlatWX.cpp, which change focus to it's parent, maybe, they get conflict which the current wx3.1.2's implementation.
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 eranif

  • Regular
  • ***
  • Posts: 253
Re: wxWidgets 3.1.2 Released
« Reply #25 on: December 21, 2018, 07:23:40 pm »
Interesting why codelite is not affected...
This is because CodeLite does not use the builtin wxSTC popup window, I created my own (for other reasons) couple of years ago.
https://github.com/eranif/codelite/blob/master/Plugin/wxCodeCompletionBox.cpp

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5161
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: wxWidgets 3.1.2 Released
« Reply #26 on: December 22, 2018, 09:56:12 am »
I don't know if this is helpful or not, but here's a patch to add a very rudimentary type of autocompletion to the wxWidgets stc sample.  It doesn't show the crash under discussion, so it might not be helpful at all.

Code: [Select]
diff --git a/samples/stc/edit.cpp b/samples/stc/edit.cpp
index 7e7f412ec2..c16b1aae2b 100644
--- a/samples/stc/edit.cpp
+++ b/samples/stc/edit.cpp
@@ -60,6 +60,21 @@ const int ANNOTATION_STYLE = wxSTC_STYLE_LASTPREDEFINED + 1;
 // Edit
 //----------------------------------------------------------------------------
 
+static char * pound_xpm[] = {
+"10 10 2 1",
+" c None",
+". c #BD08F9",
+"  ..  ..  ",
+"  ..  ..  ",
+"..........",
+"..........",
+"  ..  ..  ",
+"  ..  ..  ",
+"..........",
+"..........",
+"  ..  ..  ",
+"  ..  ..  "};
+
 wxBEGIN_EVENT_TABLE (Edit, wxStyledTextCtrl)
     // common
     EVT_SIZE (                         Edit::OnSize)
@@ -177,6 +192,10 @@ Edit::Edit (wxWindow *parent, wxWindowID id,
     CmdKeyClear (wxSTC_KEY_TAB, 0); // this is done by the menu accelerator key
     SetLayoutCache (wxSTC_CACHE_PAGE);
     UsePopUp(wxSTC_POPUP_ALL);
+   
+    wxImage::AddHandler(new wxXPMHandler);
+    wxBitmap b(pound_xpm);
+    RegisterImage(0, b);
 }
 
 Edit::~Edit () {}
@@ -483,6 +502,13 @@ void Edit::OnCharAdded (wxStyledTextEvent &event) {
         SetLineIndentation (currentLine, lineInd);
         GotoPos(PositionFromLine (currentLine) + lineInd);
     }
+    else if (chr == '#') {
+        wxString s = "define?0 elif?0 elifdef?0 elifndef?0 else?0 endif?0 "
+                      "error?0 if?0 ifdef?0 ifndef?0 include?0 line?0 line?0 "
+                      "pragma?0 undef?0";
+       
+        AutoCompShow(0,s);
+    }
 }
 
 
Hi, thanks for the contribution, I just test the stc sample with your patch.
The auto suggestion(auto completion) window shows correctly after I hit the "#", and I can keep typing in the editor, while the correct item is selected.
The issue I see is that if I "deactivate" the stcsample's main frame, the auto completion list is still active, which covers every active application's window. :(

The same effect can be achieved when we comment out the line:
Code: [Select]
void cbStyledTextCtrl::OnKillFocus(wxFocusEvent& event)
{
    // cancel auto-completion list when losing focus
    //if ( AutoCompActive() )
    //    AutoCompCancel();

    if ( CallTipActive() )
        CallTipCancel();

    event.Skip();
}
With the above changes in sdk\cbstyledtextctrl.cpp, we can avoid the crash issue, but we get the same issue as the stc sample with your 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.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5161
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: wxWidgets 3.1.2 Released
« Reply #27 on: December 22, 2018, 03:39:03 pm »
When debugging, I found the reason comes from this code flow:

Code: [Select]
void AutoComplete::Show(bool show) {
lb->Show(show);     // set bp1 here
if (show)
lb->Select(0); // set bp2 here
}

When you try to show a autocompletion window, you first hit the bp1, then I see that a lose focus event happens before I hit the bp2, so the function
Code: [Select]
void cbStyledTextCtrl::OnKillFocus(wxFocusEvent& event)
{
    // cancel auto-completion list when losing focus
    if ( AutoCompActive() )
        AutoCompCancel();

    if ( CallTipActive() )
        CallTipCancel();

    event.Skip();
}
is called between bp1 and bp2.

Finally, when we goes to bp2, the window is already destroyed (wid==0).  :(
« Last Edit: December 22, 2018, 03:40:44 pm by ollydbg »
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: 11394
    • Travis build status
Re: wxWidgets 3.1.2 Released
« Reply #28 on: January 04, 2019, 01:55:26 am »
@New Pagodi:

You can use this patch to reproduce the problem:
Code: [Select]
diff --git a/samples/stc/edit.cpp b/samples/stc/edit.cpp
index 855c18f..6a1c428 100644
--- a/samples/stc/edit.cpp
+++ b/samples/stc/edit.cpp
@@ -117,6 +117,7 @@ wxBEGIN_EVENT_TABLE (Edit, wxStyledTextCtrl)
     EVT_STC_CHARADDED (wxID_ANY,       Edit::OnCharAdded)

     EVT_KEY_DOWN( Edit::OnKeyDown )
+    EVT_KILL_FOCUS(Edit::OnKillFocus)
 wxEND_EVENT_TABLE()

 Edit::Edit (wxWindow *parent, wxWindowID id,
@@ -472,6 +473,17 @@ void Edit::OnMarginClick (wxStyledTextEvent &event) {
     }
 }

+void Edit::OnKillFocus(wxFocusEvent& event)
+{
+    if ( AutoCompActive() )
+        AutoCompCancel();
+
+    if ( CallTipActive() )
+        CallTipCancel();
+
+    event.Skip();
+}
+
 void Edit::OnCharAdded (wxStyledTextEvent &event) {
     char chr = (char)event.GetKey();
     int currentLine = GetCurrentLine();
@@ -485,6 +497,21 @@ void Edit::OnCharAdded (wxStyledTextEvent &event) {
         SetLineIndentation (currentLine, lineInd);
         GotoPos(PositionFromLine (currentLine) + lineInd);
     }
+    else
+    {
+        wxString items;
+        items += "test1\r";
+        items += "test2\r";
+        items += "test3\r";
+        items += "test4\r";
+        items += "test5\r";
+
+        AutoCompSetIgnoreCase(true);
+        AutoCompSetMaxHeight(14);
+        AutoCompSetTypeSeparator(wxT('\n'));
+        AutoCompSetSeparator(wxT('\r'));
+        AutoCompShow(0, items);
+    }
 }


diff --git a/samples/stc/edit.h b/samples/stc/edit.h
index 703ebae..2762a85 100644
--- a/samples/stc/edit.h
+++ b/samples/stc/edit.h
@@ -107,6 +107,7 @@ public:
     void OnCharAdded  (wxStyledTextEvent &event);

     void OnKeyDown(wxKeyEvent &event);
+    void OnKillFocus(wxFocusEvent& event);

     //! language/lexer
     wxString DeterminePrefs (const wxString &filename);
(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 New Pagodi

  • Multiple posting newcomer
  • *
  • Posts: 23
Re: wxWidgets 3.1.2 Released
« Reply #29 on: January 04, 2019, 06:42:23 am »
I've found that the issue was that this commit changed the style of window used for popups on MSW.  I've got a proposal for a fix that restores the old behavior if the popup is created with a certain style.

While working on this, I discovered several other issues with auto completion.  I've got a work in progress here.  It needs quite a bit of clean up and has some problems compiling on GTK.  As soon as I get everything presentable, I was going to start a thread on the wxWidgets developers list asking if those fixes are acceptable.