Jan Engelhardt
2014-08-08 02:47:56 UTC
When running below's sample code (on wxGTK2-3.0.1, should that matter),
I observe, on stdout,
SetEO: 0x558450
GetEO: 0xa0
SetEO: 0x558450
GetEO: (nil)
SetEO: 0x558450
GetEO: 0x74
and that just can't be remotely right, however I don't see where the
problem originates. Bind() is typesafe (or so I thought) and the
compiler does not yield warnings. valgrind points to
==30299== Invalid read of size 8
==30299== at 0x40F0F2: FooEvent::GetThing() const (q.cpp:14)
==30299== by 0x40F117: F::F()::{lambda(FooEvent&)#1}::operator()(FooEvent&)
const (q.cpp:30)
==30299== by 0x40F93E: wxEventFunctorFunctor<wxEventTypeTag<FooEvent>,
F::F()::{lambda(FooEvent&)#1}>::operator()(wxEvtHandler*, wxEvent&)
(event.h:516)
but GetThing should be ok, because there is always a call to SetThing.
#include <wx/wx.h>
class T : public wxTextCtrl {
public:
T(wxWindow *);
};
class FooEvent : public wxCommandEvent {
private:
T *m_text;
public:
using wxCommandEvent::wxCommandEvent;
void SetThing(T *p) { m_text = p; };
T *GetThing(void) const { return m_text; };
};
wxDEFINE_EVENT(FOOEVENT, FooEvent);
T::T(wxWindow *p) : wxTextCtrl(p, wxID_ANY) {
Bind(wxEVT_TEXT, [this](wxCommandEvent &) {
FooEvent e(FOOEVENT, GetId());
e.SetThing(this);
printf("SetEO: %p\n", this);
wxPostEvent(this, e);
});
};
class F : public wxFrame {
public:
F(void) : wxFrame(NULL, wxID_ANY, "") {
auto t = new T(this);
Bind(FOOEVENT, [this](FooEvent &e) {
T *x = e.GetThing();
printf("GetEO: %p\n", x);
}, t->GetId());
};
};
class A : public wxApp {
public:
bool OnInit(void) { (new F)->Show(); return true; };
};
IMPLEMENT_APP(A);
I observe, on stdout,
SetEO: 0x558450
GetEO: 0xa0
SetEO: 0x558450
GetEO: (nil)
SetEO: 0x558450
GetEO: 0x74
and that just can't be remotely right, however I don't see where the
problem originates. Bind() is typesafe (or so I thought) and the
compiler does not yield warnings. valgrind points to
==30299== Invalid read of size 8
==30299== at 0x40F0F2: FooEvent::GetThing() const (q.cpp:14)
==30299== by 0x40F117: F::F()::{lambda(FooEvent&)#1}::operator()(FooEvent&)
const (q.cpp:30)
==30299== by 0x40F93E: wxEventFunctorFunctor<wxEventTypeTag<FooEvent>,
F::F()::{lambda(FooEvent&)#1}>::operator()(wxEvtHandler*, wxEvent&)
(event.h:516)
but GetThing should be ok, because there is always a call to SetThing.
#include <wx/wx.h>
class T : public wxTextCtrl {
public:
T(wxWindow *);
};
class FooEvent : public wxCommandEvent {
private:
T *m_text;
public:
using wxCommandEvent::wxCommandEvent;
void SetThing(T *p) { m_text = p; };
T *GetThing(void) const { return m_text; };
};
wxDEFINE_EVENT(FOOEVENT, FooEvent);
T::T(wxWindow *p) : wxTextCtrl(p, wxID_ANY) {
Bind(wxEVT_TEXT, [this](wxCommandEvent &) {
FooEvent e(FOOEVENT, GetId());
e.SetThing(this);
printf("SetEO: %p\n", this);
wxPostEvent(this, e);
});
};
class F : public wxFrame {
public:
F(void) : wxFrame(NULL, wxID_ANY, "") {
auto t = new T(this);
Bind(FOOEVENT, [this](FooEvent &e) {
T *x = e.GetThing();
printf("GetEO: %p\n", x);
}, t->GetId());
};
};
class A : public wxApp {
public:
bool OnInit(void) { (new F)->Show(); return true; };
};
IMPLEMENT_APP(A);
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users