Skip to content

Requiring jxcore addon from "embedded" C++ mechanism works on Mac but not on Windows #6

@csapoadam

Description

@csapoadam

I am trying to run embedded javascript code within a C++ program (like in the project here https://github.com/obastemur/JXcoreWindowsEmbedded ). This works fine on both Mac and Windows unless the code uses require to import a previously compiled jxcore addon - in which case it only works on Mac (but not Windows).

For example, if I have a .js file that has:

var binding = require('./build/Release/binding');
console.log("1 + 2 = " + binding.sum(1,2));

(where binding is the addon I created), and run this through the jx interpreter, then I have the desired result. But if in C++, I do:

std::stringstream ss;
ss << "console.log("Adding 1 and 2 together "); \n";
ss << "var binding0 = process.requireGlobal('./build/Release/testadd'); \n";
ss << "var binding1 = process.requireGlobal('./build/Release/binding'); \n";
ss << "console.log(binding1.sum(1,2)); \n";
JX_Evaluate(ss.str().c_str(), "myscript", &result);

I get an invalid memory access error during runtime. Note that testadd.js is a simple js script that adds the two numbers together without using the binding addon. Thus, the above example only fails when requiring the addon. If I require the addon in the separate script (for example, inside testadd.js), the code still fails. The error message is as follows:

Error: invalid access to memory location
c:\users\adam\desktop\development\maxwhere-tests\build\release\binding.node (nat
ive:jxcore_js_object 3:11)
at (native:jxcore_js_object:3:12)
at process.dlopen (node.js:638:17)
at Module.prototype.load (module.js:347:7)
at Module._load (module.js:314:5)
at Module.prototype.require (module.js:379:10)
at require (module.js:397:12)
at myscript:3:16

Do you know what causes this? I am using the SM version on Windows7 (compiled with VS2012). The same example works on Mac.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions