Discussion:
stack overflow in event disconnect?
Alan Wolfe
2011-06-20 17:03:35 UTC
Permalink
Hi!

I'm hitting an issue where when i disconnect an event I'm getting a stack
overflow.

The details are that i have a wxScrolledWindow (inside of a sizer which is
inside of another sizer, which is inside of a panel which is.... etc).

Inside of that scrolled window I'm creating several wxCheckBoxes like so...
("this" is my main wxFrame)

wxCheckBox *pNewCheckBox = new wxCheckBox(m_scrolledWindow1,
wxID_ANY, pBone->m_sBoneName.c_str());

bSizer5->Add(pNewCheckBox, 0, wxALL, 5);

pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ),
pNewCheckBox, this );

Then, when i go to clear them out i do something like this:

wxSizerItemList &rItemList = bSizer5->GetChildren();

for(wxSizerItemList::iterator it = rItemList.begin(); it !=
rItemList.end(); ++it)
{
wxCheckBox *pCB = wxDynamicCast((*it)->GetWindow(),wxCheckBox);
if(pCB)
{
//TODO: why does this cause a stack overflow?
pCB->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ), pCB, this
);
}
}

bSizer5->Clear(true);

The stack overflow happens in the Disconnect, but if I don't disconnect, it
happens in the Clear function at the end. The stack looks like below,
repeating all the way to the bottom where it says the max # of frames in
visual studio has been exceeded so i can't look any deeper.
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0xd bytes C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes C++

Anyone know what I might be doing wrong?

Thanks!
--
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
Igor Korot
2011-06-21 06:25:16 UTC
Permalink
Hi,
Can you reproduce it in a sample?
What is your compiler, OS, wx version?
Did you build wx with the standard configuration options?

Thank you.
Post by Alan Wolfe
Hi!
I'm hitting an issue where when i disconnect an event I'm getting a stack
overflow.
The details are that i have a wxScrolledWindow (inside of a sizer which is
inside of another sizer, which is inside of a panel which is.... etc).
Inside of that scrolled window I'm creating several wxCheckBoxes like so...
("this" is my main wxFrame)
            wxCheckBox *pNewCheckBox = new wxCheckBox(m_scrolledWindow1,
wxID_ANY, pBone->m_sBoneName.c_str());
            bSizer5->Add(pNewCheckBox, 0, wxALL, 5);
            pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ),
pNewCheckBox, this );
    wxSizerItemList &rItemList = bSizer5->GetChildren();
    for(wxSizerItemList::iterator it = rItemList.begin(); it !=
rItemList.end(); ++it)
    {
        wxCheckBox *pCB = wxDynamicCast((*it)->GetWindow(),wxCheckBox);
        if(pCB)
        {
            //TODO: why does this cause a stack overflow?
            pCB->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ), pCB, this
);
        }
    }
    bSizer5->Clear(true);
The stack overflow happens in the Disconnect, but if I don't disconnect, it
happens in the Clear function at the end.  The stack looks like below,
repeating all the way to the bottom where it says the max # of frames in
visual studio has been exceeded so i can't look any deeper.
    AnimSandbox.exe!wxEvtHandler::~wxEvtHandler()  + 0xd bytes    C++
     AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'()  + 0x8
bytes    C++
     AnimSandbox.exe!wxEvtHandler::~wxEvtHandler()  + 0x73 bytes    C++
     AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'()  + 0x8
bytes    C++
     AnimSandbox.exe!wxEvtHandler::~wxEvtHandler()  + 0x73 bytes    C++
Anyone know what I might be doing wrong?
Thanks!
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
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
Alan Wolfe
2011-06-21 15:12:02 UTC
Permalink
Well, it's working now strangely.

I changed the connect / disconnect to look like this:

pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainForm::OnBoneSetBoneClicked ), NULL, this );

the differences...

1) the callback before specified a function on a derived class, now it's the
base class.
2) i was passing the new checkbox as the userdata (2nd to last param), now
i'm passing null as i realized i can still get the object that triggered the
event without sending it as user data.

not sure which of the 2 changes made it work but it's working now.

i think i'm using a fairly old version (1 year old +) as these are libs i
built a while ago and just keep re-using.

If more info would be helpful let me know and i can isolate which thing
fixed it / get you the version number I'm using.
Post by Igor Korot
Hi,
Can you reproduce it in a sample?
What is your compiler, OS, wx version?
Did you build wx with the standard configuration options?
Thank you.
Post by Alan Wolfe
Hi!
I'm hitting an issue where when i disconnect an event I'm getting a stack
overflow.
The details are that i have a wxScrolledWindow (inside of a sizer which
is
Post by Alan Wolfe
inside of another sizer, which is inside of a panel which is.... etc).
Inside of that scrolled window I'm creating several wxCheckBoxes like
so...
Post by Alan Wolfe
("this" is my main wxFrame)
wxCheckBox *pNewCheckBox = new wxCheckBox(m_scrolledWindow1,
wxID_ANY, pBone->m_sBoneName.c_str());
bSizer5->Add(pNewCheckBox, 0, wxALL, 5);
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ),
pNewCheckBox, this );
wxSizerItemList &rItemList = bSizer5->GetChildren();
for(wxSizerItemList::iterator it = rItemList.begin(); it !=
rItemList.end(); ++it)
{
wxCheckBox *pCB = wxDynamicCast((*it)->GetWindow(),wxCheckBox);
if(pCB)
{
//TODO: why does this cause a stack overflow?
pCB->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ), pCB,
this
Post by Alan Wolfe
);
}
}
bSizer5->Clear(true);
The stack overflow happens in the Disconnect, but if I don't disconnect,
it
Post by Alan Wolfe
happens in the Clear function at the end. The stack looks like below,
repeating all the way to the bottom where it says the max # of frames in
visual studio has been exceeded so i can't look any deeper.
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0xd bytes C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes C++
Anyone know what I might be doing wrong?
Thanks!
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
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
i***@gmail.com
2011-06-21 16:22:43 UTC
Permalink
Hi,
Most likely this issue is resolved in later version of wx.
Which version are working with?
Also what OS and compiler?

