Re: Why this code doesn't work?





Den 2015-12-22 kl. 01:36, skrev codekiddy:
Hey guys I solved all the issues and would like to share my findings!!

Recently I made several posts here on gtkmm-list having problems with GTKMM on Windows with msvc builds, so as if
#define GTKMM_ATKMM_ENABLED is defined during compilation there will be a runtime crash and
destruction problem with Glib::RefPtr<Pango::Layout> layout;

The problem was that I compiled ATKMM and PANGOMM with /vd2 compiler switch, and that was causing program shutdown crash in Atk::~Implementor and Layout::~Layout

I recompiled these 2 without the /vd2 option and with GTKMM_ATKMM_ENABLED 1, now everything works just fine :D


I copied a simple test program from stackoverflow to test dynamic_cast operator 


struct Base : 
virtual public Glib::Object
{
Base() :Object()
{
// upcast and downcast
Object* o = static_cast<Object*>(this);
Base*   b = dynamic_cast<Base*>(o);
std::cout << "  this: " << this << " after cast: " << b;
// should be the same address
if (this != b)
std::cout << " check address: NOK";
else
std::cout << " check address: OK ";
}
};

struct Derived : public Base
{
int i;
};

int main()
{
Derived d;
std::cout << " end arrived: ";
std::stringstream* ss = new std::stringstream;
delete ss;
std::cout << "OK";
std::cin.get();
return 0;
}


And here is a program output after running a test:

(test_dynamic_cast.exe:10464): GLib-GObject-CRITICAL **: g_object_set_qdata_full: assertion 'quark > 0' failed

  this: 0067F74C after cast: 0067F750 check address: NOK end arrived: OK

what do you think? is this output OK? obviously the cast was successful in the end, even though glib gives CRITICAL message in beginning.

There was no crash! :D YES!

You must initialize glibmm before you use Glib::Object or any other glibmm class. Add
    Glib::init();
at the beginning of main().
Gtk::Application::create() initializes both glibmm and gtkmm, so in most gtkmm programs you don't have to call any initialization function explicitly.

Kjell


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