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

Hot reloading invalid memory access on Windows #23214

Open
CodeOptimist opened this issue Dec 19, 2024 · 5 comments
Open

Hot reloading invalid memory access on Windows #23214

CodeOptimist opened this issue Dec 19, 2024 · 5 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@CodeOptimist
Copy link

CodeOptimist commented Dec 19, 2024

Describe the bug

Hot reloading example seems to fail with RUNTIME ERROR: invalid memory access

Reproduction Steps

v -live run examples/hot_reload/message.v
on a fresh V installation; Windows 11

Current Behavior

PS C:\Dropbox\vlang\examples\hot_reload> v -live run message.v
OK reloads:    0 | Total reloads:    0 | Hello! Modify this message while the program is running.
Unhandled Exception 0xC0000005
C:/Users/Chris/AppData/Local/Temp/v_0/message.01JFGGEH73ZXN1SG5KJGJEW3G1.tmp.c:5222: at print_backtrace_skipping_top_frames_tcc: Backtrace
C:/Users/Chris/AppData/Local/Temp/v_0/message.01JFGGEH73ZXN1SG5KJGJEW3G1.tmp.c:5208: by print_backtrace_skipping_top_frames
C:/Users/Chris/AppData/Local/Temp/v_0/message.01JFGGEH73ZXN1SG5KJGJEW3G1.tmp.c:5778: by unhandled_exception_handler
7fffb76ded36 : by ???
C:/Users/Chris/AppData/Local/Temp/v_0/tmp.1.message.01JFGGEHKS30AVVRA0GZ9PPZJR.tmp.so.c:4996: at strconv__format_dec_sb: RUNTIME ERROR: invalid memory access
C:/Users/Chris/AppData/Local/Temp/v_0/tmp.1.message.01JFGGEHKS30AVVRA0GZ9PPZJR.tmp.so.c:12319: by StrIntpData_process_str_intp_data
C:/Users/Chris/AppData/Local/Temp/v_0/tmp.1.message.01JFGGEHKS30AVVRA0GZ9PPZJR.tmp.so.c:12721: by str_intp
C:/Users/Chris/AppData/Local/Temp/v_0/tmp.1.message.01JFGGEHKS30AVVRA0GZ9PPZJR.tmp.so.c:15383: by impl_live_main__print_message
C:/Users/Chris/AppData/Local/Temp/v_0/message.01JFGGEH73ZXN1SG5KJGJEW3G1.tmp.c:2883: by main__print_message
C:/Users/Chris/AppData/Local/Temp/v_0/message.01JFGGEH73ZXN1SG5KJGJEW3G1.tmp.c:9676: by main__main
C:/Users/Chris/AppData/Local/Temp/v_0/message.01JFGGEH73ZXN1SG5KJGJEW3G1.tmp.c:9795: by wmain
0044da88 : by ???
0044dbeb : by ???
7fffb63de8d7 : by ???
PS C:\Dropbox\vlang\examples\hot_reload>

Additional Information/Context

I was able to run other examples without hot reloading fine, like examples/gg/polygons.v.

V version

V 0.4.8 30ececc

Environment details (OS name and version, etc.)

V full version: V 0.4.8 30ececc
OS: windows, Microsoft Windows 11 Pro v26100 64-bit
Processor: 24 cpus, 64bit, little endian,

getwd: C:\Dropbox\vlang\examples\hot_reload
vexe: C:\Dropbox\vlang\v.exe
vexe mtime: 2024-12-19 21:25:10

vroot: OK, value: C:\Dropbox\vlang
VMODULES: OK, value: C:\Users\Chris.vmodules
VTMP: OK, value: C:\Users\Chris\AppData\Local\Temp\v_0

Git version: git version 2.45.1.windows.1
Git vroot status: weekly.2024.51-23-g30ececc2
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.

emcc version: Error: 'emcc' is not recognized as an internal or external command,
operable program or batch file.

