views:

89

answers:

1

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.

+2  A: 

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.

Taxilian
Thanks again, yeah you were right about the npnfuncs pointer, I think i've fixed it by changing how I copy and store the structure although i'm stumped as to why it wasn't working to start with!As for Firebreath, I would have prefered to have used that and did try to first of all, but had problems integrating it into our build structure so unfortunately had to give up on that one.
Adam Cobb
sorry to hear that; it does take a bit of work sometimes to switch an existing build structure to use cmake, but without cmake it would be nearly impossible to attain the level of simplicity that FireBreath has. There are some different things you can do to simplify that sometimes, but of course the complexity of your project will weigh in there.
Taxilian
Dear Adam Cobb, can you please tell us how you fixed your problem?
Voulnet