Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error on window mouse move #509

Open
ArtemkaKun opened this issue Mar 2, 2023 · 1 comment
Open

Runtime error on window mouse move #509

ArtemkaKun opened this issue Mar 2, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@ArtemkaKun
Copy link
Contributor

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

cdf5216

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
@ArtemkaKun ArtemkaKun added the bug Something isn't working label Mar 2, 2023
@ArtemkaKun
Copy link
Contributor Author

Workaround - window filed in App struct must be &ui.Window, not ui.Window

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant