Skip to content

Program freezes with tcc and works with msvc #23793

@Xyndra

Description

@Xyndra

Describe the bug

I have a sdl app that runs on both, but if I try to log something (or println), it freezes on tcc.

Reproduction Steps

  1. paste this code (note that you need sdl 3 bindings)
module no_main

import sdl
import sdl.callbacks
import log

struct AppState {
mut:
	a_pressed bool
}

struct SDLApp {
	window_height int = 640
	window_width int = 480
mut:
	window   &sdl.Window   = unsafe { nil }
	renderer &sdl.Renderer = unsafe { nil }
	state AppState = AppState{}
}

fn init() {
	unbuffer_stdout()
	callbacks.on_init(app_init)
	callbacks.on_event(app_event)
	callbacks.on_iterate(app_iterate)
	callbacks.on_quit(app_quit)
}

@[export: 'v_sdl_app_init']
pub fn app_init(app_ptr &voidptr, _ int, _ &&char) sdl.AppResult {
	mut app := &SDLApp{}
	unsafe {
		*app_ptr = app
	}
	sdl.set_app_metadata(c'Snippy', c'0.01', c'de.xyndra.snippy')

	if !sdl.init(sdl.init_video) {
		error_msg := unsafe { cstring_to_vstring(sdl.get_error()) }
		eprintln("Couldn't initialize SDL: ${error_msg}")
		return .failure
	}

	if !sdl.create_window_and_renderer(c'Snippy', app.window_width, app.window_width,
		sdl.WindowFlags(0), &app.window, &app.renderer) {

		error_msg := unsafe { cstring_to_vstring(sdl.get_error()) }
		eprintln("Couldn't create window/renderer: ${error_msg}")
		return .failure
	}

	return .continue // carry on with the program!
}

@[export: 'v_sdl_app_event']
pub fn app_event(app_ptr voidptr, event &sdl.Event) sdl.AppResult {
	mut app := unsafe { &SDLApp(app_ptr) }
	match event.type {
		.quit {
			return .success // end the program, reporting success to the OS.
		}
		.key_down {
			keyboard_event := unsafe { &sdl.KeyboardEvent(event) }
			match unsafe { sdl.KeyCode(keyboard_event.key) } {
				.a {
					app.state.a_pressed = !app.state.a_pressed
				}
				else {}
			}
		}
		else {}
	}
	return .continue // carry on with the program!
}

@[export: 'v_sdl_app_iterate']
pub fn app_iterate(app_ptr voidptr) sdl.AppResult {
	return .continue // carry on with the program!
}

@[export: 'v_sdl_app_quit']
pub fn app_quit(app_ptr voidptr, _ sdl.AppResult) {
	mut app := unsafe { &SDLApp(app_ptr) }
	log.info("A was " + if app.state.a_pressed { "" } else { "not " } + "pressed.")
}
  1. see it work with v -cc msvc run .
  2. see it freeze on exiting the program with v -cc tcc run .

Expected Behavior

Both don't freeze

Current Behavior

TCC freezes during exiting and has to be terminated by the windows not responding dialog.

Possible Solution

No response

Additional Information/Context

I am using sdl 3.2.0 vlang bindings

V version

V 0.4.9 3c88926

Environment details (OS name and version, etc.)

V full version V 0.4.9 d0ce8a2.3c88926
OS windows, Microsoft Windows 11 Pro 22635 64-bit
Processor 8 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory 33.81GB/63.67GB
V executable D:\software\v\v.exe
V last modified time 2025-02-23 13:49:02
V home dir OK, value: D:\software\v
VMODULES OK, value: C:\Users\Sammy.vmodules
VTMP OK, value: C:\Users\Sammy\AppData\Local\Temp\v_0
Current working dir OK, value: D:\Code\v\snippy
Git version git version 2.48.1.windows.1
V git status weekly.2025.08-30-g3c88926f
.git/config present true
cc version N/A
gcc version gcc (MinGW.org GCC-6.3.0-1) 6.3.0
clang version clang version 19.1.7
msvc version N/A
tcc version tcc version 0.9.27 (x86_64 Windows)
tcc git status thirdparty-windows-amd64 b425ac82
emcc version emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.3 (a9651ff57165f5710bb09a5fe52590fd6ddb72df)
glibc version N/A

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.Compiler: TCCBugs/feature requests, that are related to compiling V programs with TCC.OS: WindowsBugs/feature requests, that are specific to Windows OS.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions