Chrome inspector enabled!
And React-UMG is open sourced! GitHub - ncsoft/React-UMG: A React renderer for Unreal Motion Graphics With Unreal.js
Unreal.JS is always crashing in cooked build.
@nako_sung, sorry to bother you again, but I tried working around this for a couple of days now, but no matter what I do, it always happens.
Here is what I do with custom BP GameInstance (although I tried doing purely on C++ side, then with custom actor and JavaScript component, it’s always the same result):
Here is what I get when exiting the game:
Here is what log says:
LogPlayLevel: ColonyShipGame: [2016.12.13-17.54.25:690][316]LogWindows:Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffff
LogPlayLevel: ColonyShipGame: [2016.12.13-17.54.25:690][316]LogWindows:Error: LogWindows:Error: ColonyShipGame.exe!UObjectBaseUtility::IsTemplate()
LogPlayLevel: ColonyShipGame: [2016.12.13-17.54.25:690][316]LogWindows:Error: ColonyShipGame.exe!UObjectBaseUtility::IsTemplate()
LogWindows:Error: ColonyShipGame.exe!UJavascriptIsolate::~UJavascriptIsolate() [c:\work\epic games\projects\colonyshipgame\plugins\unrealjs\source\v8\private\v8implementation.cpp:44]
LogPlayLevel: ColonyShipGame: [2016.12.13-17.54.25:690][316]LogWindows:Error: ColonyShipGame.exe!UJavascriptIsolate::~UJavascriptIsolate() [c:\work\epic games\projects\colonyshipgame\plugins\unrealjs\source\v8\private\v8implementation.cpp:44]
LogWindows:Error: ColonyShipGame.exe!UJavascriptIsolate::`scalar deleting destructor'()
LogPlayLevel: ColonyShipGame: [2016.12.13-17.54.25:690][316]LogWindows:Error: ColonyShipGame.exe!UJavascriptIsolate::`scalar deleting destructor'()
LogWindows:Error: ColonyShipGame.exe!IncrementalPurgeGarbage()
LogPlayLevel: ColonyShipGame: [2016.12.13-17.54.25:690][316]LogWindows:Error: ColonyShipGame.exe!IncrementalPurgeGarbage()
LogWindows:Error: ColonyShipGame.exe!StaticExit()
...
Having moved the plugin to project’s folder and after adding a breakpoint to ~UJavascriptIsolate(), I can see that the destructor is called twice, which is a reason for the crash. But why does that happen, and why it doesn’t happen in PIE is a mystery to me. Perhaps you have an idea.
Destructor being called during GC doesn’t seem normal to me. What about removing all js code and leave empty? If that solves your problem, there must be some GC leakage within your js logic.
@nako_sung, nope, as I have no JS logic except “5 > 3” passed into RunScript node (belonging to JavascriptContext). This is definitely an issue with plugin’s RunScript node and cooked builds - it makes the game crash even with empty project.
Repro steps:
- Create empty project (doesn’t matter if C++ and BP), no starter content;
- Open Level Blueprint and recreate this simple structure:
- Press “Launch” to make cooked build. When it runs, you’ll see “true” on screen as a confirmation that “5 > 3” script was evaluated;
- Close the window and you’ll get a crash.
…
I thought it could be related to wrong parenting, i.e. “Outer” node being linked to level blueprint or game instance parent, but it’s not the case. If you do the same with an actor with JavascriptComponent, it still crashes. The only modification you’d have to do is make JavascriptContext field of UJavascriptComponent blueprint-accessible to gain access to RunScript node from component:
UPROPERTY(transient, **BlueprintReadOnly**)
UJavascriptContext* JavascriptContext;
But again, you don’t have to do this and the crash is reproducible with unmodified plugin, following repro steps above.
@Flashback Thanks! I just updated to replace destructor with BeginDestroy. Commits · ncsoft/Unreal.js-core · GitHub
Nice! I can confirm the crash is gone
UMG in action! https://github.com/ncsoft/Unreal.js-demo
Is there a way to call Javascript functions directly from Blueprints?
Function call needs proper function signature which describes types of arguments and return value, so I decided not to support direct call to JS land from BP. Actually you can execute arbitrary ‘string -> string’ function by calling Context.RunScript(“some thing”).
Sad. A combination of Blueprint and JavaScript I would have found useful. If I have to write the whole thing in JavaScript, I can write it in C++ just as well.
What would I have to do, to implement calls to JavaScript from Blueprint? Maybe the signature could be defined with JavaScript decorators or Blueprint parameters.
@Banbury As I mentioned earlier, you can call JS function from BP like below:
in JS
global.your_js_fn = (args) => {
let …args] = JSON.parse(args)
function your_org_js_fn(x,y,z) {
return x + y * z
}
return JSON.stringify(your_org_js_fn(…args))
}
In your BP
str = FormatString(“{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}]”, your-X, your-Y, your-Z, None, None, None, None, None, …)
str_result = Context.RunScript(“your_js_fn”,str)
int_result = ToInteger(str_result)
This is quite a slow code-path but it still does its job.
I’ll try that on the weekend.
But your examples always take so much for granted. I don’t like to write documentation, either. But I’m trying to piece together how unreal.js works for over a week now, without getting anywhere.
But my original question still stands. Is there a way to implement proper Blueprint support and how difficult would it be?
Oh I forgot there was FJavascriptFunction which takes UStruct as its function signature for C++ -> JS calls. Though it doesn’t support return type.
https://github.com/ncsoft/Unreal.js-core/blob/74b13d69fac2ea029c05173c371ff3d8249435c9/Source/V8/Public/JavascriptIsolate.h#L47
There is an example of custom thunk for taking arbitrary struct type as its argument(https://github.com/EpicGames/UnrealEngine/blob/e528f9f7fa161504dd629c3b390deac93650e43a/Engine/Plugins/Experimental/StructBox/Source/StructBox/Classes/StructBoxLibrary.h#L55), so I think it is possible to extend FJavascriptFunction to support fast BP -> JS calls.
Update -
I have updated UJavascriptLibrary::CallJS in https://github.com/ncsoft/Unreal.js-core/commit/06d2cae23bb9ce018d1791e495ca3100c7550338. Currently there can be a crash during destroying FJavascriptFunction property after V8 shutdown.
I’ve got the “Run Script” command to work, after I called “Run File” first. Otherwise the function isn’t defined. Speed isn’t an issue for me right now, so this should work for me.
Is there a reason, why the Javascript Component has no “Run Script” function? Or a “Get Context”?
And now there is no way to store the context in a variable. Could you expose UJavascriptContext to Blueprint? And I don’t see a reason to not expose JavascriptContext in UJavascriptComponent.
JavascriptComponent has link to JavascriptContext in its outer, so you can retrieve JavascriptContext by calling GetOuter of JavascriptComponent.
CallJS looks like a great addition!
Any chance you update the plugin on marketplace soon, so both this and “RunScript crash” fix appear in official build too, not only in Github HEAD version?
greate work!!!
But if I want use it in the work .
iOS will be support in the future ?
I guess now, when UE 4.15 is out and plugin is not compatible anymore, the update is imminent =)