Re: [GtkGLExt] GtkGLExt in a Mozilla plug-in



Hi Braden,

The issue here is really that the conventional way of registering a
new type is fundamentally incorrect since it fails under your
situation. The conventional code for registering a new user defined
type is the following,

GType
user_defined_class_get_type (void)
{
  static GType type = 0;

  if (!type)
    {
      /** fill in a GTypeInfo structure and register it with the type system **/
      static const GTypeInfo type_info = {
        sizeof (user_defined_class),
        (GBaseInitFunc) NULL,
        (GBaseFinalizeFunc) NULL,
        (GClassInitFunc) user_defined_class_init,
        (GClassFinalizeFunc) NULL,
        NULL,                   /* class_data */
        sizeof (user_defined_class),
        0,                      /* n_preallocs */
        (GInstanceInitFunc) NULL
      };

      type = g_type_register_static (G_TYPE_OBJECT,
                                     "UserDefinedClass",
                                     &type_info, 0);
    }

  return type;
}

The above method of checking whether a type has already been
registered or not using a 'static' variable is not going to work
across dynamic module load --> unload --> reload cycles. Everytime the
dynamic module is loaded (or reloaded), the 'static' variable 'type'
will be initialised to 0 even though the typename had already been
registerred with the central GObject type system in a previous
instance. Since that GObject dynamic module may not have been unloaded
yet, the type is still valid! This is the story in your case I think
since Mozilla loads GObject itself and keeps it loaded for its
lifetime. But your plugin is loaded --> unloaded --> reloaded, so
GtkGLExt using the above code will fail.

I think the code should really be the following,

GType
user_defined_class_get_type (void)
{
  static GType type = 0;

  if (!g_type_from_name("UserDefinedClass"))
    {
      /** fill in a GTypeInfo structure and register it with the type system **/
      static const GTypeInfo type_info = {
        sizeof (user_defined_class),
        (GBaseInitFunc) NULL,
        (GBaseFinalizeFunc) NULL,
        (GClassInitFunc) user_defined_class_init,
        (GClassFinalizeFunc) NULL,
        NULL,                   /* class_data */
        sizeof (user_defined_class),
        0,                      /* n_preallocs */
        (GInstanceInitFunc) NULL
      };

      type = g_type_register_static (G_TYPE_OBJECT,
                                     "UserDefinedClass",
                                     &type_info, 0);
    }

  return type;
}

Now we're just dynamically determining whether a given typename has
already been registered or not. The call to g_type_from_name(...)
function will return a 0 if the type has not been registered yet. It
will also work across dynamic module load --> unload --> reload cycles
since it is a query to the central GObject dynamic module, which is
separate from GtkGLExt module.

So finaly to answer your question, GtkGLExt is not currently designed
to be used in your situation. However, it can be modified quite easily
I think. So may I have some feedback please from an astute
"code-disector" regarding the validity of the above method I've just
highlighted.

Regards,

Alif.

-- 
"Heaven is the peaceful place on earth...New Zealand."
     -- Alif Wahid.



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