3

I am calling back an object in Javascript using NPAPI. Before this call, the functions I am calling result in proper invocation of functions in JavaScript but it fails in NPN_Invoke calls.

Code Snippet:

sBrowserFuncs->releaseobject(object_temp);
object_temp = NPVARIANT_TO_OBJECT(args[0]);
sBrowserFuncs->retainobject(object_temp);

if (send_msg1(sBrowserFuncs, instance, msg_rcv, NPVARIANT_TO_OBJECT(args[0]), msg, name_id))

sendmsg1 spawns a new thread and this thread calls msg_rcv back. Is it okay for spawned thread to call the main thread function, is that reason of error. ... Her call to NPN_Invoke is called

NPVariant from;

STRINGZ_TO_NPVARIANT(sdata->from, from);
NPIdentifier methodId = NPN_GetStringIdentifier("new_msg");
int res = NPN_Invoke(sdata->instance, object_temp, methodId, &from, 1, &result);

sdata->instance matches with instance object_temp is last called object stored

It returns 0, while in successful case it returns 1.

In which case NPN_Invoke generates 0,

jonsca
  • 10,218
  • 26
  • 54
  • 62
Janon
  • 31
  • 1

1 Answers1

2

As far as i know , any NPN_* call should be issued from the plugin thread. You can check NPN_PluginThreadAsyncCall. I this way you can execute methods from another thread , on the main/plugin thread and avoid a nasty crash :)

codingPear
  • 274
  • 1
  • 9
  • This is exactly right; however, bear in mind that PluginThreadAsyncCall on Mac as not always reliable, so you may need to use other workarounds depending on your platform. This is one of the reasons that the FireBreath (http://firebreath.org) framework is so popular, because it abstracts nearly all of the threading issues like this away from you. – taxilian Jul 03 '11 at 06:48