Closed trufae closed 1 year ago
Hey @trufae,
Can you provide a minimal example of the code you are using to create multiple windows? Please also system information, e.g. via v doctor
. Then it'll become a bit easier to look into the issue.
Sure, this is the source, crash and doctor:
0$ v run dos.v
signal 11: segmentation fault
0 libsystem_platform.dylib 0x0000000180e42a24 _sigtramp + 56
1 dos 0x00000001004d3df0 _ZN7webview6detail22cocoa_wkwebview_engine19create_app_delegateEv + 308
2 dos 0x00000001004d3df0 _ZN7webview6detail22cocoa_wkwebview_engine19create_app_delegateEv + 308
3 dos 0x00000001004d3894 _ZN7webview6detail22cocoa_wkwebview_engineC2EbPv + 104
4 dos 0x00000001004d3808 _ZN7webview7webviewC2EbPv + 72
5 dos 0x00000001004d25bc _ZN7webview7webviewC1EbPv + 56
6 dos 0x00000001004d24ec webview_create + 56
7 dos 0x000000010050a8fc webview__create + 64
8 dos 0x000000010050ac28 main__main + 56
9 dos 0x000000010050afa8 main + 84
10 dyld 0x0000000180abbf28 start + 2236
139$
5$ cat dos.v
import webview
fn main() {
w := webview.create()
w2 := webview.create()
w.run()
w2.run()
}
0$ v doctor
V full version: V 0.4.0 56644b2
OS: macos, macOS, 13.4.1, 22F82
Processor: 10 cpus, 64bit, little endian, Apple M1 Max
getwd: /Users/pancake/prg/v-test
vexe: /Users/pancake/prg/v/v
vexe mtime: 2023-08-18 09:00:46
vroot: OK, value: /Users/pancake/prg/v
VMODULES: OK, value: /Users/pancake/.vmodules
VTMP: OK, value: /tmp/v_501
Git version: git version 2.39.2 (Apple Git-143)
Git vroot status: weekly.2023.30-165-g56644b2b (2 commit(s) behind V master)
.git/config present: true
CC version: Apple clang version 14.0.3 (clang-1403.0.22.14.1)
thirdparty/tcc status: thirdparty-macos-arm64 a668e5a0
0$
When an existing window isn't passed to the C function webview_create
then it doesn't just create a new window, it also wants to take the responsibility of managing the application's lifecycle.
It's probably crashing when attempting to register the custom app delegate class a second time with the same class name.
I can reproduce the issue on macOS. No issues to spawn multiple windows on Linux or Windows.
With the lifecycle separation implemented in https://github.com/webview/webview/pull/1005 it's possible to spawn multiple windows.
Example:
import webview
const doc = '<button onclick="window.new_window();">New window</button>'
fn main() {
w := webview.create()
w.set_title('Primary Window')
w.set_size(480, 320, .@none)
w.set_html(doc)
w.bind('new_window', fn (e &webview.Event) voidptr {
e.dispatch(fn () {
w2 := webview.create()
w2.set_title('Secondary Window')
w2.set_size(480, 320, .@none)
w2.set_html('Secondary Window')
})
return webview.no_result
})
w.run()
}
If you run into errors despite having re-run the build.vsh
, you might need to clean your vmodules cache. E.g. by removing the .vmodules/cache
directory.
Awesome!
The program crashes when trying to create a secondary webview. So not sure if its possible or just a bug