[wx-dev] Re: Idle processing

Paul Cornett pc-wx at bullseye.com
Sun Jul 15 11:21:20 PDT 2007


Arne Steinarson wrote:
> The main point is that when using asynchronous events
> (AddPendingEvent) one must be sure at some point there
> are no pointers around to objects being deleted. So
> the event queue must be empty if you ever put such
> pointers in events objects. I find I have to do this
> check manually now, in each OnIdle handler. 
> 
> There are two things that cause the event queue to be
> non-empty:
> 1 - As you say, during ProcessPendingEvents, new
> events are generated.
> 2 - There can be _several_ event loops (when showing a
> modal dialog, it installs a new event loop). And the
> Pending function when returning false only says there
> are no pending events in the current event loop. 

Okay, I think we've got some terminology confusion here.
AddPendingEvent deals with wxEvents, and uses a platform-independent
queuing and dispatch mechanism. Event loops are plaform-specific and do
not use wxEvents, and have nothing to do with AddPendingEvent.

> I verified that Pending() and HasPendingEvents() do
> return different values. 

Of course, since they mean different things.

> When it comes to 'garbage collection' the scenario is
> this:
> 
> 1 - App receives idle event
> 2 - It starts deleting dead objects
> 3 - Returns from idle handler
> 4 - Pending events with now dangling pointers are
> received in event handlers.
> 5 - Crash.

So, in response to a posted wxEvent, you post another (presumably
custom?) wxEvent, which contains a pointer to an object (a window?)
which is, or very soon will be, in the wxPendingDelete list. Without a
better idea of what you're doing, I'm inclined to say "don't do that".

> Most wxWidgets projects tend to use synchronous events
> and then this is less of an issue.
> 
> I have a patch I've been testing for some days now (so
> far no probs), I'll submit it when I feel confident it
> is solid.

Looking at wxEvtHandler::ProcessPendingEvents(), I see that only
wxEvents present at the start are processed, and it's explicitly done
that way to prevent the possibility of an infinite loop, with a comment
to that effect. So I'm skeptical anyone is going to be willing to
change that.




More information about the wx-dev mailing list