-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Requiring jxcore addon from "embedded" C++ mechanism works on Mac but not on Windows #6
Comments
@csapoadam You require a native binary from an embedded app right? I believe the app is failing to locate reference binary for native addon. It's normal that this is only happening on Windows. On Windows, when you require a 'node' file, it tries to find the reference methods etc. from 'jx.exe' Could you fork JXcore embedded windows project and edit it to something that I can reproduce the problem? That would help a lot! |
Hi @obastemur , I forked that project and changed it to demonstrate the problem I am having on Win7 with the SM version. The sources can be found here: https://github.com/csapoadam/JXcoreWindowsEmbedded Thanks for your help. |
Hi, do you have any updates on this? Could you reproduce the problem? |
@csapoadam Thanks for the work there. I am working on it. |
It worked for me. What I did. 1 - compiled the jxcore-addon project |
Hi @obastemur , that's correct, with v8 it works fine. I just tried it on my windows computer. However, the issue was with the SpiderMonkey version. I tried this again now, with the most up-to-date sources, and the SM version still doesn't work. Actually, now (with the latest sources), even doing jx install to build the addon gives this error: c:\users\adam.node-gyp\jxb303\src\jx\proxy\Mozilla/JXString.h(57): error C2071 this seems to be a new error (or rather, a recurrence of an earlier error), because when I reverted to the sources from June 6 (the ones I used when starting this ticket), jx install worked fine, but then of course I still had the problem described above, with the invalid memory access. It's true that on Windows one can use V8 without a problem, but on some plaforms (like iOS), currently the only alternative is SpiderMonkey. That's why I tried it on Windows with SM, too, and I had these errors. I thought it might be important to investigate this. So I will use the V8 version for the time being, but I think there are still definitely some problems with SM. |
@csapoadam I thought you had the issue with V8. Gonna check with SM then. Thanks for the details |
Just tested and it also works for SM. Before compiling the solution, make sure you have the jx.lib from JXcore SM. |
I don't know what's wrong on my end then... :S Truth is though, I am using a 32-bit version of Windows, with VS2012. Other than that, I don't think I'm doing anything differently. With the very latest sources, the problem can't be with the VS solution (libs, etc.), because just doing 'jx install' in the main folder (in order to install the addon) fails with: With the older sources, installing the addon works fine... then I go on to build the embedded c++ application, which works fine... then I copy the executable to the main folder and try to run it, but I get this error: If it's not the same on your end, it could just be a problem with my configuration (win7 32-bit plus VS2012). |
32Bit. That's the problem :) I will try to install 32 bit Windows whenever possible. Thanks |
OK, I am installing 64-bit windows now to try this out. I will post an update in a few days. Thanks for your help. |
Hi @obastemur , it's working for me (somewhat), but actually it's not completely doing what it should. With the example I sent you, here is the code for the script: JXValue result; so, it should print: but it is printing only the first two lines, which means that the binding2 variable is never initialized correctly: This is with the V8 version on 64-bit Windows... |
Actually it should print 4 lines but I forgot to use process.requireGlobal instead of require in the second script. However, neither correcting that nor removing it from main.cpp helps. The bottom line is that addons do not seem to work in embedded applications on windows. |
I've just figured out why. @csapoadam it definitely doesn't work for Windows. Sample native app loads jx.dll. JX.dll loads binding.node. Binding.node requires jx.exe. As a result app crashes. It is v8 or SM independent and mostly because of how node native addon works.
Dynamic library loading on iOS is not allowed. If you give me some more details on what you are trying to achieve, I would like to help. |
Hi, thanks for that info. So it seems like with Mac, it's possible to do this but not on Windows? Is the fact that it worked on Mac a coincidence, or will this be possible in future versions, too? (I don't really know the details of how addons work). The reason why we wanted to do this (require addon from embedded code) was because we are looking to develop a cross-platform solution (win, osx, ios, android) that is capable of:
Do you see any possibility for doing this? Perhaps if we are loading binding.node from an embedded application, there would be no need to require jx.exe again (since jx.dll is already loaded?). |
It's not a coincidence. It works.
Yes sure. The problem with Windows may require some time taking internal tricks but doable.
This is the part that requires the time taking work on Windows. |
Sounds great, thanks! Once you have a roadmap, let me know what timeframe you see realistic for these modifications. |
Hi @obastemur , do you have any updates on this? Thanks! |
@csapoadam could not dig on this yet. If you have a chance to look into I can provide you some details |
Hi @obastemur , I've been thinking about this and would love to contribute, but unfortunately there are quite a few projects I have to get through now. Let's talk about this later, once we have more time. |
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.
The text was updated successfully, but these errors were encountered: