Skip to content

Commit

Permalink
5.3; fixed issues related to some graphics cards not having device av…
Browse files Browse the repository at this point in the history
…ailable after first draw
  • Loading branch information
Jon committed May 17, 2021
1 parent d055177 commit 3ac5dc5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.16)

project(gwtoolbox)

set(GWTOOLBOXDLL_VERSION "5.2")
set(GWTOOLBOXDLL_VERSION "5.3")
set(GWTOOLBOXDLL_VERSION_BETA "") # can be anything. Marks beta version if not empty.
set(GWTOOBOX_MODULE_VERSION "5,2,0,0") # used for Dll module info. See GWToolboxdll/GWToolbox.rc
set(GWTOOBOX_MODULE_VERSION "5,3,0,0") # used for Dll module info. See GWToolboxdll/GWToolbox.rc

# Updates toolboxversion.txt after changes in the above version (make sure to run cmake .. or build the project)
file(WRITE "resources/toolboxversion.txt" ${GWTOOLBOXDLL_VERSION})
Expand Down
4 changes: 3 additions & 1 deletion GWToolboxdll/GWToolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ void GWToolbox::Draw(IDirect3DDevice9* device) {
if (!GuiUtils::FontsLoaded())
return; // Fonts not loaded yet.

Resources::Instance().DxUpdate(device);

ImGui_ImplDX9_NewFrame();
ImGui_ImplWin32_NewFrame();

Expand All @@ -486,7 +488,7 @@ void GWToolbox::Draw(IDirect3DDevice9* device) {
ImGui::GetIO().KeysDown[VK_CONTROL] = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
ImGui::GetIO().KeysDown[VK_SHIFT] = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
ImGui::GetIO().KeysDown[VK_MENU] = (GetKeyState(VK_MENU) & 0x8000) != 0;
Resources::Instance().DxUpdate(device);


for (ToolboxUIElement* uielement : GWToolbox::Instance().uielements) {
uielement->Draw(device);
Expand Down
22 changes: 18 additions & 4 deletions GWToolboxdll/Modules/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,13 @@ void Resources::LoadTextureAsync(IDirect3DTexture9** texture, const std::filesys
}

HRESULT Resources::TryCreateTexture(IDirect3DDevice9* device, const std::filesystem::path& path_to_file, IDirect3DTexture9** texture, bool display_error) {
HRESULT res = D3DXCreateTextureFromFileW(device, path_to_file.c_str(), texture);
// NB: Some Graphics cards seem to spit out D3DERR_NOTAVAILABLE when loading textures, haven't figured out why but retry if this error is reported
HRESULT res = D3DERR_NOTAVAILABLE;
size_t tries = 0;
do {
tries++;
res = D3DXCreateTextureFromFileExW(device, path_to_file.c_str(), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
} while (res == D3DERR_NOTAVAILABLE && tries < 3);
if (display_error && res != D3D_OK) {
Log::Error("Error loading resource from file %ls - Error is %ls", path_to_file.filename().c_str(), d3dErrorMessage(res));
}
Expand All @@ -161,7 +167,13 @@ HRESULT Resources::TryCreateTexture(IDirect3DDevice9* device, const std::filesys
return res;
}
HRESULT Resources::TryCreateTexture(IDirect3DDevice9* device, HMODULE hSrcModule, LPCSTR id, IDirect3DTexture9** texture, bool display_error) {
HRESULT res = D3DXCreateTextureFromResourceA(device, hSrcModule, id, texture);
// NB: Some Graphics cards seem to spit out D3DERR_NOTAVAILABLE when loading textures, haven't figured out why but retry if this error is reported
HRESULT res = D3DERR_NOTAVAILABLE;
size_t tries = 0;
do {
tries++;
res = D3DXCreateTextureFromResourceExA(device, hSrcModule, id, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
} while (res == D3DERR_NOTAVAILABLE && tries < 3);
if (display_error && res != D3D_OK) {
Log::Error("Error loading resource for id %d, module %p - Error is %ls", id, hSrcModule, d3dErrorMessage(res));
}
Expand Down Expand Up @@ -234,8 +246,7 @@ void Resources::LoadTextureAsync(IDirect3DTexture9** texture,
if (std::filesystem::exists(path_to_file)) {
// if file exists load it
toload.push([path_to_file, texture, id](IDirect3DDevice9* device) {
TryCreateTexture(device, path_to_file, texture);
HRESULT res = TryCreateTexture(device, path_to_file, texture, id != 0);
HRESULT res = TryCreateTexture(device, path_to_file, texture, id == 0);
if (!(res == D3D_OK && texture) && id != 0) {
Log::Log("Failed to load %ls from file; error code %ls", path_to_file.filename().c_str(), d3dErrorMessage(res));
TryCreateTexture(device, GWToolbox::GetDLLModule(), MAKEINTRESOURCE(id), texture);
Expand All @@ -254,6 +265,9 @@ void Resources::LoadTextureAsync(IDirect3DTexture9** texture,

void Resources::DxUpdate(IDirect3DDevice9* device) {
while (!toload.empty()) {
D3DCAPS9 caps;
if (device->GetDeviceCaps(&caps) != D3D_OK)
break; // Not ready yet
toload.front()(device);
toload.pop();
}
Expand Down
4 changes: 2 additions & 2 deletions docs/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Previous releases are provided as dll files. If you are looking for the latest v

In order to use these older DLL versions, you need to put `GWToolboxdll.dll` in the same folder as `GWToolbox.exe`, run the exe with the `/localdll` parameter, and disable automatic updates from within GWToolbox.

## Version 5.2
## Version 5.3

* [Fix] Fixed some map load crashes when using obfuscator
* [Fix] Fixed blank pcon icons caused by d3d errors loading from disk

[Download](https://github.com/HasKha/GWToolboxpp/releases/download/5.2_Release/GWToolboxdll.dll)
[Download](https://github.com/HasKha/GWToolboxpp/releases/download/5.3_Release/GWToolboxdll.dll)

## Version 5.1
Please note that a lot of changes have been made in this version in an effort to hide player names in-game in response to the recent bans, so there may be bugs with it. Please raise an issue on GitHub or the Toolbox Discord if you find one!
Expand Down
2 changes: 1 addition & 1 deletion resources/toolboxversion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.2
5.3

0 comments on commit 3ac5dc5

Please sign in to comment.