Skip to content

Commit bcb5afd

Browse files
committed
Fixed crash with the last token that should be nulled
1 parent 50ac5b8 commit bcb5afd

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/xrEngine/Device_create.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,18 @@ void CRenderDevice::UpdateWindowProps(const bool windowed)
8080

8181
if (windowed)
8282
{
83+
// Get the maximal available resolution (penultimate token in VidModesToken)
8384
u32 width, height;
84-
sscanf(VidModesToken.back().name, "%dx%d", &width, &height);
85+
sscanf(VidModesToken[VidModesToken.size() - 2].name, "%dx%d", &width, &height);
8586

8687
const bool drawBorders = strstr(Core.Params, "-draw_borders");
8788

88-
bool desktopResolution = false;
89+
bool maximalResolution = false;
8990
if (b_is_Ready && !drawBorders && psCurrentVidMode[0] == width && psCurrentVidMode[1] == height)
90-
desktopResolution = true;
91+
maximalResolution = true;
9192

92-
SDL_SetWindowFullscreen(m_sdlWnd, desktopResolution ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
93+
// Set SDL_WINDOW_FULLSCREEN_DESKTOP if maximal resolution is selected
94+
SDL_SetWindowFullscreen(m_sdlWnd, maximalResolution ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
9395
SDL_SetWindowSize(m_sdlWnd, psCurrentVidMode[0], psCurrentVidMode[1]);
9496
SDL_SetWindowBordered(m_sdlWnd, drawBorders ? SDL_TRUE : SDL_FALSE);
9597
}
@@ -225,6 +227,8 @@ void FillVidModesToken(u32 monitorID)
225227
R_ASSERT3(modeCount > 0, "Failed to find display modes", SDL_GetError());
226228
modes.reserve(modeCount + 1);
227229

230+
Msg("Available video modes[%d]:", modes.size());
231+
228232
SDL_DisplayMode displayMode;
229233
for (int i = modeCount - 1; i >= 0; --i)
230234
{
@@ -234,7 +238,10 @@ void FillVidModesToken(u32 monitorID)
234238
xr_sprintf(str, sizeof(str), "%dx%d", displayMode.w, displayMode.h);
235239

236240
if (modes.cend() == std::find_if(modes.cbegin(), modes.cend(), uniqueRenderingMode(str)))
241+
{
237242
modes.emplace_back(xr_strdup(str), i);
243+
Msg("[%s]", str);
244+
}
238245

239246
// For the first time we can fill refresh rate token here
240247
if (displayMode.w == psCurrentVidMode[0] && displayMode.h == psCurrentVidMode[1])
@@ -245,11 +252,8 @@ void FillVidModesToken(u32 monitorID)
245252
}
246253
}
247254

255+
modes.emplace_back(nullptr, -1);
248256
rates.emplace_back(nullptr, -1);
249-
250-
Msg("Available video modes[%d]:", modes.size());
251-
for (const auto& mode : modes)
252-
Msg("[%s]", mode.name);
253257
}
254258

255259
void FillRefreshRateToken()

0 commit comments

Comments
 (0)