sciter-sdk/rust-sciter

Sciter.JS - Segmentation fault

GirkovArpa opened this issue · 3 comments

I am trying to remake this project using Sciter.JS, and there are some problems I do not understand.

  1. In main.js, Window.this.rust.sum_async works as expected. But if this line:
document.set_title = function (text) {

Is changed to this:

function set_title(text) {

Then calling Window.this.rust.sum_async will crash the program with the following error:

process didn't exit successfully: `target\debug\sciter-js-rust-boilerplate.exe` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)
Segmentation fault

It is unclear to me how such a meaningless change could cause a crash in an apparently unrelated part of the program.

  1. Element.call_function does not seem to work as it does with vanilla Sciter. As seen on line 66 of main.rs, fn attached() is definitely called because it prints "attached", but the function set_title is not.

  2. This code seems excessively verbose. Apparently there is a better way:

Window.this.xcall("sum",1, 2);

But I don't know how to define sum on the Rust side.

Window.this.xcall throws these errors when debugging in VSCode:

Exception thrown at 0x00007FFF1244A388 in sciter-js-rust-boilerplate.exe: Microsoft C++ exception: qjs::om::type_error at memory location 0x000000C1D60FE358.
Exception thrown at 0x00007FFF1244A388 in sciter-js-rust-boilerplate.exe: Microsoft C++ exception: qjs::exception at memory location 0x000000C1D60FEA40.
ERROR:TIS: TypeError: unknown name 'sum'
ERROR:TIS:     at xcall (native)`

Workaround for being able to use Window.this.xcall in the meantime:

impl sciter::EventHandler for EventHandler {
  fn get_subscription(&mut self) -> Option<sciter::dom::event::EVENT_GROUPS> {
    Some(sciter::dom::event::default_events() | sciter::dom::event::EVENT_GROUPS::HANDLE_METHOD_CALL)
}