Changeset - r28291:4fc68c2c9a36
[Not reviewed]
master
0 1 0
Peter Nelson - 12 months ago 2023-12-14 20:05:38
peter1138@openttd.org
Fix: Don't crash when saving a crashlog save with no main window open.
1 file changed with 12 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/saveload/misc_sl.cpp
Show inline comments
 
@@ -37,11 +37,18 @@ ZoomLevel _saved_scrollpos_zoom;
 

	
 
void SaveViewportBeforeSaveGame()
 
{
 
	const Window *w = GetMainWindow();
 

	
 
	_saved_scrollpos_x = w->viewport->scrollpos_x;
 
	_saved_scrollpos_y = w->viewport->scrollpos_y;
 
	_saved_scrollpos_zoom = w->viewport->zoom;
 
	/* Don't use GetMainWindow() in case the window does not exist. */
 
	const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
 
	if (w == nullptr || w->viewport == nullptr) {
 
		/* Ensure saved position is clearly invalid. */
 
		_saved_scrollpos_x = INT_MAX;
 
		_saved_scrollpos_y = INT_MAX;
 
		_saved_scrollpos_zoom = ZOOM_LVL_END;
 
	} else {
 
		_saved_scrollpos_x = w->viewport->scrollpos_x;
 
		_saved_scrollpos_y = w->viewport->scrollpos_y;
 
		_saved_scrollpos_zoom = w->viewport->zoom;
 
	}
 
}
 

	
 
void ResetViewportAfterLoadGame()
0 comments (0 inline, 0 general)