backend update from Raze

* moving large allocations off the stack
* use proper printf formatters for size_t and ptrdiff_t.
* adding some missing 'noexcept'.
This commit is contained in:
Christoph Oelckers 2024-01-06 15:24:10 +01:00
commit 83aa9388ca
29 changed files with 117 additions and 109 deletions

View file

@ -381,12 +381,14 @@ static HANDLE WriteMyMiniDump (void)
{
MiniDumpThreadData dumpdata = { file, pMiniDumpWriteDump, &exceptor };
DWORD id;
HANDLE thread = CreateThread (NULL, 0, WriteMiniDumpInAnotherThread,
&dumpdata, 0, &id);
WaitForSingleObject (thread, INFINITE);
if (GetExitCodeThread (thread, &id))
HANDLE thread = CreateThread (NULL, 0, WriteMiniDumpInAnotherThread, &dumpdata, 0, &id);
if (thread != nullptr)
{
good = id;
WaitForSingleObject(thread, INFINITE);
if (GetExitCodeThread(thread, &id))
{
good = id;
}
}
}
}

View file

@ -421,7 +421,8 @@ void FDInputJoystick::ProcessInput()
return;
}
state = (uint8_t *)alloca(DataFormat.dwDataSize);
TArray<uint8_t> statearr(DataFormat.dwDataSize, true);
state = statearr.data();
hr = Device->GetDeviceState(DataFormat.dwDataSize, state);
if (FAILED(hr))
return;

View file

@ -334,7 +334,8 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (!GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)) &&
size != 0)
{
uint8_t *buffer = (uint8_t *)alloca(size);
TArray<uint8_t> array(size, true);
uint8_t *buffer = array.data();
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, buffer, &size, sizeof(RAWINPUTHEADER)) == size)
{
int code = GET_RAWINPUT_CODE_WPARAM(wParam);
@ -691,12 +692,15 @@ void I_PutInClipboard (const char *str)
auto wstr = WideString(str);
HGLOBAL cliphandle = GlobalAlloc (GMEM_DDESHARE, wstr.length() * 2 + 2);
if (cliphandle != NULL)
if (cliphandle != nullptr)
{
wchar_t *ptr = (wchar_t *)GlobalLock (cliphandle);
wcscpy (ptr, wstr.c_str());
GlobalUnlock (cliphandle);
SetClipboardData (CF_UNICODETEXT, cliphandle);
if (ptr)
{
wcscpy(ptr, wstr.c_str());
GlobalUnlock(cliphandle);
SetClipboardData(CF_UNICODETEXT, cliphandle);
}
}
CloseClipboard ();
}

View file

@ -284,12 +284,12 @@ int DoMain (HINSTANCE hInstance)
HANDLE stdinput = GetStdHandle(STD_INPUT_HANDLE);
ShowWindow(mainwindow.GetHandle(), SW_HIDE);
WriteFile(StdOut, "Press any key to exit...", 24, &bytes, NULL);
if (StdOut != nullptr) WriteFile(StdOut, "Press any key to exit...", 24, &bytes, nullptr);
FlushConsoleInputBuffer(stdinput);
SetConsoleMode(stdinput, 0);
ReadConsole(stdinput, &bytes, 1, &bytes, NULL);
}
else if (StdOut == NULL)
else if (StdOut == nullptr)
{
mainwindow.ShowErrorPane(nullptr);
}

View file

@ -326,8 +326,7 @@ bool Win32GLVideo::SetupPixelFormat(int multisample)
if (!myWglChoosePixelFormatARB(m_hDC, attributes.data(), attribsFloat, 1, &pixelFormat, &numFormats))
{
Printf("R_OPENGL: Couldn't choose pixel format. Retrying in compatibility mode\n");
goto oldmethod;
I_FatalError("R_OPENGL: Couldn't choose pixel format. Retrying in compatibility mode\n");
}
if (vid_hdr && numFormats == 0) // This card/driver doesn't support the rgb16f pixel format. Fall back to 8bpc
@ -343,8 +342,7 @@ bool Win32GLVideo::SetupPixelFormat(int multisample)
if (!myWglChoosePixelFormatARB(m_hDC, attributes.data(), attribsFloat, 1, &pixelFormat, &numFormats))
{
Printf("R_OPENGL: Couldn't choose pixel format. Retrying in compatibility mode\n");
goto oldmethod;
I_FatalError("R_OPENGL: Couldn't choose pixel format.");
}
}
else if (vid_hdr)
@ -360,41 +358,12 @@ bool Win32GLVideo::SetupPixelFormat(int multisample)
vr_enable_quadbuffered = false;
goto again;
}
Printf("R_OPENGL: No valid pixel formats found. Retrying in compatibility mode\n");
goto oldmethod;
I_FatalError("R_OPENGL: No valid pixel formats found.");
}
}
else
{
oldmethod:
// If wglChoosePixelFormatARB is not found we have to do it the old fashioned way.
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32, // color depth
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
32, // z depth
8, // stencil buffer
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
pixelFormat = ChoosePixelFormat(m_hDC, &pfd);
DescribePixelFormat(m_hDC, pixelFormat, sizeof(pfd), &pfd);
if (pfd.dwFlags & PFD_GENERIC_FORMAT)
{
I_Error("R_OPENGL: OpenGL driver not accelerated!");
return false;
}
I_FatalError("R_OPENGL: Unable to create an OpenGL render context. Insufficient driver support for context creation\n");
}
if (!::SetPixelFormat(m_hDC, pixelFormat, NULL))
@ -452,8 +421,7 @@ bool Win32GLVideo::InitHardware(HWND Window, int multisample)
m_hRC = zd_wglCreateContext(m_hDC);
if (m_hRC == NULL)
{
I_Error("R_OPENGL: Unable to create an OpenGL render context.\n");
return false;
I_FatalError("R_OPENGL: Unable to create an OpenGL render context.\n");
}
}
@ -464,7 +432,7 @@ bool Win32GLVideo::InitHardware(HWND Window, int multisample)
}
}
// We get here if the driver doesn't support the modern context creation API which always means an old driver.
I_Error("R_OPENGL: Unable to create an OpenGL render context. Insufficient driver support for context creation\n");
I_FatalError("R_OPENGL: Unable to create an OpenGL render context. Insufficient driver support for context creation\n");
return false;
}