emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

scanf prompt loops forever

Open ihip opened this issue 5 years ago • 11 comments

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

ihip avatar Aug 08 '19 15:08 ihip

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.

stale[bot] avatar Aug 07 '20 19:08 stale[bot]

bump; i just tried scanf and I have the same problem. this shouldn't be closed.

tom-dignan avatar Nov 10 '20 05:11 tom-dignan

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.

humphd avatar Sep 01 '21 13:09 humphd

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

VladRDV avatar Jan 20 '22 04:01 VladRDV

Same problem.

vtereshkov avatar May 07 '22 11:05 vtereshkov

I've got the same problem too.

vortigano avatar Apr 02 '23 01:04 vortigano

Oh bro, I have the same problem like you

cyk2018 avatar Apr 09 '24 07:04 cyk2018

Same issue

ShufflePerson avatar May 09 '24 14:05 ShufflePerson

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.

sbc100 avatar May 09 '24 15:05 sbc100

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.

cyk2018 avatar May 15 '24 02:05 cyk2018

@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 avatar May 15 '24 06:05 cyk2018

@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.

sbc100 avatar May 15 '24 15:05 sbc100

@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.

cyk2018 avatar May 15 '24 16:05 cyk2018