Sent from my HTC Inspire™ 4G on AT&T

----- Reply message -----
From: "Alan Wolfe" <***@gmail.com>
To: <wx-***@googlegroups.com>
Subject: stack overflow in event disconnect?
Date: Tue, Jun 21, 2011 08:12
Well, it's working now strangely.

I changed the connect / disconnect to look like this:

pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( wxASMainForm::OnBoneSetBoneClicked ), NULL, this );


the differences...

1) the callback before specified a function on a derived class, now it's the base class.
2) i was passing the new checkbox as the userdata (2nd to last param), now i'm passing null as i realized i can still get the object that triggered the event without sending it as user data.


not sure which of the 2 changes made it work but it's working now.

i think i'm using a fairly old version (1 year old +) as these are libs i built a while ago and just keep re-using.

If more info would be helpful let me know and i can isolate which thing fixed it / get you the version number I'm using.


On Mon, Jun 20, 2011 at 11:25 PM, Igor Korot <***@gmail.com> wrote:

Hi,

Can you reproduce it in a sample?

What is your compiler, OS, wx version?

Did you build wx with the standard configuration options?



Thank you.
Post by Alan Wolfe
Hi!
I'm hitting an issue where when i disconnect an event I'm getting a stack
overflow.
The details are that i have a wxScrolledWindow (inside of a sizer which is
inside of another sizer, which is inside of a panel which is.... etc).
Inside of that scrolled window I'm creating several wxCheckBoxes like so...
("this" is my main wxFrame)
            wxCheckBox *pNewCheckBox = new wxCheckBox(m_scrolledWindow1,
wxID_ANY, pBone->m_sBoneName.c_str());
            bSizer5->Add(pNewCheckBox, 0, wxALL, 5);
            pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ),
pNewCheckBox, this );
    wxSizerItemList &rItemList = bSizer5->GetChildren();
    for(wxSizerItemList::iterator it = rItemList.begin(); it !=
rItemList.end(); ++it)
    {
        wxCheckBox *pCB = wxDynamicCast((*it)->GetWindow(),wxCheckBox);
        if(pCB)
        {
            //TODO: why does this cause a stack overflow?
            pCB->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ), pCB, this
);
        }
    }
    bSizer5->Clear(true);
The stack overflow happens in the Disconnect, but if I don't disconnect, it
happens in the Clear function at the end.  The stack looks like below,
repeating all the way to the bottom where it says the max # of frames in
visual studio has been exceeded so i can't look any deeper.
    AnimSandbox.exe!wxEvtHandler::~wxEvtHandler()  + 0xd bytes    C++
     AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'()  + 0x8
bytes    C++
     AnimSandbox.exe!wxEvtHandler::~wxEvtHandler()  + 0x73 bytes    C++
     AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'()  + 0x8
bytes    C++
     AnimSandbox.exe!wxEvtHandler::~wxEvtHandler()  + 0x73 bytes    C++
Anyone know what I might be doing wrong?
Thanks!
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
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
--
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
z***@gmail.com
2014-08-10 17:21:32 UTC
Permalink
Hi,

As of 2014, this issue is still not resolved.

If you pass your event source object as userData for Bind/Connect, then
during Unbind/Disconnect that infinite loop happens because of `delete
userData` call by wxWidgets.

Why not treat userData as void* and leave its ownership to user?

P.S. one might want to pass source object as userData, when using event
handler sink - in order to be able to refer to the aforementioned event
source object in that sink event handler. Is there any other better ways of
doing it?

Thanks,
Zura
Post by i***@gmail.com
Hi,
Most likely this issue is resolved in later version of wx.
Which version are working with?
Also what OS and compiler?
Sent from my HTC Inspire™ 4G on AT&T
----- Reply message -----
Subject: stack overflow in event disconnect?
Date: Tue, Jun 21, 2011 08:12
Well, it's working now strangely.
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainForm::OnBoneSetBoneClicked ), NULL, this );
the differences...
1) the callback before specified a function on a derived class, now it's the base class.
2) i was passing the new checkbox as the userdata (2nd to last param), now
i'm passing null as i realized i can still get the object that triggered
the event without sending it as user data.
not sure which of the 2 changes made it work but it's working now.
i think i'm using a fairly old version (1 year old +) as these are libs i
built a while ago and just keep re-using.
If more info would be helpful let me know and i can isolate which thing
fixed it / get you the version number I'm using.
Post by Igor Korot
Hi,
Can you reproduce it in a sample?
What is your compiler, OS, wx version?
Did you build wx with the standard configuration options?
Thank you.
Post by Alan Wolfe
Hi!
I'm hitting an issue where when i disconnect an event I'm getting a
stack
Post by Alan Wolfe
overflow.
The details are that i have a wxScrolledWindow (inside of a sizer which
is
Post by Alan Wolfe
inside of another sizer, which is inside of a panel which is.... etc).
Inside of that scrolled window I'm creating several wxCheckBoxes like
so...
Post by Alan Wolfe
("this" is my main wxFrame)
wxCheckBox *pNewCheckBox = new wxCheckBox(m_scrolledWindow1,
wxID_ANY, pBone->m_sBoneName.c_str());
bSizer5->Add(pNewCheckBox, 0, wxALL, 5);
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ),
pNewCheckBox, this );
wxSizerItemList &rItemList = bSizer5->GetChildren();
for(wxSizerItemList::iterator it = rItemList.begin(); it !=
rItemList.end(); ++it)
{
wxCheckBox *pCB = wxDynamicCast((*it)->GetWindow(),wxCheckBox);
if(pCB)
{
//TODO: why does this cause a stack overflow?
pCB->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ), pCB,
this
Post by Alan Wolfe
);
}
}
bSizer5->Clear(true);
The stack overflow happens in the Disconnect, but if I don't
disconnect, it
Post by Alan Wolfe
happens in the Clear function at the end. The stack looks like below,
repeating all the way to the bottom where it says the max # of frames in
visual studio has been exceeded so i can't look any deeper.
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0xd bytes C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes C++
Anyone know what I might be doing wrong?
Thanks!
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before
posting.
<javascript:>
Post by Alan Wolfe
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
<javascript:>
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
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
Igor Korot
2014-08-10 19:36:26 UTC
Permalink
Hi, Zura,
Post by z***@gmail.com
Hi,
As of 2014, this issue is still not resolved.
If you pass your event source object as userData for Bind/Connect, then
during Unbind/Disconnect that infinite loop happens because of `delete
userData` call by wxWidgets.
Why not treat userData as void* and leave its ownership to user?
P.S. one might want to pass source object as userData, when using event
handler sink - in order to be able to refer to the aforementioned event
source object in that sink event handler. Is there any other better ways of
doing it?
In the event handler, you can call:

event.GetEventObject();

and it will give you the object that initiate this event.

Thank you.
Post by z***@gmail.com
Thanks,
Zura
Post by i***@gmail.com
Hi,
Most likely this issue is resolved in later version of wx.
Which version are working with?
Also what OS and compiler?
Sent from my HTC Inspire™ 4G on AT&T
----- Reply message -----
Subject: stack overflow in event disconnect?
Date: Tue, Jun 21, 2011 08:12
Well, it's working now strangely.
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainForm::OnBoneSetBoneClicked ), NULL, this );
the differences...
1) the callback before specified a function on a derived class, now it's the base class.
2) i was passing the new checkbox as the userdata (2nd to last param), now
i'm passing null as i realized i can still get the object that triggered the
event without sending it as user data.
not sure which of the 2 changes made it work but it's working now.
i think i'm using a fairly old version (1 year old +) as these are libs i
built a while ago and just keep re-using.
If more info would be helpful let me know and i can isolate which thing
fixed it / get you the version number I'm using.
Post by Igor Korot
Hi,
Can you reproduce it in a sample?
What is your compiler, OS, wx version?
Did you build wx with the standard configuration options?
Thank you.
Post by Alan Wolfe
Hi!
I'm hitting an issue where when i disconnect an event I'm getting a stack
overflow.
The details are that i have a wxScrolledWindow (inside of a sizer which is
inside of another sizer, which is inside of a panel which is.... etc).
Inside of that scrolled window I'm creating several wxCheckBoxes like so...
("this" is my main wxFrame)
wxCheckBox *pNewCheckBox = new
wxCheckBox(m_scrolledWindow1,
wxID_ANY, pBone->m_sBoneName.c_str());
bSizer5->Add(pNewCheckBox, 0, wxALL, 5);
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ),
pNewCheckBox, this );
wxSizerItemList &rItemList = bSizer5->GetChildren();
for(wxSizerItemList::iterator it = rItemList.begin(); it !=
rItemList.end(); ++it)
{
wxCheckBox *pCB = wxDynamicCast((*it)->GetWindow(),wxCheckBox);
if(pCB)
{
//TODO: why does this cause a stack overflow?
pCB->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ), pCB, this
);
}
}
bSizer5->Clear(true);
The stack overflow happens in the Disconnect, but if I don't disconnect, it
happens in the Clear function at the end. The stack looks like below,
repeating all the way to the bottom where it says the max # of frames in
visual studio has been exceeded so i can't look any deeper.
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0xd bytes C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes C++
Anyone know what I might be doing wrong?
Thanks!
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
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
z***@gmail.com
2014-08-11 05:41:57 UTC
Permalink
Hi Igor, Vadim

I'm talking about a situation when you need to use an event sink:

dlg->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &OtherClass::OtherMethod,
otherClassObj, wxID_ANY, wxID_ANY, dlg);


So here it is impossible to pass `dlg` pointer as the last argument. There
is also no elegant way of getting it (e.g. from wxCommandEvent object in
the handler).

So we have to fall back to some kind of workaround, as Vadim recommends.

Treating user data as void* is quite common and intuitive so please
consider addition of this variant in the future (Like you have
SetClientData and SetClientObject).

Thank you,
Zura
Post by Igor Korot
Hi, Zura,
Post by z***@gmail.com
Hi,
As of 2014, this issue is still not resolved.
If you pass your event source object as userData for Bind/Connect, then
during Unbind/Disconnect that infinite loop happens because of `delete
userData` call by wxWidgets.
Why not treat userData as void* and leave its ownership to user?
P.S. one might want to pass source object as userData, when using event
handler sink - in order to be able to refer to the aforementioned event
source object in that sink event handler. Is there any other better ways
of
Post by z***@gmail.com
doing it?
event.GetEventObject();
and it will give you the object that initiate this event.
Thank you.
Post by z***@gmail.com
Thanks,
Zura
Post by i***@gmail.com
Hi,
Most likely this issue is resolved in later version of wx.
Which version are working with?
Also what OS and compiler?
Sent from my HTC Inspire™ 4G on AT&T
----- Reply message -----
Subject: stack overflow in event disconnect?
Date: Tue, Jun 21, 2011 08:12
Well, it's working now strangely.
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainForm::OnBoneSetBoneClicked ), NULL, this
);
Post by z***@gmail.com
Post by i***@gmail.com
the differences...
1) the callback before specified a function on a derived class, now
it's
Post by z***@gmail.com
Post by i***@gmail.com
the base class.
2) i was passing the new checkbox as the userdata (2nd to last param),
now
Post by z***@gmail.com
Post by i***@gmail.com
i'm passing null as i realized i can still get the object that
triggered the
Post by z***@gmail.com
Post by i***@gmail.com
event without sending it as user data.
not sure which of the 2 changes made it work but it's working now.
i think i'm using a fairly old version (1 year old +) as these are libs
i
Post by z***@gmail.com
Post by i***@gmail.com
built a while ago and just keep re-using.
If more info would be helpful let me know and i can isolate which thing
fixed it / get you the version number I'm using.
Post by Igor Korot
Hi,
Can you reproduce it in a sample?
What is your compiler, OS, wx version?
Did you build wx with the standard configuration options?
Thank you.
Post by Alan Wolfe
Hi!
I'm hitting an issue where when i disconnect an event I'm getting a stack
overflow.
The details are that i have a wxScrolledWindow (inside of a sizer
which
Post by z***@gmail.com
Post by i***@gmail.com
Post by Igor Korot
Post by Alan Wolfe
is
inside of another sizer, which is inside of a panel which is....
etc).
Post by z***@gmail.com
Post by i***@gmail.com
Post by Igor Korot
Post by Alan Wolfe
Inside of that scrolled window I'm creating several wxCheckBoxes
like
Post by z***@gmail.com
Post by i***@gmail.com
Post by Igor Korot
Post by Alan Wolfe
so...
("this" is my main wxFrame)
wxCheckBox *pNewCheckBox = new
wxCheckBox(m_scrolledWindow1,
wxID_ANY, pBone->m_sBoneName.c_str());
bSizer5->Add(pNewCheckBox, 0, wxALL, 5);
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ),
pNewCheckBox, this );
wxSizerItemList &rItemList = bSizer5->GetChildren();
for(wxSizerItemList::iterator it = rItemList.begin(); it !=
rItemList.end(); ++it)
{
wxCheckBox *pCB =
wxDynamicCast((*it)->GetWindow(),wxCheckBox);
Post by z***@gmail.com
Post by i***@gmail.com
Post by Igor Korot
Post by Alan Wolfe
if(pCB)
{
//TODO: why does this cause a stack overflow?
pCB->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ),
pCB,
Post by z***@gmail.com
Post by i***@gmail.com
Post by Igor Korot
Post by Alan Wolfe
this
);
}
}
bSizer5->Clear(true);
The stack overflow happens in the Disconnect, but if I don't disconnect, it
happens in the Clear function at the end. The stack looks like
below,
Post by z***@gmail.com
Post by i***@gmail.com
Post by Igor Korot
Post by Alan Wolfe
repeating all the way to the bottom where it says the max # of
frames
Post by z***@gmail.com
Post by i***@gmail.com
Post by Igor Korot
Post by Alan Wolfe
in
visual studio has been exceeded so i can't look any deeper.
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0xd bytes
C++
Post by z***@gmail.com
Post by i***@gmail.com
Post by Igor Korot
Post by Alan Wolfe
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes
C++
Post by z***@gmail.com
Post by i***@gmail.com
Post by Igor Korot
Post by Alan Wolfe
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes
C++
Post by z***@gmail.com
Post by i***@gmail.com
Post by Igor Korot
Post by Alan Wolfe
Anyone know what I might be doing wrong?
Thanks!
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before
posting.
Post by z***@gmail.com
Post by i***@gmail.com
Post by Igor Korot
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before
posting.
Post by z***@gmail.com
Post by i***@gmail.com
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before
posting.
<javascript:>
Post by z***@gmail.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
Igor Korot
2014-08-11 05:52:05 UTC
Permalink
Hi, Zura,
Post by z***@gmail.com
Hi Igor, Vadim
dlg->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &OtherClass::OtherMethod,
otherClassObj, wxID_ANY, wxID_ANY, dlg);
So here it is impossible to pass `dlg` pointer as the last argument. There
is also no elegant way of getting it (e.g. from wxCommandEvent object in the
handler).
What do you see if you execute the following:

void OtherClass::OtherMethod(wxCommandEvent &event)
{
// assuming that in the code above dlg is of the class wxDialog
wxDialog obj = event.GetEventObject();
}

Thank you.
Post by z***@gmail.com
So we have to fall back to some kind of workaround, as Vadim recommends.
Treating user data as void* is quite common and intuitive so please consider
addition of this variant in the future (Like you have SetClientData and
SetClientObject).
Thank you,
Zura
Post by Igor Korot
Hi, Zura,
Post by z***@gmail.com
Hi,
As of 2014, this issue is still not resolved.
If you pass your event source object as userData for Bind/Connect, then
during Unbind/Disconnect that infinite loop happens because of `delete
userData` call by wxWidgets.
Why not treat userData as void* and leave its ownership to user?
P.S. one might want to pass source object as userData, when using event
handler sink - in order to be able to refer to the aforementioned event
source object in that sink event handler. Is there any other better ways of
doing it?
event.GetEventObject();
and it will give you the object that initiate this event.
Thank you.
Post by z***@gmail.com
Thanks,
Zura
Post by i***@gmail.com
Hi,
Most likely this issue is resolved in later version of wx.
Which version are working with?
Also what OS and compiler?
Sent from my HTC Inspire™ 4G on AT&T
----- Reply message -----
Subject: stack overflow in event disconnect?
Date: Tue, Jun 21, 2011 08:12
Well, it's working now strangely.
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainForm::OnBoneSetBoneClicked ), NULL, this );
the differences...
1) the callback before specified a function on a derived class, now
it's
the base class.
2) i was passing the new checkbox as the userdata (2nd to last param), now
i'm passing null as i realized i can still get the object that triggered the
event without sending it as user data.
not sure which of the 2 changes made it work but it's working now.
i think i'm using a fairly old version (1 year old +) as these are libs i
built a while ago and just keep re-using.
If more info would be helpful let me know and i can isolate which thing
fixed it / get you the version number I'm using.
Post by Igor Korot
Hi,
Can you reproduce it in a sample?
What is your compiler, OS, wx version?
Did you build wx with the standard configuration options?
Thank you.
Post by Alan Wolfe
Hi!
I'm hitting an issue where when i disconnect an event I'm getting a stack
overflow.
The details are that i have a wxScrolledWindow (inside of a sizer which
is
inside of another sizer, which is inside of a panel which is.... etc).
Inside of that scrolled window I'm creating several wxCheckBoxes like
so...
("this" is my main wxFrame)
wxCheckBox *pNewCheckBox = new
wxCheckBox(m_scrolledWindow1,
wxID_ANY, pBone->m_sBoneName.c_str());
bSizer5->Add(pNewCheckBox, 0, wxALL, 5);
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ),
pNewCheckBox, this );
wxSizerItemList &rItemList = bSizer5->GetChildren();
for(wxSizerItemList::iterator it = rItemList.begin(); it !=
rItemList.end(); ++it)
{
wxCheckBox *pCB =
wxDynamicCast((*it)->GetWindow(),wxCheckBox);
if(pCB)
{
//TODO: why does this cause a stack overflow?
pCB->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ), pCB,
this
);
}
}
bSizer5->Clear(true);
The stack overflow happens in the Disconnect, but if I don't disconnect, it
happens in the Clear function at the end. The stack looks like below,
repeating all the way to the bottom where it says the max # of
frames
in
visual studio has been exceeded so i can't look any deeper.
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0xd bytes
C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes
C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes
C++
Anyone know what I might be doing wrong?
Thanks!
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
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
Zura Khetsuriani
2014-08-11 06:01:28 UTC
Permalink
Hi Igor,

