I had the whole plugin working previously as a very simple implementation with lots of global and static variables, i've now converted it to an object based design so I can instantiate multiple instances safely etc.
However, since I have done that, when creating an instance of the plugin it gets as far as the MyScriptableNPObject::NewObject() method, where it attempts to call createobject() but never returns and the browser crashes.
ScriptableNPObject* ScriptableNPObject::NewObject(NPP npp)
{
_DebugLog("ScriptableNPObject::NewObject");
ScriptableNPObject* newObj = (MyScriptableNPObject*)npnfuncs->createobject(npp, &_npclass);
_DebugLog("ScriptableNPObject::NewObject - end");
return newObj;
}
I've got some basic logging in there as a quick way of debugging this and I can see that this method is being called from getValue() as expected but the end log is never coming out, so something is obviously going wrong in createobject().
I have defined my own Allocate() method for my NPObject and the NPClass seems to be defined correctly as far as I can tell, these are as follows -
NPObject* ScriptableNPObject::_Allocate(NPP npp, NPClass *aClass)
{
return (NPObject *)new ScriptableNPObject(npp);
}
NPClass ScriptableNPObject::_npclass = {
NP_CLASS_STRUCT_VERSION,
ScriptableNPObject::_Allocate,
ScriptableNPObject::_Deallocate,
NULL,
ScriptableNPObject::_HasMethod,
ScriptableNPObject::_Invoke,
ScriptableNPObject::_InvokeDefault,
ScriptableNPObject::_HasProperty,
ScriptableNPObject::_GetProperty,
NULL,
NULL,
NULL,
ScriptableNPObject::_Construct,
};
The npnfuncs struct is also valid from what I can see. So i'm a bit stumped as to whats going wrong!
Any help would be greatly appreciated,
Thanks.
Check your npnfuncs pointer in a debugger; I bet there is a problem with it.
Barring that, get the mozilla source and build a debug version so that you can step through the code and see exactly where it is crashing. That's the easiest way to track down pointer issues like the one you describe.
Seriously, though, I second what Georg said (though I'm admittedly biased): Check out FireBreath, it'll save you a lot of troubleshooting as well as making it easier to port to IE if you ever want to.