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]: Crashed while creating small map #9722

Closed
ghost opened this issue Nov 29, 2021 · 3 comments · Fixed by #11858
Closed

[Crash]: Crashed while creating small map #9722

ghost opened this issue Nov 29, 2021 · 3 comments · Fixed by #11858
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Nov 29, 2021

Version of OpenTTD

12.1, Windows 10

Steps to reproduce

  1. Create game, select temperate, industries very low, towns very low, map size 64x64.

Upload crash files

OpenTTD.zip

@glx22
Copy link
Contributor

glx22 commented Dec 4, 2021

Main thread:

>	openttd.exe!GetToolbarAlignedWindowPosition(int window_width) Ligne 1668	C++
 	openttd.exe!LocalGetWindowPlacement(const WindowDesc * desc, short sm_width, short sm_height, int window_number) Ligne 1726	C++
 	openttd.exe!Window::OnInitialPosition(short sm_width, short sm_height, int window_number) Ligne 1750	C++
 	openttd.exe!Window::FinishInitNested(int window_number) Ligne 1781	C++
 	[Cadre en ligne] openttd.exe!BuildRailToolbarWindow::{ctor}(WindowDesc *) Ligne 432	C++
 	openttd.exe!ShowBuildRailToolbar(RailType) Ligne 874	C++
 	openttd.exe!RailToolbarGlobalHotkeys(int hotkey) Ligne 783	C++
 	openttd.exe!HandleGlobalHotkeys(char32_t keycode, unsigned short) Ligne 374	C++
 	openttd.exe!HandleKeypress(unsigned int keycode, char32_t key) Ligne 2660	C++
 	openttd.exe!HandleCharMsg(unsigned int keycode, char32_t charcode) Ligne 254	C++
 	openttd.exe!WndProcGdi(HWND__ * hwnd, unsigned int msg, unsigned __int64 wParam, __int64 lParam) Ligne 579	C++
 	[Code externe]	
 	openttd.exe!VideoDriver_Win32Base::PollEvent() Ligne 857	C++
 	openttd.exe!VideoDriver::Tick() Ligne 133	C++
 	openttd.exe!VideoDriver_Win32Base::MainLoop() Ligne 868	C++
 	openttd.exe!openttd_main(int argc, char * * argv) Ligne 804	C++
 	openttd.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow) Ligne 416	C++
 	[Code externe]	

Game thread:

 	[Code externe]	
>	[Cadre en ligne] openttd.exe!std::_Mutex_base::lock() Ligne 51	C++
 	[Cadre en ligne] openttd.exe!std::lock_guard<std::mutex>::{ctor}(std::mutex &) Ligne 438	C++
 	openttd.exe!VideoDriver::GameLoopPause() Ligne 73	C++
 	openttd.exe!_SetGeneratingWorldProgress(GenWorldProgress cls, unsigned int progress, unsigned int total) Ligne 1470	C++
 	openttd.exe!_GenerateWorld() Ligne 187	C++
 	openttd.exe!SwitchToMode(SwitchMode new_mode) Ligne 1115	C++
 	openttd.exe!GameLoop() Ligne 1448	C++
 	openttd.exe!VideoDriver::GameLoop() Ligne 37	C++
 	openttd.exe!VideoDriver::GameThread() Ligne 46	C++
 	openttd.exe!StartNewThread::__l3::<lambda>(const char * name, void(*)(VideoDriver *) && F, VideoDriver * && <A_0>) Ligne 65	C++
 	[Code externe]	
 	openttd.exe!thread_start<unsigned int (__cdecl*)(void *),1>(void * const parameter) Ligne 97	C++
 	[Code externe]	

@glx22
Copy link
Contributor

glx22 commented Dec 4, 2021

Crash seems to be caused by 'A' hotkey being pressed during world generation. But I fail to reproduce it.

@2TallTyler 2TallTyler added the needs triage This issue needs further investigation before it becomes actionable label Oct 19, 2022
@TrueBrain
Copy link
Member

OP must have been the luckiest person alive. There is like a VERY small window in which this crash can happen. Let me explain.

HandleKeypress() can be called in two instances: when there is a modal window (read: world generation) or when there is an active local company. In both cases, keypresses are handled, all the way down to ShowBuildRailToolbar.

This function checks if a local company exists (if not, the world is generating). If it doesn't, it doesn't create an actual toolbar. If the local company does exist, it does create the toolbar.

During world generation, the local company is not set, till just before the end. And then twice, and only twice, so 2 times a context-switch, we allow the system to read keyboard inputs. At SetGeneratingWorldProgress(GWP_GAME_START, 1);, just when we have set the local company to something valid. And then IncreaseGeneratingWorldProgress(GWP_GAME_START) slightly after.

But only after those two functions, we actually create the vital windows, needed for ShowBuildRailToolbar to work.

In order to reproduce this, I had to add 1000000 context-switches (not kidding) to make it anywhere possible to have a small window where I could press a hotkey and cause this crash. And that wasn't even a second of time. So either OP had a very slow computer or one under a lot of CPU stress .. or he was just REALLY lucky to hit this bug. Amazing.

Either way, it is a bug, and one we should fix.

@TrueBrain TrueBrain added bug Something isn't working and removed needs triage This issue needs further investigation before it becomes actionable labels Jan 21, 2024
TrueBrain added a commit that referenced this issue Jan 21, 2024
Many places use local_company to detect whether world generation is
done, and blindly assume all vital windows exists when local_company
is set.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants