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

OS.read_string_from_stdin() switches contexts when running without console wrapper from a console. #86813

Closed
Braxtogoo opened this issue Jan 5, 2024 · 4 comments · Fixed by #86903

Comments

@Braxtogoo
Copy link

Tested versions

Reproducible in: v4.2.1.stable.official [b09f793]

System information

Godot v4.2.1.stable - Windows 10.0.19045 - Vulkan (Mobile) - dedicated NVIDIA GeForce RTX 3060 (NVIDIA; 31.0.15.3742) - AMD Ryzen 9 5900X 12-Core Processor (24 Threads)

Issue description

When trying to use OS.read_string_from_stdin() if the application is not launched from the console wrapper produced with debug enabled it switches between giving input back to the running console and the game. This is likely a Windows specific issue but I don't have other platforms to test on at the moment.

It doesn't matter if the game is headless or not. It also doesn't matter if OS.read_string_from_stdin() is in a separate thread.

image

Steps to reproduce

-Make an empty scene, set it as main.
-Attach a script that calls OS.read_string_from_stdin() at least more than once.
-Build game.
-Run game directly from console (not the console wrapper)
-Try to enter input a few times.

Minimal reproduction project (MRP)

(How to see the error.)
-Open project.
-Build project with "Export With Debug" checked.
-Run the project from the console with: "Read Console Error.exe"
-Enter the command 'hi' a few times to see the context switch back and forth

Run the project from the console with "Read Console Error.console.exe" to see that the console wrapper makes the issue go away.

Read_Console_Error.zip

@akien-mga
Copy link
Member

CC @bruvzg

@bruvzg
Copy link
Member

bruvzg commented Jan 5, 2024

This is one of the reason console wrapper exist, if you are running an app without it, you should not expect any console IO to work at all. If you want a single executable with console support, use a custom build with windows_subsystem=console flag.

@Braxtogoo
Copy link
Author

That makes sense, perhaps this info and/or an example of using the windows_subsytem=console flag could be added to the docs of OS.read_string_from_stdin() for those like me trying to make a stand alone headless server on Windows? Without coming here and reading this issue I would have no idea what else I could do besides using the debug console wrapper.

At the very least it would be nice to see this issue noted somewhere as I almost missed it and it took me a while to figure out why it wasn't happening when I first started using OS.read_string_from_stdin().

@Braxtogoo
Copy link
Author

Also, I can confirm this issue doesn't seem to happen on headless Linux so far, using debug or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants