Problem with exception when press button in form

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
Valerio
Knows some wx things
Knows some wx things
Posts: 42
Joined: Tue Apr 17, 2018 9:58 am

Problem with exception when press button in form

Post by Valerio »

Dear all,i'm Vale,i do project with wxwidget.Compile all ok.I use visual studio 17,version 15.7 preview 4.0.I do project with wxwidget,compile all ok.When press button in debug program go in exception :

void wxAppConsoleBase::CallEventHandler(wxEvtHandler *handler,
wxEventFunctor& functor,
wxEvent& event) const
{
// If the functor holds a method then, for backward compatibility, call
// HandleEvent():
wxEventFunction eventFunction = functor.GetEvtMethod();

if ( eventFunction )
HandleEvent(handler, eventFunction, event);
else
functor(handler, event);
}

Exception not managed in 0x00ED6EA1 in UnifiedHost2.exe: 0xC0000005: access violation when writing the path 0x00000004.

stop in exception for every button pressed.Which problem is?

Thanks.Best regards Vale
Valerio
Knows some wx things
Knows some wx things
Posts: 42
Joined: Tue Apr 17, 2018 9:58 am

Re: Problem with exception when press button in form

Post by Valerio »

This is window error
Attachments
Exception.JPG
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Problem with exception when press button in form

Post by PB »

You need to provide your relevant code, i.e., how you connect and handle the event.

The common cause of such errors is connecting the event with a wrong sink, you can find many examples of this on the forum, such as here
viewtopic.php?f=1&t=43868&p=179592#p179592
Valerio
Knows some wx things
Knows some wx things
Posts: 42
Joined: Tue Apr 17, 2018 9:58 am

Re: Problem with exception when press button in form

Post by Valerio »

Here my code for event button :

in file header :

void WxRecoverClick(wxCommandEvent& event);

in file cpp :

EVT_BUTTON(ID_WXRECOVER,UnifiedHost2Dlg::WxRecoverClick)
............

/*
* WxRecoverClick
*/
void UnifiedHost2Dlg::WxRecoverClick(wxCommandEvent& event)
{
event.GetId();
// char* c = GetComSync(); //debug
nProgramButtonId = COMMAND_RECOVER_PM;
Connect();
}

go in exception GetId().

Thanks

best regards

Vale
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Problem with exception when press button in form

Post by PB »

I cannot spot any obvious issue from in the code fragments you posted. I assume GUI is not accessed from secondary threads.

I remember you having some odd issues with building wxWidgets, have you verified that the samples (at least the minimal) run correctly in the same build your application is using?

Can you verify that if copy your project and use some simple code such as the one posted below instead in it, all works as expected?

Code: Select all

#include <wx/wx.h>

class MyFrame : public wxFrame
{
public:
    MyFrame() : wxFrame(NULL, wxID_ANY, _("A simple test"))
    {
        wxBoxSizer* bSizer = new wxBoxSizer(wxVERTICAL);

        wxButton* button = new wxButton(this, wxID_ANY, "Click me");
        bSizer->Add(button, 0, wxEXPAND | wxALL, 5);
        button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &MyFrame::OnButtonClicked, this);

        SetSizer(bSizer);
    }	
private:    
    void OnButtonClicked(wxCommandEvent&)
    {     
        wxLogMessage("Hello from %s", GetTitle());
    }
};

class MyApp : public wxApp
{
public:
    virtual bool OnInit()
    {     
        (new MyFrame())->Show();               
        return true;
    }
}; wxIMPLEMENT_APP(MyApp);
Valerio
Knows some wx things
Knows some wx things
Posts: 42
Joined: Tue Apr 17, 2018 9:58 am

Re: Problem with exception when press button in form

Post by Valerio »

I find line that cause exception,is Connect();
When i put in comment this function,press button and go ok,when insert this function,go exception.

void UnifiedHost2Dlg::WxGetIDClick(wxCommandEvent& event)
{
event.GetId();
// char* c = GetComSync(); //debug
nProgramButtonId = COMMAND_READ_ID;
//When put this line in comment button don't do in exception...
Connect();
}
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Problem with exception when press button in form

Post by PB »

Valerio wrote:I find line that cause exception,is Connect();
When i put in comment this function,press button and go ok,when insert this function,go exception.
But you said before the exception is raised when executing event.GetId()?

Anyway, if the exception is in the Connect() function, which AFAICT is not a part of wxWidgets, you need to look into it... I don't think anyone can help you with the amount of information you provide.
Post Reply