Safari插件在NPN_GetValue上崩溃 [英] Safari plugin crashes on NPN_GetValue

查看:149
本文介绍了Safari插件在NPN_GetValue上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用NPN_GetValue时,我的插件代码崩溃.基本上,我创建了一个可脚本编写的对象,该对象具有一个"getDevice"方法,可以将设备数组返回给JavaScript.下面是代码段.

My plugin code crashes when I call the NPN_GetValue. Basically I created a scriptable object which has a 'getDevice' method that can return a device array to JavaScript. Below is the code snippet.

static bool mainNPObjectInvoke(NPObject *obj, NPIdentifier identifier, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
    printf("create main object");
    MainNPObject *mainObject = (MainNPObject *)obj;

    if (identifier == methodIdentifiers[METHOD_ID_GET_DEVICES])
    {
        NPObject *windowObj = NULL;
        browser->getvalue(mainObject->npp, NPNVWindowNPObject, &windowObj);
        // it crashed here
    ....
    }
}

我使用以下方法创建了MainNPObject实例.

I created the MainNPObject instance with below method.

NPObject *createMainNPObject(NPP npp)
{
    MainNPObject *object = (MainNPObject *)browser->createobject(npp, &mainNPClass);
    object->npp = npp;

    theMainObject = object;

    return (NPObject *)object;
}

在我提供给浏览器的插件函数中调用了createMainNPObject.

The createMainNPObject is called in the plugin function I provided to browser.

NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
{
    PluginObject *obj = instance->pdata;

    switch (variable) {
        case NPPVpluginCoreAnimationLayer:
            if (!obj->rootLayer)
                setupLayerHierarchy(obj);

            *(CALayer **)value = obj->rootLayer;

            return NPERR_NO_ERROR;

        case NPPVpluginScriptableNPObject:

            if (!obj->mainObject)
            {
                obj->mainObject = createMainNPObject(instance);
            }
 ....
}

分配函数如下.

static NPObject *mainNPObjectAllocate(NPP npp, NPClass *class)
{
    initializeIdentifiers();

    MainNPObject *mainObject = malloc(sizeof(MainNPObject));
    mainObject->deviceManager = [[DeviceManager alloc] init];

    return (NPObject *)mainObject;
}

MainNPObject的定义:

Definition of MainNPObject:

typedef struct
{
    NPObject *npobject;
    NPP npp;
    DeviceManager *deviceManager;
} MainNPObject;

通过调试代码,我发现系统在调用浏览器-> getValue时引发了EXC_BAD_ACCESS,看起来npp指针无效.

By debugging the code, I found that the system raised an EXC_BAD_ACCESS when calling the browser->getValue and it looks like the npp pointer is invalid.

0x00007fff83f82dab  <+0019>  je     0x7fff83f82db9 <_ZN6WebKit14NetscapePlugin7fromNPPEP4_NPP+33>
0x00007fff83f82dad  <+0021>  incl   0x8(%rax)

有人可以帮我吗?

谢谢!

推荐答案

Hmm;没有看到明显的东西.尝试在结构中添加另一个参数(int?),并在分配或紧接后置字中设置它,然后稍后再检查它是否仍然是您在调用getvalue之前设置的值.查看您的结构是否以某种方式损坏.当我以一种非显而易见的方式使NPObject变得有趣时,这发生在我身上.

Hmm; not seeing anything obvious. Try adding another parameter (an int?) to your structure and set it during allocate or immediately afterwords, then later on check to see if it's still the value you set before you call getvalue. See if your struct is somehow getting corrupt. That happened to me once when I was casting the NPObject funny in a non-obvious way.

这篇关于Safari插件在NPN_GetValue上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