Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(ww3d2): fail a texture load that created no texture

Olcay Seyganc39f1c98e18c
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
index 4818c1c07..eac9e9aad 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
@@ -2088,6 +2088,24 @@ AGAIN:
}
// render is all done!
WW3D::End_Render();
+
+ /* End_Render is where a lost device is noticed and reset, and that reset is the most
+ dangerous thing this process does: it hands every default-pool resource back and asks
+ the driver to rebuild the swap chain, and under -d3d12 it has been seen to fault
+ inside the 9On12 layer. WW3D2 is built without RELEASE_DEBUG_LOGGING, so its own
+ "Resetting device" line does not exist in a shipping build and the log went straight
+ from an ordinary frame to a crash dump. This is on the GameEngineDevice side of the
+ fence, where logging is compiled in. */
+ {
+ static Bool s_wasDeviceLost = FALSE;
+ const Bool lost = DX8Wrapper::Is_Device_Lost();
+ if (lost != s_wasDeviceLost)
+ {
+ s_wasDeviceLost = lost;
+ DEBUG_LOG(("Direct3D device %s\n",
+ lost ? "LOST - End_Render will try to reset it" : "recovered"));
+ }
+ }
}
else
{
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp
index 561be2870..70de2b9e9 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp
@@ -1220,6 +1220,23 @@ bool TextureLoadTaskClass::Begin_Load(void)
return false;
}
+ /* A load that reported success and produced no texture is not a success. Both of the Begin_
+ functions above return true whatever _Create_DX8_Texture gave them, and that function returns
+ NULL on a device that cannot currently create anything - which is every frame between losing
+ the device and getting it back. Lock_Surfaces then called GetLevelCount on a null pointer and
+ took the game with it.
+
+ The way in is ordinary: alt-tab out of a fullscreen game, the log fills with "Could not do
+ WW3D::Begin_Render()", the simulation carries on regardless, a script spawns a unit, its model
+ asks for a texture and there is no device to make one on. Seen on 2026-09-05 in a script
+ reinforcement drop, three frames after the device went. Failing here instead puts the missing
+ texture on it, which is what Finish_Load already does for a file that will not load. */
+ if (!D3DTexture) {
+ WWDEBUG_SAY(("Texture creation gave nothing back for %s - the device is probably lost\n",
+ Texture ? Texture->Get_Full_Path() : "<no texture>"));
+ return false;
+ }
+
// lock surfaces in preparation for copy
Lock_Surfaces();
@@ -1797,6 +1814,12 @@ bool TextureLoadTaskClass::Begin_Uncompressed_Load(void)
void TextureLoadTaskClass::Lock_Surfaces(void)
{
+ // nothing to lock, and the caller has already been told: see Begin_Load
+ if (!D3DTexture) {
+ MipLevelCount = 0;
+ return;
+ }
+
MipLevelCount = D3DTexture->GetLevelCount();
for (unsigned int i = 0; i < MipLevelCount; ++i)