Problem with mouse events

Craig Deady cdeady at systems-shop.com
Thu Oct 5 06:57:26 PDT 2006


Julian,

The code crashes at the printf in the UserSelect routine. The printf is 
the only line of code and is there to show the problem. When the code 
tries to access the variable vUserLevel which is a wxTextCtrl object, 
the program seg faults. The object is initialized in the constructor 
before the event occurs. The other routine "OnStartrefClick" accesses 
the same variable without causing a seg fault.

The variable is initialized in the constructor, here is the code:
    vUserLevel = new wxTextCtrl(this, wxID_ANY, wxEmptyString, 
wxPoint(x+7,y+22),
                                                        wxSize(150, 30), 
wxTE_READONLY);                                                        
               
    vUserLevel->Connect(wxEVT_LEFT_DOWN, 
wxMouseEventHandler(MainPanel::UserSelect));

Here is the stack trace:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1208326448 (LWP 3257)]
0x08063b29 in MainPanel::UserSelect (this=0x97f72e0, event=@0xbfa90a34)
    at ../GuiMain.cpp:535
535             printf("UserLevel = %s\n",vUserLevel->GetValue().c_str());
(gdb) bt
#0  0x08063b29 in MainPanel::UserSelect (this=0x97f72e0, event=@0xbfa90a34)
    at ../GuiMain.cpp:535
#1  0x081a6873 in wxAppConsole::HandleEvent (this=0x9708fb8,
    handler=0x97f72e0, func=
      {__pfn = 0x8063ac0 <MainPanel::UserSelect(wxMouseEvent&)>, __delta 
= 0},
    event=@0xbfa90a34) at 
/usr/lib/wxWidgets-2.6.3/src/common/appbase.cpp:324
#2  0x0820f2f2 in wxEvtHandler::ProcessEventIfMatches (entry=@0x97fa3a0,
    handler=0x97f72e0, event=@0xbfa90a34)
    at /usr/lib/wxWidgets-2.6.3/src/common/event.cpp:1193
#3  0x0820f707 in wxEvtHandler::SearchDynamicEventTable (this=0x97f72e0,
    event=@0xbfa90a34) at /usr/lib/wxWidgets-2.6.3/src/common/event.cpp:1371
#4  0x08210c03 in wxEvtHandler::ProcessEvent (this=0x97f72e0,
    event=@0xbfa90a34) at /usr/lib/wxWidgets-2.6.3/src/common/event.cpp:1251
#5  0x080adfe1 in gtk_window_button_press_callback (widget=0x9753228,
    gdk_event=0x97235e0, win=0x97f72e0)
    at /usr/lib/wxWidgets-2.6.3/src/gtk/window.cpp:1850
#6  0x4411658e in gtk_marshal_BOOLEAN__VOID ()
   from /usr/lib/libgtk-x11-2.0.so.0
#7  0x43e04f8b in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#8  0x43e15e3d in g_signal_override_class_closure ()
   from /usr/lib/libgobject-2.0.so.0
#9  0x43e1710f in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#10 0x43e17509 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#11 0x44201858 in gtk_widget_get_default_style ()
   from /usr/lib/libgtk-x11-2.0.so.0
#12 0x4410ff63 in gtk_propagate_event () from /usr/lib/libgtk-x11-2.0.so.0
#13 0x441111b7 in gtk_main_do_event () from /usr/lib/libgtk-x11-2.0.so.0
#14 0x43fa785a in gdk_add_client_message_filter ()
   from /usr/lib/libgdk-x11-2.0.so.0
#15 0x43d8d15d in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#16 0x43d903ef in g_main_context_check () from /usr/lib/libglib-2.0.so.0
#17 0x43d90799 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#18 0x44111634 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
#19 0x0812ca81 in wxEventLoop::Run (this=0x9828a68)
    at /usr/lib/wxWidgets-2.6.3/src/gtk/evtloop.cpp:80
#20 0x080d25c6 in wxAppBase::MainLoop (this=0x9708fb8)
    at /usr/lib/wxWidgets-2.6.3/src/common/appcmn.cpp:272
#21 0x080d2121 in wxAppBase::OnRun (this=0x9708fb8)
    at /usr/lib/wxWidgets-2.6.3/src/common/appcmn.cpp:340
#22 0x081d482a in wxEntry (argc=@0xbfa91220, argv=0xbfa912a4)
    at /usr/lib/wxWidgets-2.6.3/src/common/init.cpp:439
#23 0x08061030 in main (argc=Cannot access memory at address 0x1
) at ../GuiMain.cpp:114
(gdb)

Thanks for your help,
Craig

Iulian-Nicu Serbanoiu wrote:
> what part of the code crashes/where ?
>
> a stack trace in gdb would be good.
>
> try removing the printf. check if the objects are initialized ( 
> vUserLevel not initialized for example could be the cause of the crash ).
>
> HTH,
>
> Iulian
>
>
> On 10/4/06, *Craig Deady* <cdeady at systems-shop.com 
> <mailto:cdeady at systems-shop.com>> wrote:
>
>     I have the following two sample code fragments. The first code
>     fragment
>     works fine, the second one causes a Segmentation fault. The only
>     difference is that the second responds to a mouse down event on a
>     wxTextCtrl object and the first is a clicked event on a button.
>     Any ideas why I am getting the Segmentation fault?
>     Linux 2.6 (Fedora Core 5) & wxWidgets 2.6.3
>
>     Thanks,
>     Craig
>
>     void MainPanel::OnStartrefClick( wxCommandEvent& event )
>     {
>         printf("UserLevel = %s\n",vUserLevel->GetValue().c_str());
>
>     event.Skip();
>     }
>
>
>     void MainPanel::UserSelect(wxMouseEvent& event)
>     {
>         printf("UserLevel = %s\n",vUserLevel->GetValue().c_str());
>
>         event.Skip();
>     }
>
>     --
>     Craig Deady
>
>

-- 
Craig Deady
cdeady at systems-shop.com

C & D Systems
118 England Rd.
Rochester, NH 03867-4616 USA
Tel: +1 603-330-3939
Fax: +1 603-330-0556
www.systems-shop.com






More information about the wx-users mailing list