ui
ui copied to clipboard
Runtime error on window mouse move
V doctor
OS: linux, "Garuda Linux"
Processor: 16 cpus, 64bit, little endian, AMD Ryzen 7 3800X 8-Core Processor
CC version: cc (GCC) 12.2.1 20230201
getwd: /home/yuart
vmodules: /home/yuart/.vmodules
vroot: /home/yuart/Projects/v
vexe: /home/yuart/Projects/v/v
vexe mtime: 2023-03-01 21:46:21
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.3 d971d93.e2daa84
Git version: git version 2.39.2
Git vroot status: weekly.2023.08-45-ge2daa84a
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3
UI package version
cdf521649d41ab93fc645f0a398d94fecb587883
System DE
DE: KDE Plasma 5.27.2
WM: KWin (Wayland)
What did you do?
Run the following code with v run .
import ui
[heap]
struct App {
mut:
window ui.Window
label ui.Label
model Model
}
struct Model {
counter_value int
}
enum Message {
increment
decrement
}
fn main() {
mut app := App{}
setup_app(mut app)
ui.run(app.window)
}
fn setup_app(mut app App) {
app.window = ui.window(
width: 400
height: 400
title: 'MVU counter'
children: [
ui.column(
margin: ui.Margin{50, 50, 50, 50}
spacing: 5
children: [
app.label,
ui.row(
spacing: 5
children: [
ui.button(
text: 'Increment'
width: 100
height: 50
text_size: 20
on_click: app.send_increment_signal
),
ui.button(
text: 'Decrement'
width: 100
height: 50
text_size: 20
on_click: app.send_decrement_signal
),
]
),
]
),
]
)
app.label = ui.label(text: '0', text_size: 36)
}
fn (mut app App) send_increment_signal(_ &ui.Button) {
app.model = update(Message.increment, app.model)
app.react_on_model_change()
}
fn (mut app App) send_decrement_signal(_ &ui.Button) {
app.model = update(Message.decrement, app.model)
app.react_on_model_change()
}
fn update(message Message, current_model Model) Model {
return match message {
.increment {
Model{
counter_value: current_model.counter_value + 1
}
}
.decrement {
Model{
counter_value: current_model.counter_value - 1
}
}
}
}
fn (mut app App) react_on_model_change() {
app.label.text = app.model.counter_value.str()
}
The program started as expected and a window appeared.
What did you expect to see?
When moving the mouse cursor on windows - no crash.
What did you see instead
The app crashes immediately after the mouse cursor touches the window with the following error.
/tmp/v_1000/ui_counter.14357049844790996348.tmp.c:2121: at ui__Tooltip_update: RUNTIME ERROR: invalid memory access
/tmp/v_1000/ui_counter.14357049844790996348.tmp.c:64100: by ui__window_mouse_move
/tmp/v_1000/ui_counter.14357049844790996348.tmp.c:63913: by ui__on_event
/tmp/v_1000/ui_counter.14357049844790996348.tmp.c:45353: by gg__gg_event_fn
/home/yuart/Projects/v/thirdparty/sokol/sokol_app.h:2895: by _sapp_call_event
/home/yuart/Projects/v/thirdparty/sokol/sokol_app.h:11124: by _sapp_x11_mouse_event
/home/yuart/Projects/v/thirdparty/sokol/sokol_app.h:11551: by _sapp_x11_process_event
/home/yuart/Projects/v/thirdparty/sokol/sokol_app.h:11898: by _sapp_linux_run
/home/yuart/Projects/v/thirdparty/sokol/sokol_app.h:11953: by sapp_run
/tmp/v_1000/ui_counter.14357049844790996348.tmp.c:43754: by sokol__sapp__run
/tmp/v_1000/ui_counter.14357049844790996348.tmp.c:45542: by gg__Context_run
/tmp/v_1000/ui_counter.14357049844790996348.tmp.c:2228: by ui__run
/tmp/v_1000/ui_counter.14357049844790996348.tmp.c:8781: by main__main
/tmp/v_1000/ui_counter.14357049844790996348.tmp.c:9730: by main
Workaround - window filed in App struct must be &ui.Window, not ui.Window