event.GetEventObject() returns an object (pointer to it), which
generates an event, e.g. it can be some wxButton, wxComboBox, etc..

Zura
Post by Igor Korot
Hi, Zura,
Post by z***@gmail.com
Hi Igor, Vadim
dlg->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &OtherClass::OtherMethod,
otherClassObj, wxID_ANY, wxID_ANY, dlg);
So here it is impossible to pass `dlg` pointer as the last argument. There
is also no elegant way of getting it (e.g. from wxCommandEvent object in the
handler).
void OtherClass::OtherMethod(wxCommandEvent &event)
{
// assuming that in the code above dlg is of the class wxDialog
wxDialog obj = event.GetEventObject();
}
Thank you.
Post by z***@gmail.com
So we have to fall back to some kind of workaround, as Vadim recommends.
Treating user data as void* is quite common and intuitive so please consider
addition of this variant in the future (Like you have SetClientData and
SetClientObject).
Thank you,
Zura
Post by Igor Korot
Hi, Zura,
Post by z***@gmail.com
Hi,
As of 2014, this issue is still not resolved.
If you pass your event source object as userData for Bind/Connect, then
during Unbind/Disconnect that infinite loop happens because of `delete
userData` call by wxWidgets.
Why not treat userData as void* and leave its ownership to user?
P.S. one might want to pass source object as userData, when using event
handler sink - in order to be able to refer to the aforementioned event
source object in that sink event handler. Is there any other better ways of
doing it?
event.GetEventObject();
and it will give you the object that initiate this event.
Thank you.
Post by z***@gmail.com
Thanks,
Zura
Post by i***@gmail.com
Hi,
Most likely this issue is resolved in later version of wx.
Which version are working with?
Also what OS and compiler?
Sent from my HTC Inspire™ 4G on AT&T
----- Reply message -----
Subject: stack overflow in event disconnect?
Date: Tue, Jun 21, 2011 08:12
Well, it's working now strangely.
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainForm::OnBoneSetBoneClicked ), NULL, this );
the differences...
1) the callback before specified a function on a derived class, now
it's
the base class.
2) i was passing the new checkbox as the userdata (2nd to last param), now
i'm passing null as i realized i can still get the object that triggered the
event without sending it as user data.
not sure which of the 2 changes made it work but it's working now.
i think i'm using a fairly old version (1 year old +) as these are libs i
built a while ago and just keep re-using.
If more info would be helpful let me know and i can isolate which thing
fixed it / get you the version number I'm using.
Post by Igor Korot
Hi,
Can you reproduce it in a sample?
What is your compiler, OS, wx version?
Did you build wx with the standard configuration options?
Thank you.
Post by Alan Wolfe
Hi!
I'm hitting an issue where when i disconnect an event I'm getting a stack
overflow.
The details are that i have a wxScrolledWindow (inside of a sizer which
is
inside of another sizer, which is inside of a panel which is.... etc).
Inside of that scrolled window I'm creating several wxCheckBoxes like
so...
("this" is my main wxFrame)
wxCheckBox *pNewCheckBox = new
wxCheckBox(m_scrolledWindow1,
wxID_ANY, pBone->m_sBoneName.c_str());
bSizer5->Add(pNewCheckBox, 0, wxALL, 5);
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ),
pNewCheckBox, this );
wxSizerItemList &rItemList = bSizer5->GetChildren();
for(wxSizerItemList::iterator it = rItemList.begin(); it !=
rItemList.end(); ++it)
{
wxCheckBox *pCB =
wxDynamicCast((*it)->GetWindow(),wxCheckBox);
if(pCB)
{
//TODO: why does this cause a stack overflow?
pCB->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ), pCB,
this
);
}
}
bSizer5->Clear(true);
The stack overflow happens in the Disconnect, but if I don't disconnect, it
happens in the Clear function at the end. The stack looks like below,
repeating all the way to the bottom where it says the max # of
frames
in
visual studio has been exceeded so i can't look any deeper.
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0xd bytes
C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes
C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'() + 0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes
C++
Anyone know what I might be doing wrong?
Thanks!
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
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
Marian 'VooDooMan' Meravy
2014-08-11 07:46:53 UTC
Permalink
Greetings,
Post by z***@gmail.com
Hi Igor,
event.GetEventObject() returns an object (pointer to it), which
generates an event, e.g. it can be some wxButton, wxComboBox, etc..
[1] Yes! and this is the pointer, even more, with the right type you
need in your code.

