#11013: wxGTK: 100% cpu if wxSpinCtrl::GetValue is called in an UpdateUIEvent
handler
--------------------------------+-------------------------------------------
Reporter: dghart | Owner:
Type: defect | Status: new
Priority: low | Milestone: 2.9.1
Component: wxGTK | Version: 2.9-svn
Keywords: wxSpinCtrl 100%cpu | Blockedby:
Patch: 0 | Blocking:
--------------------------------+-------------------------------------------
Two of my dialogs consume 100% cpu. This turns out to be due to them
calling wxSpinCtrl::GetValue inside their UpdateUI handler. It happens in
2.8 and 2.9, and can be demonstrated by the attached diff to the 2.9
minimal sample.
The line responsible is
src/gtk/spinctrl.cpp:154 gtk_spin_button_update(
GTK_SPIN_BUTTON(m_widget) );
The same thing also happens with wxSpinCtrl::SetRange, and
wxSpinButton::SetRange, both of which call gtk_spin_button_set_range.
The cpu overuse is because of the wx event loop continuously firing
wxEVT_IDLE and wxEVT_UPDATE_UI. I don't know how the gtk functions cause
this, or whether it's a wx or a gtk bug.
--
Ticket URL: <http://trac.wxwidgets.org/ticket/11013>
#11013: wxGTK: 100% cpu if wxSpinCtrl::GetValue is called in an UpdateUIEvent
handler
---------------------+------------------------------------------------------
Reporter: dghart | Owner:
Type: defect | Status: confirmed
Priority: low | Milestone:
Component: wxGTK | Version: 2.9-svn
Resolution: | Keywords: wxSpinCtrl 100%cpu idle
Blockedby: | Patch: 0
Blocking: |
---------------------+------------------------------------------------------
Changes (by vadz):
* cc: roebling (added)
* keywords: wxSpinCtrl 100%cpu => wxSpinCtrl 100%cpu idle
* status: new => confirmed
* milestone: 2.9.1 =>
Comment:
I have no idea why is `gtk_spin_button_update()` called here, IMO it
shouldn't but there probably was a reason for it... unfortunately only
Robert is likely to know what what it was.
Have you tried removing it? Did this result in any visible problems?
--
Ticket URL: <http://trac.wxwidgets.org/ticket/11013#comment:1>
#11013: wxGTK: 100% cpu if wxSpinCtrl::GetValue is called in an UpdateUIEvent
handler
---------------------+------------------------------------------------------
Reporter: dghart | Owner:
Type: defect | Status: confirmed
Priority: low | Milestone:
Component: wxGTK | Version: 2.9-svn
Resolution: | Keywords: wxSpinCtrl 100%cpu idle
Blockedby: | Patch: 0
Blocking: |
---------------------+------------------------------------------------------
Comment(by dghart):
Replying to [comment:1 vadz]:
> I have no idea why is `gtk_spin_button_update()` called here, IMO it
shouldn't but there probably was a reason for it... unfortunately only
Robert is likely to know what what it was.
It was probably inherited from gtk1, which added gtk_spin_button_update()
in r5194: "Corrected spin control, which ignored hand typed text."
> Have you tried removing it? Did this result in any visible problems?
I hoped it wouldn't in gtk2, but unfortunately it does. Without it, doing
GetValue() immediately after altering the control via the textctrl returns
the old value. This can be see in the widgets sample:
Index: samples/widgets/spinbtn.cpp
===================================================================
--- samples/widgets/spinbtn.cpp (revision 61521)
+++ samples/widgets/spinbtn.cpp (working copy)
@@ -528,6 +528,8 @@
{
wxLogMessage(wxT("Text changed in spin control, now \"%s\""),
event.GetString().c_str());
+ wxLogMessage(wxT("SpinCtrl now contains %d"),
+ m_spinctrl->GetValue());
}
void SpinBtnWidgetsPage::OnSpinTextEnter(wxCommandEvent& event)
--
Ticket URL: <http://trac.wxwidgets.org/ticket/11013#comment:2>
#11013: wxGTK: 100% cpu if wxSpinCtrl::GetValue is called in an UpdateUIEvent
handler
-------------------------------------+--------------------------------------
Reporter: dghart | Owner:
Type: defect | Status: confirmed
Priority: low | Milestone:
Component: wxGTK | Version: 2.9-svn
Keywords: wxSpinCtrl 100%cpu idle | Blockedby:
Patch: 1 | Blocking:
-------------------------------------+--------------------------------------
Changes (by AlexeyT):
* cc: zone19@… (added)
* patch: 0 => 1
Comment:
I do patch which fix this problem for my program. May be this patch can be
usefull for you too. I tested it in some cases and all work fine. I hope
patch don't do some behaviour regressions.
--
Ticket URL: <http://trac.wxwidgets.org/ticket/11013#comment:3>
#11013: wxGTK: 100% cpu if wxSpinCtrl::GetValue is called in an UpdateUIEvent
handler
-------------------------------------+--------------------------------------
Reporter: dghart | Owner:
Type: defect | Status: confirmed
Priority: low | Milestone:
Component: wxGTK | Version: 2.9-svn
Keywords: wxSpinCtrl 100%cpu idle | Blockedby:
Patch: 1 | Blocking:
-------------------------------------+--------------------------------------
Comment(by dghart):
I confirm that the patch works in the minimal sample diff and in my app,
and behaves correctly in the 'widgets' spinctrls. Thanks, Alexey!
I attach a 2.8-branch diff too.
--
Ticket URL: <http://trac.wxwidgets.org/ticket/11013#comment:4>
#11013: wxGTK: 100% cpu if wxSpinCtrl::GetValue is called in an UpdateUIEvent
handler
-------------------------------------+--------------------------------------
Reporter: dghart | Owner: pcor
Type: defect | Status: accepted
Priority: low | Milestone: 2.8.11
Component: wxGTK | Version: 2.8.10
Keywords: wxSpinCtrl 100%cpu idle | Blockedby:
Patch: 1 | Blocking:
-------------------------------------+--------------------------------------
Changes (by pcor):
* owner: => pcor
* status: confirmed => accepted
* version: 2.9-svn => 2.8.10
* milestone: => 2.8.11
Comment:
The patch is not correct, it won't allow entering 10 into a control with a
range of 5 to 50 for instance. I'll come up with a fix.
--
Ticket URL: <http://trac.wxwidgets.org/ticket/11013#comment:5>
#11013: wxGTK: 100% cpu if wxSpinCtrl::GetValue is called in an UpdateUIEvent
handler
---------------------+------------------------------------------------------
Reporter: dghart | Owner: pcor
Type: defect | Status: closed
Priority: low | Milestone: 2.8.11
Component: wxGTK | Version: 2.8.10
Resolution: fixed | Keywords: wxSpinCtrl 100%cpu idle
Blockedby: | Patch: 1
Blocking: |
---------------------+------------------------------------------------------
Changes (by PC):
* status: accepted => closed
* resolution: => fixed
Comment:
(In [62574]) avoid causing idle event from GetValue(), fixes #11013
--
Ticket URL: <http://trac.wxwidgets.org/ticket/11013#comment:6>