Re: Glib errors while deleting Gtk::ComboBoxEntryText. help needed



This example code produces the same Glib errors in my machine.

/**************************************/
/* CODE START                                              */
/**************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <gtkmm.h>

class MyPanel : public Gtk::HBox
{
	public:
		static MyPanel *Create();
		void Release();

	private:
		MyPanel();
		~MyPanel();
	
		void OnComboChanged();
		
		Gtk::Label *				label;
		Gtk::ComboBoxEntryText *	combo;
};

MyPanel::MyPanel() : Gtk::HBox()
{
	label = new Gtk::Label("select one:");
	combo = new Gtk::ComboBoxEntryText();
}

MyPanel::~MyPanel()
{
	if (combo)
	{
		delete combo;
		combo = NULL;
	}
	
	if (label)
	{
		delete label;
		label = NULL;
	}	
}

void MyPanel::OnComboChanged()
{
	Release();
}

MyPanel *MyPanel::Create()
{
	int retVal = 0;
	MyPanel *mypanel = NULL;
	
	try
	{
		mypanel = new MyPanel();
	}
	catch(...)
	{
		retVal = 1;
	}

	if (!retVal)
	{
		mypanel -> combo -> append_text("green");
		mypanel -> combo -> append_text("blue");
		mypanel -> combo -> append_text("white");

		mypanel -> combo -> get_entry() ->
signal_changed().connect(sigc::mem_fun(mypanel, &MyPanel::OnComboChanged));
	}
	
	if (!retVal)
	{
		mypanel -> pack_start(*(mypanel -> label), false, false, 2);
		mypanel -> pack_start(*(mypanel -> combo), true, true, 2);
		
		mypanel -> show_all();
	}
	
	if (!retVal)
	{
		return mypanel;
	}
	else
	{
		if (mypanel != NULL)
		{
			mypanel -> Release();
			mypanel = NULL;
		}
		return NULL;
	}
}

void MyPanel::Release()
{
	delete this;
}

int main(int argc, char *argv[])
{
	Gtk::Main kit(argc, argv);

	int retVal = 0;
	Gtk::Window *window = NULL;
	
	try
	{
		window = new Gtk::Window();		
	}
	catch(...)
	{
		retVal = 1;
	}
	
	if (!retVal)
	{
		MyPanel *panel = MyPanel::Create();
		if (panel == NULL)
		{
			retVal = 1;
		}
		else
		{
			window -> add(*panel);
		}
	}

	if (!retVal)
	{
		Gtk::Main::run(*window);					
	}
	
	if (window != NULL)
	{
		delete window;
		window = NULL;
	}
	
	return retVal;
}

/**************************************/
/* CODE END                                                 */
/**************************************/

No errors where reported by valgrind:

==2838== Memcheck, a memory error detector.
==2838== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==2838== Using LibVEX rev 1854, a library for dynamic binary translation.
==2838== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==2838== Using valgrind-3.3.1-Debian, a dynamic binary instrumentation
framework.
==2838== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==2838== For more details, rerun with: -v
==2838== 

(test:2838): GLib-GObject-WARNING **: instance with invalid (NULL) class
pointer

(test:2838): GLib-GObject-CRITICAL **: g_signal_handlers_unblock_matched:
assertion `G_TYPE_CHECK_INSTANCE (instance)' failed

(test:2838): GLib-GObject-CRITICAL **: g_object_notify: assertion
`G_IS_OBJECT (object)' failed

I hope this helps.



Murray Cumming wrote:
> 
> On Fri, 2010-01-15 at 14:18 -0800, siagogam wrote:
>> I'm still curious about this Glib errors but, as with the new approach
>> no
>> errors appeared, my priority now is continue with my development. Of
>> course,
>> I can give more feedback about the error or perform any specific test
>> if
>> suggested. 
> 
> Valgrind's memcheck might give some clue.
> 
> Otherwise, you need to reduce it to a simple test case.
> 
> -- 
> murrayc murrayc com
> www.murrayc.com
> www.openismus.com
> 
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
> 
> 

-- 
View this message in context: http://old.nabble.com/Glib-errors-while-deleting-Gtk%3A%3AComboBoxEntryText.-help-needed-tp27168573p27193452.html
Sent from the Gtkmm mailing list archive at Nabble.com.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]