Glib::RefPtr and Pointer



Hello,

I noticed something that I don't understand with a RefPtr. This is my
situation:

- I've a class "Global" that is a Singleton

- I store the pointer to "IconBrowser" class in this singleton

  Global &global = Global::instance ();
  global.init (); // set all store pointers to NULL and other things
   
  m_iconScrolledWindow->add (m_iconBrowser);
  
  global.setIconBrowser (&m_iconBrowser); // stores my pointer

- This is IconBrowser:

class IconBrowser : public Gtk::IconView
{
  // code to setup m_refListModel correct...
  
  Glib::RefPtr<Gtk::ListStore> m_refListModel;
};

- Now I do this somewhere in a callback function:

  Global &global = Global::instance ();
  IconBrowser *ib = global.getIconBrowser ();
  
  // clear treeview after row changed
  ib->clear ();

  // call some other functions from IconBrowser without problems...

But now a function in IconBrowser try to access m_refListModel and my
application crash. I debugged into it and the problem is that
m_refListModel is NULL in that case. But if I stop before at the setup
of m_refListModel there is a real value for it.

Now the really interesting problem: If I copy the memory address of
m_refListModel from my debugger and paste it into m_refListModel before
accessing it from my callback function than it works.

So the question is: Could you imagine why my RefPtr lost his value if I
access it from within the callback?

If you need more code or info to help me, than please tell me.

regards
Andreas


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