Search code examples
javascriptc++comfirebreath

Bad variant cast exception when converting a Javascript object to a JSAPIPtr


I am initialising a Javascript object and passing it to a registered API function whose signature is as follows::

I checked that the variant object coming from Javascript is not empty....

JS file

Initialize function called when I press a button...

 function Initialize() 
    {
        var Class=function(){this.member1_JS='Red'};
        BorderStyle.prototype.member2_JS='1';
        var obj=new Class();
        plugin().DoTheChanges(obj);

    }

=======================================================


Solution

  • It should be:

    _jsObjPtr= objectFromJavaScript.convert_cast<FB::JSObjectPtr>();
    

    Any object coming from javascript is a JSObjectPtr; if it's doing a convert_cast to JSAPIPtr it will try to find inside the JSObjectPtr a C++ JSAPI object that you have created (for example, a DicomAPI object) which won't actually work on most browsers because they hide it too deep to get back out.