From f344154a3fdbc4f8cc5af8a0d28301478c2f6ae1 Mon Sep 17 00:00:00 2001 From: jarmonik Date: Thu, 28 Dec 2023 16:47:25 +0200 Subject: [PATCH] Further startup cleanup and error detection. --- OVP/D3D9Client/D3D9Client.cpp | 5 +++-- OVP/D3D9Client/VideoTab.cpp | 29 +++++++++++++++-------------- OVP/D3D9Client/VideoTab.h | 7 +++---- Src/Orbiter/Orbiter.cpp | 17 +++++++++++++++-- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/OVP/D3D9Client/D3D9Client.cpp b/OVP/D3D9Client/D3D9Client.cpp index c73c3d587..dbdc78bc9 100644 --- a/OVP/D3D9Client/D3D9Client.cpp +++ b/OVP/D3D9Client/D3D9Client.cpp @@ -195,6 +195,7 @@ DLLCLBK void ExitModule(HINSTANCE hDLL) delete TileCatalog; delete Config; delete g_pConst; + delete g_client; DebugControls::Release(); AtmoControls::Release(); @@ -334,11 +335,11 @@ bool D3D9Client::clbkInitialise() // Perform default setup if (GraphicsClient::clbkInitialise()==false) return false; + //Create the Launchpad video tab interface oapiWriteLog("[D3D9] Initialize VideoTab..."); vtab = new VideoTab(this, ModuleInstance(), OrbiterInstance(), LaunchpadVideoTab()); - oapiWriteLog("[D3D9] VideoTab Created..."); - return true; + return vtab->Initialise(); } diff --git a/OVP/D3D9Client/VideoTab.cpp b/OVP/D3D9Client/VideoTab.cpp index ffb6c0ec8..3fa9e411b 100644 --- a/OVP/D3D9Client/VideoTab.cpp +++ b/OVP/D3D9Client/VideoTab.cpp @@ -47,8 +47,6 @@ VideoTab::VideoTab(D3D9Client *gc, HINSTANCE _hInst, HINSTANCE _hOrbiterInst, HW hTab = hVideoTab; aspect_idx = 0; SelectedAdapterIdx = 0; - - Initialise(); } VideoTab::~VideoTab() @@ -160,7 +158,7 @@ BOOL VideoTab::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) // ============================================================== // Initialise the Launchpad "video" tab -void VideoTab::Initialise() +bool VideoTab::Initialise() { D3DDISPLAYMODE mode, curMode; D3DADAPTER_IDENTIFIER9 info; @@ -181,7 +179,7 @@ void VideoTab::Initialise() if (nAdapter == 0) { LogErr("VideoTab::Initialize() No DirectX9 Adapters Found"); - return; + return false; } if (data->deviceidx < 0 || (data->deviceidx)>=nAdapter) data->deviceidx = 0; @@ -242,13 +240,15 @@ void VideoTab::Initialise() SendDlgItemMessage(hTab, IDC_VID_ENUM, BM_SETCHECK, data->forceenum, 0); SendDlgItemMessage(hTab, IDC_VID_PAGEFLIP, BM_SETCHECK, data->pageflip, 0); // Full scrren Window - SelectAdapter(data->deviceidx); + bool bRet = SelectAdapter(data->deviceidx); SelectFullscreen(data->fullscreen); ShowWindow (GetDlgItem (hTab, IDC_VID_INFO), SW_SHOW); - SetWindowText(GetDlgItem(hTab, IDC_VID_INFO), "Advanced"); + SetWindowText(GetDlgItem(hTab, IDC_VID_INFO), "Advanced"); + + return bRet; } @@ -265,17 +265,17 @@ void VideoTab::SelectMode(DWORD index) // ============================================================== // Respond to user adapter selection // -void VideoTab::SelectAdapter(DWORD index) +bool VideoTab::SelectAdapter(DWORD index) { SelectedAdapterIdx = index; GraphicsClient::VIDEODATA *data = gclient->GetVideoData(); - // Create the Direct3D9 --------------------------------------------- - // - - if (g_pD3DObject == NULL) LogErr("VideoTab::SelectAdapter(%u) Direct3DCreate9 Failed",index); + if (g_pD3DObject == NULL) { + LogErr("VideoTab::SelectAdapter(%u) Direct3DCreate9 Failed", index); + return false; + } else { char cbuf[32]; @@ -283,7 +283,7 @@ void VideoTab::SelectAdapter(DWORD index) if (g_pD3DObject->GetAdapterCount()<=index) { LogErr("Adapter Index out of range"); - return; + return false; } HR(g_pD3DObject->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &curMode)); @@ -293,8 +293,7 @@ void VideoTab::SelectAdapter(DWORD index) DWORD nModes = g_pD3DObject->GetAdapterModeCount(index, D3DFMT_X8R8G8B8); if (nModes == 0) { - LogErr("VideoTab::SelectAdapter() No Display Modes Available"); - return; + LogErr("VideoTab::SelectAdapter() No Display Modes Available"); } for (DWORD k=0;kmodeidx&0xFF, 0); } + + return true; } diff --git a/OVP/D3D9Client/VideoTab.h b/OVP/D3D9Client/VideoTab.h index 5e4a9d43c..4ef007625 100644 --- a/OVP/D3D9Client/VideoTab.h +++ b/OVP/D3D9Client/VideoTab.h @@ -25,14 +25,13 @@ class VideoTab { void UpdateConfigData(); // copy dialog state back to parameter structure -protected: - - void Initialise(); + bool Initialise(); // Initialise dialog elements +protected: void SelectFullscreen(bool); void SelectMode(DWORD index); - void SelectAdapter(DWORD index); + bool SelectAdapter(DWORD index); // Update dialog after user device selection void SelectWidth(); diff --git a/Src/Orbiter/Orbiter.cpp b/Src/Orbiter/Orbiter.cpp index c70c8eb4d..ee13cf477 100644 --- a/Src/Orbiter/Orbiter.cpp +++ b/Src/Orbiter/Orbiter.cpp @@ -630,10 +630,23 @@ HINSTANCE Orbiter::LoadModule (const char *path, const char *name) } } +#ifndef INLINEGRAPHICS + // Can't initialize DirectX in DllMain(), let's do it over here (jarmonik 28.12.2023) if (hDLL) { - // Can't initialize DirectX in DllMain(), let's do it over here (jarmonik 28.12.2023) - if (register_module == gclient && gclient != NULL) gclient->clbkInitialise(); + if (register_module == gclient && gclient != NULL) { + if (gclient->clbkInitialise() == false) { + // If graphics initialization fails remove client + RemoveGraphicsClient(gclient); + FreeLibrary(hDLL); + LOGOUT_ERR("Client Initialization Failed. Unloading %s", name); + hDLL = NULL; + return NULL; + } + } + } +#endif + if (hDLL) { DLLModule module = { hDLL, register_module ? register_module : new oapi::Module(hDLL), std::string(name), !register_module }; // If the DLL doesn't provide a Module interface, create a default one which provides the legacy callbacks LOGOUT(register_module ? "Loading module %s" : "Loading module %s (legacy interface)", name);