The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: Yona-TYT on November 30, 2022, 07:10:26 PM

Title: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Yona-TYT on November 30, 2022, 07:10:26 PM

I think I mentioned this bug before, but now I've confirmed it.

Unfortunately it is not easy to reproduce and I only get it in the tutorial.

What happens is the following:
When I use the tunnel tool under specific conditions in the "is_work_allowed_here" function, for some reason in some cases the condition will fail causing an infinite loop "possibly in the tool" and this generates an infinite execution of "is_work_allowed_here".

Once it occurs there is no way to escape this, even if you reload the scenario's savegame, the infinite loop continues there.

It's strange isn't it? This has me baffled. :o
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Dwachs on November 30, 2022, 07:13:17 PM
Then please send the savegame (and the scenario). If it is reproducible it can be fixed. hopefully.
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Yona-TYT on November 30, 2022, 08:05:33 PM
The text label indicates the number of times "is_work_allowed_here" is executed.

Look at this video:



Quote from: Dwachs on November 30, 2022, 07:13:17 PMThen please send the savegame (and the scenario). If it is reproducible it can be fixed. hopefully.
This is the new tutorial scenario I'm working on for pak192.comic (this bug forces me to reveal it early hehehehe). ;D

scenario: tutorial-pak192.comic-test.zip

savegame: tutorial-33333test.sve
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Dwachs on December 03, 2022, 12:31:20 PM
should be fixed in r10825
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Yona-TYT on December 03, 2022, 08:24:57 PM
Quote from: Dwachs on December 03, 2022, 12:31:20 PMshould be fixed in r10825

Now I'm getting a crash on simutrans.  :o

Thread 1 "simutrans" received signal SIGSEGV, Segmentation fault.
0x0000555555a6e3bc in SQVM::Remove(long long) ()
(gdb) where
#0  0x0000555555a6e3bc in SQVM::Remove(long long) ()
#1  0x0000555555952c5f in script_vm_t::intern_prepare_call(SQVM*&, script_vm_t::call_type_t, char const*) ()
#2  0x00005555556a22d3 in scenario_t::is_work_allowed_here(player_t const*, unsigned short, short, koord3d) ()
#3  0x0000555555a2554b in karte_t::interactive(unsigned int) ()
#4  0x000055555598fffd in simu_main(int, char**) ()
#5  0x0000555555997445 in sysmain(int, char**) ()
#6  0x00007ffff7554290 in __libc_start_call_main (
    main=main@entry=0x55555563c490 <main>, argc=argc@entry=1,
    argv=argv@entry=0x7fffffffe818)
    at ../sysdeps/nptl/libc_start_call_main.h:58
#7  0x00007ffff755434a in __libc_start_main_impl (main=0x55555563c490 <main>,
    argc=1, argv=0x7fffffffe818, init=<optimized out>, fini=<optimized out>,
    rtld_fini=<optimized out>, stack_end=0x7fffffffe808)
    at ../csu/libc-start.c:381
#8  0x000055555563c55e in _start ()
(gdb)
Captura desde 2022-12-03 16-22-00.png
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Dwachs on December 03, 2022, 09:22:23 PM
Quote from: Yona-TYT on December 03, 2022, 08:24:57 PMNow I'm getting a crash on simutrans.  :o

How?
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Yona-TYT on December 03, 2022, 09:27:36 PM
Quote from: Dwachs on December 03, 2022, 09:22:23 PMHow?
hahahaha translation error, I meant something like " simutrans it shock". ;D

Quote from: Yona-TYT on December 03, 2022, 08:24:57 PMNow I'm getting a crash on simutrans.  :o
The firefox translator tells me "Now I'm ruining Simutrans". lol
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Dwachs on December 03, 2022, 10:13:12 PM
The problem is the gui.add_message call from is_work_allowed. The script gets suspended, which should not happen, and causes a squirrel stack overflow.

