emscripten
emscripten copied to clipboard
scanf prompt loops forever
To illustrate the problem with scanf I prepared simple demo at
https://ihip.github.io/WASM/scanf/scanf.html
Prompt loops forever so one has to click button Cancel (both on Chrome and Firefox) or check box "Prevent this page from creating additional dialogs" (Firefox).
I propose simple solution: I added (by hand, using editor) just one flag (called scanflag) in scanf-hip.js (https://github.com/ihip/WASM/blob/master/scanf/scanf-hip.js) - it is easy to find where by using CTRL-F (altogether scanflag appears 3 times) and achieved the normal behavior of scanf which can be seen by starting the same little demo at
https://ihip.github.io/WASM/scanf/scanf-hip.html
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.
bump; i just tried scanf and I have the same problem. this shouldn't be closed.
I ran into this today as well. Setting the "prevent this window from showing this dialog again" toggle in the prompt window made it work.
Same problem here. Browser prompt just keeps showing up untill I press it's cancel button, at least it actualy uses only input from the very first prompt in that cascade
Same problem.
I've got the same problem too.
Oh bro, I have the same problem like you
Same issue
scanf is hard / impossible to implement on the web in a generic way since there is no general notion of stdin.
emscripten tries to do a very hacky thing which is pop up and input dialog using windows.prompt
: https://github.com/emscripten-core/emscripten/blob/619f08d9498f417eae94deab129f3e97df8995eb/src/library_fs_shared.js#L152-L165
It seems like this is almost never what folks actually want so perhaps we should just delete that code path since is seems to be causing confusion.
scanf is hard / impossible to implement on the web in a generic way since there is no general notion of stdin.
emscripten tries to do a very hacky thing which is pop up and input dialog using
windows.prompt
:https://github.com/emscripten-core/emscripten/blob/619f08d9498f417eae94deab129f3e97df8995eb/src/library_fs_shared.js#L152-L165
It seems like this is almost never what folks actually want so perhaps we should just delete that code path since is seems to be causing confusion.
maybe we can add some support like macro in C code. or we can support default implemention with "<input>" if we can deal with this loop forever problem. but this is a big work.
@sbc100 sorry for interrupt. I found this problem alive because we only set the maximum of length such as 1024 in my environment. So this is not loop forever but loop until get 1024 chars. here is the core code: https://github.com/emscripten-core/emscripten/blob/2bc5e3156f07e603bc4f3580cf84c038ea99b2df/src/library_fs.js#L1592-L1605 so if I add a break code when I get "\n" or ascii(10) and I break this for loop, so this problem fixed. And this is my patch.
@cyk2018, but in practice are you actually going to use the windows.prompt
thing to do input for your program. It seems unlikely that anyone would actually want that.
@cyk2018, but in practice are you actually going to use the
windows.prompt
thing to do input for your program. It seems unlikely that anyone would actually want that.
Yes, so maybe we can not support this situation because we don't know what users want. But I can write some libs to support I/O. And Thanks for your reply.