events problem Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
spectrum
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Sat Jul 21, 2007 12:17 pm

events problem

Post by spectrum »

Hello All,

i need some suggestion, in particular if there is a kind of class/tool i can use to remember some events order:

i have myframe, i click on a button, the event for button down is emitted. In the following code, OnBtnDown is entered.

With a very quick tap on the mouse, "before" OnBtnDown is completed, OnBtnUp happen.
It should someway "leave a messge and exit", to be executed only when all OnBtnDown is completed.

void MyFrame::OnBtnDown (wxMouseEvent &)
{

line of code 1
line of code 2
line of code 3
--> OnBtnUp happen
line of code 100
}


void MyFrame::OnBtnUp (wxMouseEvent &)
{
...
}

Is there some kind of semaphore class/tool to keep track of the right sequence of events ?
Many thanks,
Angelo
spectrum
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

As the event loop in wxWidgets is not multithreaded, i just don't see how this can ever happen. An eventhandler can not be entered before another one is finished unless you call wxYield or anything similar that gives control back to the event dispatcher.
Use the source, Luke!
JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway »

Hi Angelo,

Are you multi-threading? I didn't think what you described was an issue unless you were.

If you are, have a look at wxMutex:

http://docs.wxwidgets.org/2.6/wx_wxmutex.html


Hope that helps,

Jim
OS: Vista SP1, wxWidgets 2.8.7.
spectrum
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Sat Jul 21, 2007 12:17 pm

Post by spectrum »

hi all,

doublemax,
yes, it happen, normally you don't see it for small event handlers.
There is no multithreading for this, is just a simple mechanism:

OnBtnDown start
--
--
Here Happen OnBtnUp (OnBtnDown execution point is pushed on some stack)
OnBtnUp start
OnBtnUp exit
---
---
OnBtnDown exit

You can see it only on very quick tap on the button, and a quite heavy function code for OnBtnDown. I have traces of it.

JimFairway,
i think this is not a thread issue, events handlers are all in the main wxApp, and wxmutex'es called from the same thread have no effect.
spectrum
JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway »

Hi,

Might you be calling a widgets function which calls wxYield in the OnBtnDown handler?

Jim
OS: Vista SP1, wxWidgets 2.8.7.
spectrum
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Sat Jul 21, 2007 12:17 pm

Post by spectrum »

no, definitely, i removed every chance to have Yields/sleep inside the event handler. This misaligment still happen, i have traces that shows that "OnButtonUp" happen before the exiting from "OnButtonDown".

Maybe this can be due to the fact that my Frame handle OnIdle eventy also ? There inside there is a wxYield().
spectrum
spectrum
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Sat Jul 21, 2007 12:17 pm

Post by spectrum »

i apologize for confusion,

there was a wxYieldIfNeeded, and was causing this events overlapping.

manyt thanks
spectrum
Post Reply