Attached is a simple test case which explains what the problem is. The
ending of Clutter::main() does not remove actors from the stage.
stage->remove_actor(object) has to be called explicitly for the
reference count of object to be decremented properly. I would consider
this a bug taking into account how dynamic instantiation can be in C++.

-Bartek

#include <cluttermm.h>
#include <iostream>
#include <string>

class CustomTexture : public Clutter::Texture {
public:
	CustomTexture(const std::string _name) : Clutter::Texture::Texture() {
		name = _name;
		std::cout << "CustomTexture ctor: " << name << std::endl;
	}

	~CustomTexture() {
		std::cout << "CustomTexture dtor: " << name << std::endl;
	}

	static Glib::RefPtr<CustomTexture>
	create(const std::string _name) { return (Glib::RefPtr<CustomTexture>) new CustomTexture(_name); }

private:
	std::string name;
};

int main(int argc, char** argv) {
	try
	{
		Clutter::init(&argc,&argv);

		Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();

		stage->set_size(640,480);
		stage->set_color(Clutter::Color(0,0,0));

		Glib::RefPtr<CustomTexture> cust_text1 = CustomTexture::create("cust_text1");
		Glib::RefPtr<CustomTexture> cust_text2 = CustomTexture::create("cust_text2");

		stage->add_actor( cust_text1 );
		stage->add_actor( cust_text2 );

		stage->show();

		Clutter::main();

		stage->remove_actor( cust_text1 );

		/* make sure cust_text2 is finalized */
		if( cust_text2 ) {
			std::cout << "unreffing cust_text2\n";
			cust_text2.reset();
		}
	}
	catch(const Glib::Error& error)
	{
		std::cerr << "Exception: " << error.what() << std::endl;
		return 1;
	}
	return 0;
}

Reply via email to