Edit: there is a bug in the script.cc code. Please do not call gui.add_message (or any tool/command) from is_work_allowed. This will cause the crash, when dragging the tunnel tool into forbidden regions. Not sure how to properly fix this.
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Dwachs on December 04, 2022, 09:58:19 AM
The crash should be fixed in r10829. Next step would be to enable gui.add_message for such function calls.
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Yona-TYT on December 05, 2022, 04:51:37 AM
Quote from: Dwachs on December 03, 2022, 10:13:12 PMThe problem is the gui.add_message call from is_work_allowed. The script gets suspended, which should not happen, and causes a squirrel stack overflow.
Edit: there is a bug in the script.cc code. Please do not call gui.add_message (or any tool/command) from is_work_allowed. This will cause the crash, when dragging the tunnel tool into forbidden regions. Not sure how to properly fix this.
I didn't know what to call there that was causing so much trouble. :P

Quote from: Dwachs on December 04, 2022, 09:58:19 AMThe crash should be fixed in r10829. Next step would be to enable gui.add_message for such function calls.
The truth is that even simutrans fails if I call gui there . :o
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Dwachs on December 05, 2022, 06:56:09 AM
Can you be more specific? Do you still get that crash with r10829?
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Yona-TYT on December 05, 2022, 11:42:55 AM
Quote from: Dwachs on December 05, 2022, 06:56:09 AMCan you be more specific? Do you still get that crash with r10829?
Yes, the r10829 is failing, use the scenario and the savegame that I shared in the other post.
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Dwachs on December 05, 2022, 05:56:52 PM
I do not get any crashes. What should I do to get the tutorial to crash simutrans?
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Yona-TYT on December 05, 2022, 08:01:01 PM
Quote from: Dwachs on December 05, 2022, 05:56:52 PMI do not get any crashes. What should I do to get the tutorial to crash simutrans?
Wait a minute, r10829 hasn't made it to github yet...  I did the tests with , r10828
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Yona-TYT on December 06, 2022, 05:14:04 AM
Look at this video: https://youtu.be/mQ4DboU5Pjk

The script code is:
function is_work_allowed_here(pl, tool_id, pos)
{
gui.add_message("hello")
return null
}


Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Dwachs on December 06, 2022, 05:19:01 PM
This should be fixed with r10829, which is at github since two days ago. With with revision did you record the video?
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Yona-TYT on December 06, 2022, 05:59:20 PM
Quote from: Dwachs on December 06, 2022, 05:19:01 PMThis should be fixed with r10829, which is at github since two days ago. With with revision did you record the video?

r10828
Screenshot 2022-12-06 at 13-58-33 simutrans_simutrans.png
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Dwachs on December 06, 2022, 09:03:33 PM
Do not know why, but I can download r10829 on github :/
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Yona-TYT on December 06, 2022, 09:37:31 PM
Quote from: Dwachs on December 06, 2022, 09:03:33 PMDo not know why, but I can download r10829 on github :/
It's because you are using the old repo "https://github.com/aburch/" And I use "https://github.com/simutrans/"

EDIT.

Apparently github played a trick on me with revisions. :o

I confirm that r10829 no longer hangs/breaks simutrans.

Although my custom is to use messages in gui for debugging and testing, so at the moment I'm limited in that aspect. :-[


Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Dwachs on December 07, 2022, 07:00:50 AM
Enabling these messages again is the next thing on my todo-list.
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Yona-TYT on December 07, 2022, 01:25:50 PM
Quote from: Dwachs on December 07, 2022, 07:00:50 AMEnabling these messages again is the next thing on my todo-list.
Nice 8) ;D .
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Dwachs on December 15, 2022, 09:22:10 PM
in r10833 gui.add_message will not suspend
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Yona-TYT on December 16, 2022, 04:04:41 PM
Removing text label also gives error.

Captura desde 2022-12-16 11-43-37.png
Title: Re: function "is_work_allowed_here" gets stuck in infinite loop
Post by: Dwachs on December 17, 2022, 04:57:03 PM
Please do not call any commands in is_allwed_here. This is a bug of the script not of simutrans.