[2] "userData" is intended for time being to be user's object that will
be automatically deleted, when event object itself is deleted. This is
WX facility that has been around since the time being.

If we had changed this behaviour, it would cause memory leak in all
existing code in all projects using it, since it is pretty documented
for many years, that "userData" is automatical pointer, i.e. it is
delete automatically, so you don't bother about delete'ing it. It is for
user's convenience. In other words, it is not a bug, it is feature, and
this time I am not speaking ironically.

[3] BUT: if you bother, then use shared_ptr feature of C++ like Vadim
suggested.

Really, there is no other way. possibilities are again [1] or [2] or
[3], it is up to you which way you will chose in your code...

best,
vdm
.
Post by z***@gmail.com
Zura
Post by Igor Korot
Hi, Zura,
Post by z***@gmail.com
Hi Igor, Vadim
dlg->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &OtherClass::OtherMethod,
otherClassObj, wxID_ANY, wxID_ANY, dlg);
So here it is impossible to pass `dlg` pointer as the last argument. There
is also no elegant way of getting it (e.g. from wxCommandEvent object in the
handler).
void OtherClass::OtherMethod(wxCommandEvent &event)
{
// assuming that in the code above dlg is of the class wxDialog
wxDialog obj = event.GetEventObject();
}
Thank you.
Post by z***@gmail.com
So we have to fall back to some kind of workaround, as Vadim recommends.
Treating user data as void* is quite common and intuitive so please consider
addition of this variant in the future (Like you have SetClientData and
SetClientObject).
Thank you,
Zura
Post by Igor Korot
Hi, Zura,
Post by z***@gmail.com
Hi,
As of 2014, this issue is still not resolved.
If you pass your event source object as userData for Bind/Connect, then
during Unbind/Disconnect that infinite loop happens because of `delete
userData` call by wxWidgets.
Why not treat userData as void* and leave its ownership to user?
P.S. one might want to pass source object as userData, when using event
handler sink - in order to be able to refer to the aforementioned event
source object in that sink event handler. Is there any other better ways
of
doing it?
event.GetEventObject();
and it will give you the object that initiate this event.
Thank you.
Post by z***@gmail.com
Thanks,
Zura
Post by i***@gmail.com
Hi,
Most likely this issue is resolved in later version of wx.
Which version are working with?
Also what OS and compiler?
Sent from my HTC Inspire™ 4G on AT&T
----- Reply message -----
Subject: stack overflow in event disconnect?
Date: Tue, Jun 21, 2011 08:12
Well, it's working now strangely.
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainForm::OnBoneSetBoneClicked ), NULL, this
);
the differences...
1) the callback before specified a function on a derived class, now
it's
the base class.
2) i was passing the new checkbox as the userdata (2nd to last param),
now
i'm passing null as i realized i can still get the object that triggered the
event without sending it as user data.
not sure which of the 2 changes made it work but it's working now.
i think i'm using a fairly old version (1 year old +) as these are libs
i
built a while ago and just keep re-using.
If more info would be helpful let me know and i can isolate which thing
fixed it / get you the version number I'm using.
Post by Igor Korot
Hi,
Can you reproduce it in a sample?
What is your compiler, OS, wx version?
Did you build wx with the standard configuration options?
Thank you.
Post by Alan Wolfe
Hi!
I'm hitting an issue where when i disconnect an event I'm getting a stack
overflow.
The details are that i have a wxScrolledWindow (inside of a sizer which
is
inside of another sizer, which is inside of a panel which is.... etc).
Inside of that scrolled window I'm creating several wxCheckBoxes like
so...
("this" is my main wxFrame)
wxCheckBox *pNewCheckBox = new
wxCheckBox(m_scrolledWindow1,
wxID_ANY, pBone->m_sBoneName.c_str());
bSizer5->Add(pNewCheckBox, 0, wxALL, 5);
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ),
pNewCheckBox, this );
wxSizerItemList &rItemList = bSizer5->GetChildren();
for(wxSizerItemList::iterator it = rItemList.begin(); it !=
rItemList.end(); ++it)
{
wxCheckBox *pCB =
wxDynamicCast((*it)->GetWindow(),wxCheckBox);
if(pCB)
{
//TODO: why does this cause a stack overflow?
pCB->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ), pCB,
this
);
}
}
bSizer5->Clear(true);
The stack overflow happens in the Disconnect, but if I don't disconnect, it
happens in the Clear function at the end. The stack looks like below,
repeating all the way to the bottom where it says the max # of
frames
in
visual studio has been exceeded so i can't look any deeper.
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0xd bytes
C++
AnimSandbox.exe!wxEvtHandler::`vector deleting
destructor'() +
0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes
C++
AnimSandbox.exe!wxEvtHandler::`vector deleting
destructor'() +
0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes
C++
Anyone know what I might be doing wrong?
Thanks!
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
Igor Korot
2014-08-11 09:24:53 UTC
Permalink
Hi, Zura,

On Sun, Aug 10, 2014 at 11:01 PM, Zura Khetsuriani
Post by z***@gmail.com
Hi Igor,
event.GetEventObject() returns an object (pointer to it), which generates an
event, e.g. it can be some wxButton, wxComboBox, etc..
Are you saying that in this particular code snippet:

void Foo::Bar()
{
SomeDialog *dlg = new wxDialog();
dlg->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
&OtherClass::OtherMethod, otherClassObj, wxID_ANY, wxID_ANY, dlg);
dlg->ShowModal();
}

void OtherClass::OtherMethod(wxCommandEvent &event)
{
wxObject *obj = event.GetEventObject();
}

the "obj" pointer can be any class?

Please clarify you point.

