Repeating the last performed menu command
Chris Borgolte
wx at delta-h.de
Mon Apr 7 00:38:08 PDT 2008
Vadim Zeitlin wrote:
> On Fri, 28 Mar 2008 16:35:40 +0100 Chris Borgolte <wx at delta-h.de> wrote:
>
> CB> I try to do this by keeping a copy of the last handled event and calling
> CB> ProcessEvent() with this copy.
> CB> This works with wxGTK (2.8.7) but not with wxMSW (2.8.7).
> CB>
> CB> Has anyone an idea what i'm doing wrong?
>
> I have no idea why/how does it work for wxGTK but in wxMSW (as I've just
> discovered after spending time to debug it...) when you process your stored
> event it gets to the same OnAnyMenuCommand() first which resets the shared
> pointer and so frees the old pointer (containing the event being processed)
> leaving it with garbage. In fact I think the difference is not between
> wxGTK and wxMSW but between using debug CRT (as I do under MSW) and not
> using it (as you probably don't under Unix), try to run your program under
> valgrind and you should see the problem with wxGTK too.
>
> Anyhow, the fix is, of course, to ensure that the pointer is not deleted
> which in the simplest case would consist in replacing your
>
> wxCommandEvent* e = dynamic_cast<wxCommandEvent*>(m_lastMenuCommand.get());
> assert(e);
> e->Skip(false);
> ProcessEvent(*e);
>
> with
>
> boost::shared_ptr<wxEvent> ptr(m_lastMenuCommand);
> ptr->Skip(false);
> ProcessEvent(*ptr);
>
> Regards,
> VZ
>
>
Thanks!
More information about the wx-users
mailing list