Hi,

I want to use <nsCOMPtr> inside my plugin because NS_ADDREF and RELEASE is
managed.

My plugin instance holds an pointer to an interface which allows me
scripting my plugin. The browser ask the plugin for the scriptable interface
via NPP_GetValue(..., void* value). I return the instance of scriptpable
interface in void* followed:

*(nsISupports **)value = scriptablePeer;

When the browser loads the webdocument with inside the plugin, scripting is
ok it does what I want. But when I load a new other webdocument after some
seconds the browser crashes. I think it happens because the browser cleans
the memory and some went wrong.

This happens only when I use <nsCOMPtr>. When I use the conventional
programming style with NS_ADDREF all runs correct.

Here some of my code:

...
nsCOMPtr<nsIjs2plugin> scriptablePeer;
...
void PInstance::getScriptableInstance(void* value) {

  /* Sometimes the browser calls getScriptableInstace() more than once.
     Be sure that only one instance of scriptablePeer exits ! */
  if (!scriptablePeer)
   {
      /* We generate an instance of 'ns6xScriptablePeer' because
      this class implements the interface methods ! */
   scriptablePeer = new ns6xScriptablePeer(this);

      // It's generated we increase the refcnt !
     //  NS_ADDREF(scriptablePeer); // Not used, because it's a smartpointer
!!
   }

  if (scriptablePeer)
   {
  // ... told them the browser
  *(nsISupports **)value = scriptablePeer;

  // This is the second refrence to the instance
  // NS_ADDREF(scriptablePeer); // Not used, because it's a smartpointer !!
   }
  else
   value = NULL;
} // End, getScriptableInstance()


Causes the pointer conversion of void* value the crashes ?

Thanks ...



Reply via email to