Thank you.
Post by z***@gmail.com
Zura
Post by Igor Korot
Hi, Zura,
Post by z***@gmail.com
Hi Igor, Vadim
dlg->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &OtherClass::OtherMethod,
otherClassObj, wxID_ANY, wxID_ANY, dlg);
So here it is impossible to pass `dlg` pointer as the last argument. There
is also no elegant way of getting it (e.g. from wxCommandEvent object in the
handler).
void OtherClass::OtherMethod(wxCommandEvent &event)
{
// assuming that in the code above dlg is of the class wxDialog
wxDialog obj = event.GetEventObject();
}
Thank you.
Post by z***@gmail.com
So we have to fall back to some kind of workaround, as Vadim recommends.
Treating user data as void* is quite common and intuitive so please consider
addition of this variant in the future (Like you have SetClientData and
SetClientObject).
Thank you,
Zura
Post by Igor Korot
Hi, Zura,
Post by z***@gmail.com
Hi,
As of 2014, this issue is still not resolved.
If you pass your event source object as userData for Bind/Connect, then
during Unbind/Disconnect that infinite loop happens because of `delete
userData` call by wxWidgets.
Why not treat userData as void* and leave its ownership to user?
P.S. one might want to pass source object as userData, when using event
handler sink - in order to be able to refer to the aforementioned event
source object in that sink event handler. Is there any other better ways
of
doing it?
event.GetEventObject();
and it will give you the object that initiate this event.
Thank you.
Post by z***@gmail.com
Thanks,
Zura
Post by i***@gmail.com
Hi,
Most likely this issue is resolved in later version of wx.
Which version are working with?
Also what OS and compiler?
Sent from my HTC Inspire™ 4G on AT&T
----- Reply message -----
Subject: stack overflow in event disconnect?
Date: Tue, Jun 21, 2011 08:12
Well, it's working now strangely.
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainForm::OnBoneSetBoneClicked ), NULL, this
);
the differences...
1) the callback before specified a function on a derived class, now
it's
the base class.
2) i was passing the new checkbox as the userdata (2nd to last param), now
i'm passing null as i realized i can still get the object that triggered the
event without sending it as user data.
not sure which of the 2 changes made it work but it's working now.
i think i'm using a fairly old version (1 year old +) as these are libs
i
built a while ago and just keep re-using.
If more info would be helpful let me know and i can isolate which thing
fixed it / get you the version number I'm using.
Post by Igor Korot
Hi,
Can you reproduce it in a sample?
What is your compiler, OS, wx version?
Did you build wx with the standard configuration options?
Thank you.
Post by Alan Wolfe
Hi!
I'm hitting an issue where when i disconnect an event I'm getting a stack
overflow.
The details are that i have a wxScrolledWindow (inside of a sizer which
is
inside of another sizer, which is inside of a panel which is.... etc).
Inside of that scrolled window I'm creating several wxCheckBoxes like
so...
("this" is my main wxFrame)
wxCheckBox *pNewCheckBox = new
wxCheckBox(m_scrolledWindow1,
wxID_ANY, pBone->m_sBoneName.c_str());
bSizer5->Add(pNewCheckBox, 0, wxALL, 5);
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ),
pNewCheckBox, this );
wxSizerItemList &rItemList = bSizer5->GetChildren();
for(wxSizerItemList::iterator it = rItemList.begin(); it !=
rItemList.end(); ++it)
{
wxCheckBox *pCB =
wxDynamicCast((*it)->GetWindow(),wxCheckBox);
if(pCB)
{
//TODO: why does this cause a stack overflow?
pCB->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ), pCB,
this
);
}
}
bSizer5->Clear(true);
The stack overflow happens in the Disconnect, but if I don't disconnect, it
happens in the Clear function at the end. The stack looks like below,
repeating all the way to the bottom where it says the max # of
frames
in
visual studio has been exceeded so i can't look any deeper.
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0xd bytes
C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'()
+
0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes
C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'()
+
0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes
C++
Anyone know what I might be doing wrong?
Thanks!
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
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
Zura Khetsuriani
2014-08-11 11:01:41 UTC
Permalink
Yes, Igor,

You can connect several times, e.g.:

dlg->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &OtherClass::OtherMethod,
otherClassObj, wxID_ANY, wxID_ANY, dlg);

dlg->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED, &OtherClass::OtherMethod,
otherClassObj, wxID_ANY, wxID_ANY, dlg);

dlg->Bind(wxEVT_COMMAND_RADIOBUTTON_SELECTED, &OtherClass::OtherMethod,
otherClassObj, wxID_ANY, wxID_ANY, dlg);


and you have to dynamic cast (and check) event.GetEventObject() in your
event handler.

As for the original issue, I'm now passing:

new DialogWrapper(dlg)

As the last argument, so in fact now I'm using original behaviour
(delete userData) as a feature (for deleting DialogWrapper instance) ;)

The class itself:

// wraps wxDialog for passing as userData to Bind's. So that destructor
doesn't delete wxDialog
struct DialogWrapper: public wxObject {

DialogWrapper(wxDialog* dialog_): dialog(dialog_) {}

wxDialog* dialog;
};


