Skip to content

Commit

Permalink
Further startup cleanup and error detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmonik committed Dec 28, 2023
1 parent 04017e6 commit f344154
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
5 changes: 3 additions & 2 deletions OVP/D3D9Client/D3D9Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ DLLCLBK void ExitModule(HINSTANCE hDLL)
delete TileCatalog;
delete Config;
delete g_pConst;
delete g_client;

DebugControls::Release();
AtmoControls::Release();
Expand Down Expand Up @@ -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();
}


Expand Down
29 changes: 15 additions & 14 deletions OVP/D3D9Client/VideoTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ VideoTab::VideoTab(D3D9Client *gc, HINSTANCE _hInst, HINSTANCE _hOrbiterInst, HW
hTab = hVideoTab;
aspect_idx = 0;
SelectedAdapterIdx = 0;

Initialise();
}

VideoTab::~VideoTab()
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}


Expand All @@ -265,25 +265,25 @@ 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];
D3DDISPLAYMODE mode, curMode;

if (g_pD3DObject->GetAdapterCount()<=index) {
LogErr("Adapter Index out of range");
return;
return false;
}

HR(g_pD3DObject->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &curMode));
Expand All @@ -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;k<nModes;k++) {
Expand All @@ -306,6 +305,8 @@ void VideoTab::SelectAdapter(DWORD index)

SendDlgItemMessage(hTab, IDC_VID_MODE, CB_SETCURSEL, data->modeidx&0xFF, 0);
}

return true;
}


Expand Down
7 changes: 3 additions & 4 deletions OVP/D3D9Client/VideoTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 15 additions & 2 deletions Src/Orbiter/Orbiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f344154

Please sign in to comment.