Segfault on popup from a DrawingArea
- From: Christophe andral <christophe andral fr>
- To: gtkmm-list gnome org
- Subject: Segfault on popup from a DrawingArea
- Date: Thu, 28 Jan 2010 08:34:31 +0100
Hi gtkmm team, all,
First question : Can I attach a popup menu on Gtk::DrawingArea widget ?
(If not, following questions are not relevant ^_^')
Second (and longer) question :
I implement a popup menu based on the gtkmm example:
http://library.gnome.org/devel/gtkmm-tutorial/unstable/sec-menus-examples.html.en#menu-example-popup
The differences are :
- my implem is on a DrawingArea child type and not a Gtk::Window child
- ActionGroup and UIManager are not attribute of my class but only
local variable to construction
Here is my piece of code:
// Construct a popup menu
Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup =
Gtk::ActionGroup::create();
//File|New sub menu:
//These menu actions would normally already exist for a main menu, because a
//context menu should not normally contain menu items that are
only available
//via a context menu.
m_refActionGroup->add(Gtk::Action::create("ContextMenu", "Context Menu"));
m_refActionGroup->add(
Gtk::Action::create("ContextEdit", "Edit"),
sigc::mem_fun(*this, &PoutreSlotEditor::on_popup_generic));
m_refActionGroup->add(
Gtk::Action::create("ContextProcess", "Process"),
// Gtk::AccelKey("<control>P"), // Since we don't call add_accel_group
sigc::mem_fun(*this, &PoutreSlotEditor::on_popup_generic));
m_refActionGroup->add(
Gtk::Action::create("ContextRemove", "Remove"),
sigc::mem_fun(*this, &PoutreSlotEditor::on_popup_generic));
Glib::RefPtr<Gtk::UIManager> m_refUIManager = Gtk::UIManager::create();
m_refUIManager->insert_action_group(m_refActionGroup);
// It appears DrawingArea does not support add_accel_group
// but Is it important for my case
//add_accel_group(m_refUIManager->get_accel_group());
//Layout the actions in a menubar and toolbar:
Glib::ustring ui_info =
"<ui>"
" <popup name='PopupMenu'>"
" <menuitem action='ContextEdit'/>"
" <menuitem action='ContextProcess'/>"
" <menuitem action='ContextRemove'/>"
" </popup>"
"</ui>";
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Log::DEBUG("GLIBMM_EXCEPTIONS_ENABLED");
// It's the case for me
try
{
m_refUIManager->add_ui_from_string(ui_info);
}
catch(const Glib::Error& ex)
{
Log::ERROR("building menus failed:%s", ex.what().c_str());
}
#else
// Not my case
Log::DEBUG("GLIBMM_EXCEPTIONS_ NOT _ENABLED");
#endif
//Get the menu:
m_pMenuPopup =
dynamic_cast<Gtk::Menu*>(m_refUIManager->get_widget("/PopupMenu"));
if(!m_pMenuPopup)
Log::WARN("menu not found");
// This function does not exist on DrawingArea
// show_all_children();
// May this call equivalent in my case ?
m_pMenuPopup->show();
When I call the popup, I do the following (exactly what is said in the
example) :
if (event->button == 3 ) // Right button
{
if(m_pMenuPopup)
{
Log::DEBUG("Popup request");
m_pMenuPopup->popup(event->button, event->time);
}
}
And I return true later in the code.
I valgrind execution and here is the stack trace :
==5008== Invalid read of size 4
==5008== at 0x420A9E5: Gtk::Menu::popup(unsigned int, unsigned int)
(in /usr/lib/libgtkmm-2.4.so.1.1.0)
==5008== by 0x805667F:
Poutre::PoutreSlotEditor::on_button_press_event(_GdkEventButton*)
(PoutreSlotEdito
r.cc:299)
==5008== by 0x4294021:
Gtk::Widget_Class::button_press_event_callback(_GtkWidget*,
_GdkEventButton*) (in
/usr/lib/libgtkmm-2.4.so.1.1.0)
==5008== by 0x45E0473: ??? (in /usr/lib/libgtk-x11-2.0.so.0.1800.3)
==5008== by 0x4C036F8: ??? (in /usr/lib/libgobject-2.0.so.0.2200.3)
==5008== by 0x4C05071: g_closure_invoke (in
/usr/lib/libgobject-2.0.so.0.2200.3)
==5008== by 0x4C1A49D: ??? (in /usr/lib/libgobject-2.0.so.0.2200.3)
==5008== by 0x4C1B9B7: g_signal_emit_valist (in
/usr/lib/libgobject-2.0.so.0.2200.3)
==5008== by 0x4C1BFB5: g_signal_emit (in /usr/lib/libgobject-2.0.so.0.2200.3)
==5008== by 0x46FC95D: ??? (in /usr/lib/libgtk-x11-2.0.so.0.1800.3)
==5008== by 0x45D8C1F: gtk_propagate_event (in
/usr/lib/libgtk-x11-2.0.so.0.1800.3)
==5008== by 0x45D9EA8: gtk_main_do_event (in
/usr/lib/libgtk-x11-2.0.so.0.1800.3)
==5008== Address 0x76616b is not stack'd, malloc'd or (recently) free'd
What's wrong ? :(
Do I have to maintain instance of ActionGroup and UIManager in my class ?
Thank's in advance for your help,
Christophe
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]