Zura
Post by Igor Korot
Hi, Zura,
On Sun, Aug 10, 2014 at 11:01 PM, Zura Khetsuriani
Post by z***@gmail.com
Hi Igor,
event.GetEventObject() returns an object (pointer to it), which generates an
event, e.g. it can be some wxButton, wxComboBox, etc..
void Foo::Bar()
{
SomeDialog *dlg = new wxDialog();
dlg->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
&OtherClass::OtherMethod, otherClassObj, wxID_ANY, wxID_ANY, dlg);
dlg->ShowModal();
}
void OtherClass::OtherMethod(wxCommandEvent &event)
{
wxObject *obj = event.GetEventObject();
}
the "obj" pointer can be any class?
Please clarify you point.
Thank you.
Post by z***@gmail.com
Zura
Post by Igor Korot
Hi, Zura,
Post by z***@gmail.com
Hi Igor, Vadim
dlg->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &OtherClass::OtherMethod,
otherClassObj, wxID_ANY, wxID_ANY, dlg);
So here it is impossible to pass `dlg` pointer as the last argument. There
is also no elegant way of getting it (e.g. from wxCommandEvent object in the
handler).
void OtherClass::OtherMethod(wxCommandEvent &event)
{
// assuming that in the code above dlg is of the class wxDialog
wxDialog obj = event.GetEventObject();
}
Thank you.
Post by z***@gmail.com
So we have to fall back to some kind of workaround, as Vadim recommends.
Treating user data as void* is quite common and intuitive so please consider
addition of this variant in the future (Like you have SetClientData and
SetClientObject).
Thank you,
Zura
Post by Igor Korot
Hi, Zura,
Post by z***@gmail.com
Hi,
As of 2014, this issue is still not resolved.
If you pass your event source object as userData for Bind/Connect, then
during Unbind/Disconnect that infinite loop happens because of `delete
userData` call by wxWidgets.
Why not treat userData as void* and leave its ownership to user?
P.S. one might want to pass source object as userData, when using event
handler sink - in order to be able to refer to the aforementioned event
source object in that sink event handler. Is there any other better ways
of
doing it?
event.GetEventObject();
and it will give you the object that initiate this event.
Thank you.
Post by z***@gmail.com
Thanks,
Zura
Post by i***@gmail.com
Hi,
Most likely this issue is resolved in later version of wx.
Which version are working with?
Also what OS and compiler?
Sent from my HTC Inspire™ 4G on AT&T
----- Reply message -----
Subject: stack overflow in event disconnect?
Date: Tue, Jun 21, 2011 08:12
Well, it's working now strangely.
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainForm::OnBoneSetBoneClicked ), NULL, this
);
the differences...
1) the callback before specified a function on a derived class, now
it's
the base class.
2) i was passing the new checkbox as the userdata (2nd to last param), now
i'm passing null as i realized i can still get the object that triggered the
event without sending it as user data.
not sure which of the 2 changes made it work but it's working now.
i think i'm using a fairly old version (1 year old +) as these are libs
i
built a while ago and just keep re-using.
If more info would be helpful let me know and i can isolate which thing
fixed it / get you the version number I'm using.
Post by Igor Korot
Hi,
Can you reproduce it in a sample?
What is your compiler, OS, wx version?
Did you build wx with the standard configuration options?
Thank you.
Post by Alan Wolfe
Hi!
I'm hitting an issue where when i disconnect an event I'm getting a stack
overflow.
The details are that i have a wxScrolledWindow (inside of a sizer which
is
inside of another sizer, which is inside of a panel which is.... etc).
Inside of that scrolled window I'm creating several wxCheckBoxes like
so...
("this" is my main wxFrame)
wxCheckBox *pNewCheckBox = new
wxCheckBox(m_scrolledWindow1,
wxID_ANY, pBone->m_sBoneName.c_str());
bSizer5->Add(pNewCheckBox, 0, wxALL, 5);
pNewCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ),
pNewCheckBox, this );
wxSizerItemList &rItemList = bSizer5->GetChildren();
for(wxSizerItemList::iterator it = rItemList.begin(); it !=
rItemList.end(); ++it)
{
wxCheckBox *pCB =
wxDynamicCast((*it)->GetWindow(),wxCheckBox);
if(pCB)
{
//TODO: why does this cause a stack overflow?
pCB->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( wxASMainFormReal::OnBoneSetBoneClicked ), pCB,
this
);
}
}
bSizer5->Clear(true);
The stack overflow happens in the Disconnect, but if I don't disconnect, it
happens in the Clear function at the end. The stack looks like below,
repeating all the way to the bottom where it says the max # of
frames
in
visual studio has been exceeded so i can't look any deeper.
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0xd bytes
C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'()
+
0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes
C++
AnimSandbox.exe!wxEvtHandler::`vector deleting destructor'()
+
0x8
bytes C++
AnimSandbox.exe!wxEvtHandler::~wxEvtHandler() + 0x73 bytes
C++
Anyone know what I might be doing wrong?
Thanks!
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
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
Vadim Zeitlin
2014-08-11 11:37:23 UTC
Permalink
Post by z***@gmail.com
Hi Igor, Vadim
dlg->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &OtherClass::OtherMethod,
otherClassObj, wxID_ANY, wxID_ANY, dlg);
So here it is impossible to pass `dlg` pointer as the last argument.
Yes, but this is rarely needed and there is a trivial workaround, so IMHO
it's not a huge problem.

BTW, another possible fix is to just associate the dialog with
otherClassObj: if OtherMethod handles events for the dialog, it probably
needs the dialog itself anyhow, so just give it to it.
Post by z***@gmail.com
So we have to fall back to some kind of workaround, as Vadim recommends.
Treating user data as void* is quite common and intuitive so please
consider addition of this variant in the future (Like you have
SetClientData and SetClientObject).
The difference is that we already have several Bind() overloads and
duplicating them is really not an option.

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Vadim Zeitlin
2014-08-10 23:21:39 UTC
Permalink
Post by z***@gmail.com
As of 2014, this issue is still not resolved.
This might be due to the fact that there are no plans to resolve it.
Post by z***@gmail.com
If you pass your event source object as userData for Bind/Connect, then
during Unbind/Disconnect that infinite loop happens because of `delete
userData` call by wxWidgets.
Why not treat userData as void* and leave its ownership to user?
Because this would silently break existing code relying on the current
behaviour. If you don't want the object to be deleted, don't pass the
pointer to it, pass a pointer to some wrapper object which won't delete the
object when it is deleted itself. Potentially, it could be a shared_ptr<>
containing your object to ensure that it remains alive for as long as it's
needed but is still deleted at the end, but this is not at all the only
possibility.

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Loading...