diff --git a/vlib/v/live/common.c.v b/vlib/v/live/common.c.v index 186ef0be4e3c81..8275ead93868ff 100644 --- a/vlib/v/live/common.c.v +++ b/vlib/v/live/common.c.v @@ -48,19 +48,15 @@ pub mut: // live.info - give user access to program's LiveReloadInfo struct, // so that the user can set callbacks, read meta information, etc. pub fn info() &LiveReloadInfo { - if C.g_live_info != 0 { - return unsafe { &LiveReloadInfo(C.g_live_info) } + if C.g_live_info == 0 { + // When the current program is not compiled with -live, simply + // return a new empty struct LiveReloadInfo in order to prevent + // crashes. In this case, the background reloader thread is not + // started, and the structure LiveReloadInfo will not get updated. + // All its fields will be 0, but still safe to access. + unsafe { + C.g_live_info = int(&LiveReloadInfo{}) + } } - // When the current program is not compiled with -live, simply - // return a new empty struct LiveReloadInfo in order to prevent - // crashes. In this case, the background reloader thread is not - // started, and the structure LiveReloadInfo will not get updated. - // All its fields will be 0, but still safe to access. - mut x := &LiveReloadInfo{} - unsafe { - mut p := &u64(&C.g_live_info) - *p = u64(x) - _ = p - } - return x + return unsafe { &LiveReloadInfo(C.g_live_info) } }