thirdparty/tcc status: thirdparty-windows-amd64 b425ac82

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@CodeOptimist CodeOptimist added the Bug This tag is applied to issues which reports bugs. label Dec 19, 2024
@kbkpbot
Copy link
Contributor

kbkpbot commented Dec 20, 2024

I think it maybe a TCC compiler bug, because I use msvc can run the program:

v -live -cc msvc run examples\hot_reload\message.v
OK reloads:    0 | Total reloads:    0 | Hello! Modify this message while the program is running.
OK reloads:    0 | Total reloads:    0 | Hello! Modify this message while the program is running.
OK reloads:    0 | Total reloads:    0 | Hello! Modify this message while the program is running.
OK reloads:    0 | Total reloads:    0 | Hello! Modify this message while the program is running.
OK reloads:    0 | Total reloads:    0 | Hello! Modify this message while the program is running.
OK reloads:    0 | Total reloads:    0 | Hello! Modify this message while the program is running.
OK reloads:    0 | Total reloads:    0 | Hello! Modify this message while the program is running.
OK reloads:    0 | Total reloads:    0 | Hello! Modify this message while the program is running.
OK reloads:    0 | Total reloads:    0 | Hello! Modify this message while the program is running.
OK reloads:    0 | Total reloads:    0 | Hello! Modify this message while the program is running.
OK reloads:    0 | Total reloads:    0 | Hello! Modify this message while the program is running.
OK reloads:    0 | Total reloads:    0 | Hello! Modify this message while the program is running.

@CodeOptimist
Copy link
Author

CodeOptimist commented Dec 20, 2024

Apparently I'm a little blind, thanks @JalonSolov for pointing out that there are open issues on this. 😅
It looks like @KevinDaSilvaS already discovered the solution a cold-reloading alternative in #16256

Succeeds:
v watch run message.v
Fails:
v -live run message.v

So this might be a documentation issue. I'll change the title and/or submit a fix for this myself shortly.

@CodeOptimist
Copy link
Author

CodeOptimist commented Dec 20, 2024

I believe I figured it out; I'll leave the history of my stupidity here for posterity. 😅
Edit: Nope, this is all wrong, watch is helpful but it's not hot reloading.

v -live run is not related to watching,
it's just compile for live (to watch separately?), and run.

v watch will continually watch/rebuild (I think), and v watch run will continually watch/rebuild/rerun.


investigation

I had found vwatch.v created in 2021 c698fa1
I saw v -live run in docs.md in 2022 43d6b97

Grepping for (\blive\b.*?\brun\b|\brun\b.*?\blive\b) (whole-words "live" and "run" in either order) I found -live run mentioned in just doc/docs.md and vlib/v/gen/c/consts_and_globals.v.

I saw -live run mentioned in a couple of commit messages: 48d4228 and e9fac05

Noting that those commit messages were by the author of vwatch.v themselves and thus unlikely to be a mistake, my brain finally kicked-in and I recognized -live run as its own thing not related to watching (they aren't a pair, just separate things).

run is simply an option of the separate program watch just like it's an option of the compiler.

// Implements `v watch file.v` , `v watch run file.v` etc.


So I think the docs need updated. I need a break for now!
Though perhaps v -live run crashing still needs sorted somehow? A suggestion to run it with watch run instead??? 🤔

@KevinDaSilvaS
Copy link

Awesome investigation work!

@CodeOptimist
Copy link
Author

CodeOptimist commented Dec 24, 2024

I was wrong. I finally finished reading all of the V documentation today, and it's very plain that the program should continue running. (The @[live] functions go in a shared library, recompiled and reloaded via a separate thread.)
https://docs.vlang.io/other-v-features.html#hot-code-reloading

So I guess it's just broken.
Using watch is a workaround... but more like "cold" reloading than "hot" reloading.

@kbkpbot is probably right

I think it maybe a TCC compiler bug, because I use msvc can run the program

So I will try msvc. If it's indeed tcc I can retitle this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

3 participants