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

[Crash]: Threads can crash the game after level restart #3190

Open
6 tasks done
Narre opened this issue Jan 27, 2025 · 1 comment
Open
6 tasks done

[Crash]: Threads can crash the game after level restart #3190

Narre opened this issue Jan 27, 2025 · 1 comment

Comments

@Narre
Copy link
Contributor

Narre commented Jan 27, 2025

SuperTux Version

current master (as of 27 Jan 2025)

System Information

LMDE6 64bit

Steps To Reproduce Crash

I tried to get around this using scripting, but it's nearly impossible to detect when the level is restarted since the thread still sees the old sector table. There are ways to do it but they become nearly impossible to implement when the thread runs a lot of nested functions. Either way, the game shouldn't crash under any circumstances.

The simplest way I could find to reproduce this crash is by putting the following code in a .nut file:

img <- FloatingImage("images/engine/menu/logo.png");
img.set_visible(true);

function f() {
	while(true) {
		wait(0);
		if(sector.Tux.get_input_held("jump")) img.set_visible(false);
	}
}

t <- newthread(f);
t.call();

and then importing said file from e.g. a switch in a level.
After using said switch, restart the level and jump → game crashes.

At first, I tried putting this in the init script and in a switch, but the thread would just cease to exist after running the contents of the while loop once. Another bug, perhaps? From an external file, it works as expected (enabling the crash, which isn't as expected).

I don't think this has anything to do with specifically FloatingImages, as long as the thread in the no longer existing instance of the level tries to do anything in its "ghost" sector table, it probably has the same result (though I haven't tested this thoroughly - it's 4 AM rn)

Debugging Information

This is what I've got (terminal output), no debugging tools were used:

Error: signal 11:
SuperTux has encountered an unrecoverable error!
supertux2(_ZN12ErrorHandler14get_stacktraceB5cxx11Ev+0x29) [0x55dbe0237029]
supertux2(_ZN12ErrorHandler12handle_errorEi+0x57) [0x55dbe02385d7]
/lib/x86_64-linux-gnu/libc.so.6(+0x3c050) [0x7fcb4757c050]
/lib/x86_64-linux-gnu/libstdc++.so.6(__dynamic_cast+0x22) [0x7fcb478aead2]
supertux2(_ZN3ssq6detail11funcBindingILi0EvSt5tupleIJEEJP13FloatingImagebEE4callEP4SQVM+0xeb) [0x55dbe017fb9b]
/usr/local/lib/libsimplesquirrel.so(_ZN4SQVM10CallNativeEP15SQNativeClosurexxR11SQObjectPtriRbS4_+0x213) [0x7fcb481411b3]
/usr/local/lib/libsimplesquirrel.so(_ZN4SQVM7ExecuteER11SQObjectPtrxxS1_yNS_13ExecutionTypeE+0x132e) [0x7fcb48142fae]
/usr/local/lib/libsimplesquirrel.so(sq_wakeupvm+0xa7) [0x7fcb4811f687]
supertux2(_ZN17SquirrelScheduler6updateEf+0x170) [0x55dbe022bc60]
supertux2(_ZN13ScreenManager16update_gamelogicEf+0x44) [0x55dbdffb2844]
supertux2(_ZN13ScreenManager9loop_iterEv+0x1d9) [0x55dbdffb37b9]
supertux2(_ZN13ScreenManager3runEv+0x30) [0x55dbdffb3ac0]
supertux2(_ZN4Main3runEiPPc+0x403) [0x55dbdff74223]
supertux2(main+0x60) [0x55dbdfecc810]
/lib/x86_64-linux-gnu/libc.so.6(+0x2724a) [0x7fcb4756724a]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85) [0x7fcb47567305]
supertux2(_start+0x21) [0x55dbdfeff471]

Additional Information

I noticed this when running STAGE in multithreaded mode - the game would crash when I restarted the level with the inventory open. It took me hours to isolate the issue. I ended up fixing it in STAGE via scripting, but it's really finicky and it doesn't fix crashes while more complex stuff in the engine is running.

Guidelines For Reporting Issues

  • I have read https://github.com/SuperTux/supertux/blob/master/CONTRIBUTING.md#bug-reports.
  • I have verified this isn't an issue that's already been reported.
  • I have verified this isn't a discussion, or an issue about unintended behavior or a feature request, but rather an actual crash ─ that is, the game closed unexpectedly.
  • I have verified this issue is not about wrong translations (use Transifex for those), or anything unsupported (e.g. third-party add-ons).
  • In this report, I have only included details about one (1) crash.
  • If I make a mistake while submitting this report, I agree to use the "Edit" feature to correct it, instead of closing this issue and opening a new one.
@Narre
Copy link
Contributor Author

Narre commented Jan 27, 2025

IMO the best solution would be to just kill all squirrel threads created in a level/sector upon level/sector exit / level restart.

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

No branches or pull requests

1 participant