SnosMe/uiohook-napi

An error is reported when exiting the electron application

lmk123 opened this issue · 1 comments

macOS: 12.3.1 arm64
Electron: 18.2.0

I generated the prebuild on my own macOS arm64 computer and then tried to use it in my electron project in the main process, and when I quit the application, electron reported the following error:

FATAL ERROR: uiohook_to_js_event napi_define_properties
 1: 0x111e2e09c node::FatalException(v8::Isolate*, v8::TryCatch const&) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 2: 0x111e2e21c node::OnFatalError(char const*, char const*) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 3: 0x111e2e0b4 node::OnFatalError(char const*, char const*) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 4: 0x111de76d4 napi_open_callback_scope [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 5: 0x10bee9e90 tsfn_to_js_proxy [/Users/myproject/node_modules/uiohook-napi/prebuilds/darwin-arm64/node.napi.node]
 6: 0x10bee9ecc tsfn_to_js_proxy [/Users/myproject/node_modules/uiohook-napi/prebuilds/darwin-arm64/node.napi.node]
 7: 0x111de9f58 node_api_get_module_file_name [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 8: 0x10c4202dc uv_async_send [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 9: 0x10c4310d0 uv_free_interface_addresses [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
10: 0x10c4206f0 uv_run [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
11: 0x111dceffc node::EmitAsyncDestroy(node::Environment*, node::async_context) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
12: 0x111dcf330 node::EmitAsyncDestroy(node::Environment*, node::async_context) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
13: 0x111d9d274 node::FreeEnvironment(node::Environment*) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
14: 0x10c506210 heap::base::Stack::SetStackStart(void const*) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
15: 0x10c4f2820 v8::internal::compiler::RawMachineAssembler::TargetParameter() [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
16: 0x10dfc86c0 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
17: 0x10dfc9d4c v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
18: 0x10dfc61ac v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
19: 0x10c6a7bbc v8::internal::compiler::BasicBlock::set_loop_header(v8::internal::compiler::BasicBlock*) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
20: 0x10c6a8bdc v8::internal::compiler::BasicBlock::set_loop_header(v8::internal::compiler::BasicBlock*) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
21: 0x10c6a8778 v8::internal::compiler::BasicBlock::set_loop_header(v8::internal::compiler::BasicBlock*) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
22: 0x10c6a7280 v8::internal::compiler::BasicBlock::set_loop_header(v8::internal::compiler::BasicBlock*) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
23: 0x10c6a774c v8::internal::compiler::BasicBlock::set_loop_header(v8::internal::compiler::BasicBlock*) [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
24: 0x10c431688 ElectronMain [/Users/myproject/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
25: 0x10488d088 
/Users/myproject/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron exited with signal SIGABRT

iohook also has this problem, but I can fix it by uninstalling .node before exiting the app:

app.on('will-quit', () => {
  iohook.unload()
})

This problem can probably be solved by upgrading libuiohook to the latest version.

I tried to upgrade libuiohook to the latest version and then I don't have this problem. The steps I used were as follows:

git clone https://github.com/SnosMe/uiohook-napi.git
cd uiohook-napi/libuiohook
git branch --set-upstream-to=origin/1.2 master
git pull
cd ..
yarn
yarn prebuild
cp -r prebuilds/drawin-arm64 ../myproject/node_modules/uiohook-napi/prebuilds

But I'm not familiar with Node.js native addons and I don't know how to write C/C++ code, so I'm not sure if this upgrade will cause other problems (for example, I noticed that you should have modified the libuiohook code with libuiohook.patch), so I'd like you to upgrade the version of libuiohook, thanks!