[bug] App silent crash if using textbox
V doctor:
OS: windows, Microsoft Windows 10 Home v19044 64 bit
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
CC version: Error: exec failed (CreateProcess) with code 2: Impossibile trovare il file specificato.
cmd: cc --version
getwd: C:\Users\Giorgio\DEV\v\ui_test
vmodules: C:\Users\Giorgio\.vmodules
vroot: C:\Users\Giorgio\v
vexe: C:\Users\Giorgio\v\v.exe
vexe mtime: 2022-09-21 16:00:50
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.1 993802f
Git version: git version 2.37.3.windows.1
Git vroot status: Error: fatal: detected dubious ownership in repository at 'C:/Users/Giorgio/v'
'C:/Users/Giorgio/v' is owned by:
'S-1-5-32-544'
but the current user is:
'S-1-5-21-3810202797-4041029411-129394997-1001'
To add an exception for this directory, call:
git config --global --add safe.directory C:/Users/Giorgio/v
.git/config present: true
thirdparty/tcc: N/A
What did you do?
v run . and also v . && <app>.exe
import ui
const (
win_width = 450
win_height = 120
)
[heap]
struct App {
mut:
window &ui.Window = unsafe { nil }
title_box_text string
}
fn main() {
mut app := &App{}
app.window = ui.window(
width: win_width
height: win_height
title: 'Name'
children: [
ui.column(
spacing: 20
margin: ui.Margin{30, 30, 30, 30}
// uncomment if you don't set the width of the button
// widths: [ui.stretch,150]
children: [
ui.row(
spacing: 10
alignment: .center
children: [
ui.label(text: 'Title name: '),
ui.textbox(
max_len: 20
width: 300
placeholder: 'Please enter new title name'
text: &app.title_box_text
is_focused: true
),
]
),
ui.button(text: 'Change title', on_click: app.btn_change_title, width: 150),
]
),
]
)
ui.run(app.window)
}
fn (mut app App) btn_change_title(btn &ui.Button) {
app.window.set_title(app.title_box_text)
}
What did you expect to see?
I expected application didn't close just after started running (displaying window).
What did you see instead?
Application closes just after showing the window, making the program not usable.
C:/Users/Giorgio/AppData/Local/Temp/v_0/ui_example.4546725332393050560.tmp.c:23264: at print_backtrace_skipping_top_frames_tcc: Backtrace
C:/Users/Giorgio/AppData/Local/Temp/v_0/ui_example.4546725332393050560.tmp.c:23231: by print_backtrace_skipping_top_frames
C:/Users/Giorgio/AppData/Local/Temp/v_0/ui_example.4546725332393050560.tmp.c:23289: by unhandled_exception_handler
7ff8bdd08a8c : by ???
7ff8bdba43d7 : at ???: RUNTIME ERROR: invalid memory access
C:/Users/Giorgio/AppData/Local/Temp/v_0/ui_example.4546725332393050560.tmp.c:54405: by ui__Stack_draw_device
C:/Users/Giorgio/AppData/Local/Temp/v_0/ui_example.4546725332393050560.tmp.c:54405: by ui__Stack_draw_device
C:/Users/Giorgio/AppData/Local/Temp/v_0/ui_example.4546725332393050560.tmp.c:54378: by ui__Stack_draw
C:/Users/Giorgio/AppData/Local/Temp/v_0/ui_example.4546725332393050560.tmp.c:55032: by ui__frame
C:/Users/Giorgio/AppData/Local/Temp/v_0/ui_example.4546725332393050560.tmp.c:40305: by gg__gg_frame_fn
C:/Users/Giorgio/v/thirdparty/sokol/sokol_app.h:2629: by _sapp_call_frame
C:/Users/Giorgio/v/thirdparty/sokol/sokol_app.h:2832: by _sapp_frame
C:/Users/Giorgio/v/thirdparty/sokol/sokol_app.h:7197: by _sapp_win32_run
C:/Users/Giorgio/v/thirdparty/sokol/sokol_app.h:11232: by sapp_run
C:/Users/Giorgio/AppData/Local/Temp/v_0/ui_example.4546725332393050560.tmp.c:38851: by sokol__sapp__run
C:/Users/Giorgio/AppData/Local/Temp/v_0/ui_example.4546725332393050560.tmp.c:40540: by gg__Context_run
C:/Users/Giorgio/AppData/Local/Temp/v_0/ui_example.4546725332393050560.tmp.c:58690: by ui__run
C:/Users/Giorgio/AppData/Local/Temp/v_0/ui_example.4546725332393050560.tmp.c:64734: by main__main
C:/Users/Giorgio/AppData/Local/Temp/v_0/ui_example.4546725332393050560.tmp.c:88: by wWinMain
006e2887 : by ???
006e29e8 : by ???
7ff8bca87034 : by ???
P.S.: I'm not a V expert (I'm just learning it and the UI library) and I cannot say if this code it's bad, but it should run because it's the example here.
I have no clue what you are trying to do with "&ui.Window = unsafe { nil }" but it looks wrong and probably the reason your code doesn't work. Start with simpler examples that you can easily understand and the rest should come naturally.
@xandro0777 thanks for your answer. I looked for some other examples and found how to start properly.
Anyway, I found where is the bug: the usage of a textbox causes app crash without any error (at compile time and running).
For example, this simple code won't run on my machine because of the textbox (commenting it will run successfully):
import ui
[heap]
struct App {
mut:
text string
}
fn main() {
mut app := App{}
c := ui.column(
widths: ui.stretch
margin_: 5
spacing: 10
children: [
ui.textbox(
max_len: 20
width: 300
placeholder: 'Text here'
text: &app.text
is_focused: true
),
ui.button(text: 'Alert Textbox Output', on_click: app.btn_click, width: 150),
]
)
w := ui.window(
width: 450
height: 120
title: 'Textbox Bug'
children: [c]
)
ui.run(w)
}
fn (mut app App) btn_click(b voidptr) {
ui.message_box('Output: $app.text')
}
Same bug of #444.
Bug workaround with https://github.com/vlang/ui/issues/444#issuecomment-1193042155