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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(w3ddevice): -nodevice, a start on running with no Direct3D device
Olcay Seyganadd7e0f132fb
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 0187635a3..f3b27bb8e 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -401,6 +401,7 @@ public:Int m_resDrillX; ///< the width -resdrill asks for (0 = the next mode the device offers)Int m_resDrillY; ///< the height -resdrill asks forBool m_resDrillKeep; ///< -resdrillkeep: answer the confirmation with Ok and stay on the new mode+ Bool m_noRenderDevice; ///< -nodevice: run without a Direct3D device at all, for a machine whose session is lockedAsciiString m_scenarioFile; ///< -scenario <name>: play Run/Scenarios/<name>.txt instead of leaving the match to a person or an AI (empty = off)Bool m_autoSkirmishTakeover; ///< -takeover: give every -autoskirmish slot a driverless human seat, so nothing thinks unless a scenario says soAsciiString m_autoSkirmishSide[ MAX_PLAYER_COUNT ]; ///< -side <slot> <faction>: name that slot's faction instead of drawing it from the seeddiff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex 61b24ecbb..b18ed6615 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -1600,6 +1600,26 @@ Int parseResDrillKeep(char *args[], int)return 1;}+/* -nodevice runs the whole game without a Direct3D device.++ -headless already draws nothing, but it still takes a 100x100 windowed device, and D3D9 answers+ CreateDevice with D3DERR_DEVICELOST while the workstation is locked. That puts every unattended+ run behind somebody being logged in with the screen awake, which is the one thing an unattended+ run should not need. With this on, the device is never asked for: WW3D2 hands out plain memory+ where it would have handed out a vertex or index buffer, no texture is loaded, and the render+ systems that exist only to draw are not brought up at all.++ Still a work in progress - a match started this way does not survive map load yet - so it is a+ separate switch rather than something -headless does on its own. */+Int parseNoDevice(char *args[], int num)+{+ if (TheWritableGlobalData)+ {+ TheWritableGlobalData->m_noRenderDevice = TRUE;+ }+ return 1;+}+/* -scenario <name> plays Run/Scenarios/<name>.txt: spawn this unit here, send it there, on thatframe.@@ -2060,6 +2080,7 @@ static CommandLineParam params[] ={ "-uidrill", parseUIDrill },{ "-resdrill", parseResDrill },{ "-resdrillkeep", parseResDrillKeep },+ { "-nodevice", parseNoDevice },{ "-scenario", parseScenario },{ "-side", parseSide },{ "-takeover", parseTakeover },diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex aecf82de9..86fd653c6 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -708,6 +708,7 @@ GlobalData::GlobalData()m_resDrillX = 0;m_resDrillY = 0;m_resDrillKeep = FALSE;+ m_noRenderDevice = FALSE; // -headless still takes a 100x100 device unless -nodevice says not tom_scenarioFile.clear(); // nothing is scripted; -scenario is a measuring tool and, like -groupdrill, ruins the match it runs inm_autoSkirmishTakeover = FALSE; // the AI plays the opponents unless -takeover empties their seatsfor( Int slot = 0; slot < MAX_PLAYER_COUNT; slot++ )diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cppindex f97d7cb1d..129501a4b 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp@@ -870,6 +870,12 @@ void W3DRadar::init( void )// extending functionalityRadar::init();+ // The radar's picture is three textures it paints the terrain and the blips into. Under+ // -nodevice there is nothing to hold them, and nothing looks at the result; the base class+ // above is the half that logic cares about, and that half has already run.+ if (TheGlobalData && TheGlobalData->m_noRenderDevice)+ return;+// gather specific texture format informationinitializeTextureFormats();diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DShadow.cppindex 6d6fbf1df..bb369cbce 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DShadow.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DShadow.cpp@@ -127,6 +127,11 @@ Bool W3DShadowManager::init( void ){Bool result=TRUE;+ // A shadow is nothing but a thing drawn, and ReAcquireResources below asks the device for the+ // buffers to draw it with. Under -nodevice there is nothing here to acquire.+ if (TheGlobalData && TheGlobalData->m_noRenderDevice)+ return result;+if (TheW3DVolumetricShadowManager && TheW3DVolumetricShadowManager->init()){if (TheW3DVolumetricShadowManager->ReAcquireResources())diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cppindex fd01d26c4..999a175a3 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp@@ -925,12 +925,31 @@ void W3DDisplay::init( void )WW3D::Set_Requested_Texture_Filter( TheGlobalData->m_textureFilterMode );TextureFilterClass::_Set_Requested_Anisotropy( (unsigned int)TheGlobalData->m_anisotropyLevel );+ /* -nodevice: never ask for a device at all. D3D9 answers CreateDevice with D3DERR_DEVICELOST+ while the workstation is locked, and init then threw ERROR_INVALID_D3D and took the run with+ it, so an unattended measurement needed somebody logged in with the screen awake.+ Enumeration above still happens - DX8Wrapper::Init only counts adapters and modes, which+ works locked - so anything that asks what the hardware is still gets an answer.+ Everything below this point is the device and the things drawn with it: the shader manager,+ the debug display's font, the browser control. None of it has a caller in a run that draws+ nothing. */+ if( TheGlobalData && TheGlobalData->m_noRenderDevice )+ {+ // The subsystems the device would normally have brought up, minus the ones that are D3D+ // resources. Every render object's constructor reaches for a preset vertex material, so+ // without these the first drawable built takes the process down.+ DX8Wrapper::Do_Onetime_Device_Independent_Inits();+ DEBUG_LOG(("W3DDisplay::init - headless: no render device, nothing will be drawn\n"));+ m_initialized = true;+ return;+ }+if( WW3D::Set_Render_Device( 0,- getWidth(),- getHeight(),- getBitDepth(),- getWindowed(),- true ) != WW3D_ERROR_OK )+ getWidth(),+ getHeight(),+ getBitDepth(),+ getWindowed(),+ true ) != WW3D_ERROR_OK ){// Getting the device at the default bit depth (32) didn't work, so try// getting a 16 bit display. (Voodoo 1-3 only supported 16 bit.) jba.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSmudge.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSmudge.cppindex bbd2dea71..908e5cee2 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSmudge.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSmudge.cpp@@ -32,6 +32,7 @@#include "W3DDevice/GameClient/W3DSmudge.h"#include "W3DDevice/GameClient/W3DShaderManager.h"#include "Common/GameMemory.h"+#include "Common/GlobalData.h"#include "GameClient/view.h"#include "GameClient/display.h"#include "WW3D2/texture.h"@@ -61,6 +62,11 @@ W3DSmudgeManager::~W3DSmudgeManager()void W3DSmudgeManager::init(void){SmudgeManager::init();++ // ReAcquireResources reads the back buffer off the device, and -nodevice has neither.+ if (TheGlobalData && TheGlobalData->m_noRenderDevice)+ return;+ReAcquireResources();}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cppindex 8df3a1e9a..977a20f39 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp@@ -1027,6 +1027,10 @@ void WaterRenderObjClass::load(void)//-------------------------------------------------------------------------------------------------Int WaterRenderObjClass::init(Real waterLevel, Real dx, Real dy, SceneClass *parentScene, WaterType type){+ // The water is a mesh, a bump map painted pixel by pixel and a set of render targets, all of+ // which want a device. Under -nodevice there is none, and nothing looks at water.+ if (TheGlobalData && TheGlobalData->m_noRenderDevice)+ return 0;m_iBumpFrame=0;m_bumpFrameAccum=0.0f;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cppindex 68cadbba2..5f60ef114 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cpp@@ -190,6 +190,12 @@ IndexBufferClass::WriteLockClass::WriteLockClass(IndexBufferClass* index_buffer_index_buffer->Add_Ref();switch (index_buffer->Type()) {case BUFFER_TYPE_DX8:+ // No device means no D3D buffer; write into the scratch block instead. See+ // DX8IndexBufferClass::Get_Scratch_Indices.+ if (static_cast<DX8IndexBufferClass*>(index_buffer)->Get_DX8_Index_Buffer()==NULL) {+ indices=static_cast<DX8IndexBufferClass*>(index_buffer)->Get_Scratch_Indices();+ break;+ }DX8_Assert();DX8_ErrorCode(static_cast<DX8IndexBufferClass*>(index_buffer)->Get_DX8_Index_Buffer()->Lock(0,@@ -216,6 +222,7 @@ IndexBufferClass::WriteLockClass::~WriteLockClass()DX8_THREAD_ASSERT();switch (index_buffer->Type()) {case BUFFER_TYPE_DX8:+ if (static_cast<DX8IndexBufferClass*>(index_buffer)->index_buffer==NULL) break;DX8_Assert();DX8_ErrorCode(static_cast<DX8IndexBufferClass*>(index_buffer)->index_buffer->Unlock());break;@@ -242,6 +249,10 @@ IndexBufferClass::AppendLockClass::AppendLockClass(IndexBufferClass* index_buffeswitch (index_buffer->Type()) {case BUFFER_TYPE_DX8:DX8_Assert();+ if (static_cast<DX8IndexBufferClass*>(index_buffer)->index_buffer==NULL) {+ indices=static_cast<DX8IndexBufferClass*>(index_buffer)->Get_Scratch_Indices()+start_index;+ break;+ }DX8_ErrorCode(static_cast<DX8IndexBufferClass*>(index_buffer)->index_buffer->Lock(start_index*sizeof(unsigned short),index_range*sizeof(unsigned short),@@ -264,6 +275,7 @@ IndexBufferClass::AppendLockClass::~AppendLockClass()DX8_THREAD_ASSERT();switch (index_buffer->Type()) {case BUFFER_TYPE_DX8:+ if (static_cast<DX8IndexBufferClass*>(index_buffer)->index_buffer==NULL) break;DX8_Assert();DX8_ErrorCode(static_cast<DX8IndexBufferClass*>(index_buffer)->index_buffer->Unlock());break;@@ -288,6 +300,15 @@ DX8IndexBufferClass::DX8IndexBufferClass(unsigned short index_count_,UsageType u{DX8_THREAD_ASSERT();WWASSERT(index_count);+ index_buffer=NULL;+ scratch_indices=NULL;++ // Same as the vertex buffer: no render device, no D3D buffer. See Create_Vertex_Buffer.+ if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ scratch_indices=W3DNEWARRAY unsigned short[index_count];+ return;+ }+unsigned usage_flags=D3DUSAGE_WRITEONLY|((usage&USAGE_DYNAMIC) ? D3DUSAGE_DYNAMIC : 0)|@@ -338,7 +359,8 @@ DX8IndexBufferClass::DX8IndexBufferClass(unsigned short index_count_,UsageType uDX8IndexBufferClass::~DX8IndexBufferClass(){- index_buffer->Release();+ if (index_buffer) index_buffer->Release();+ if (scratch_indices) delete [] scratch_indices;}// ----------------------------------------------------------------------------diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.hindex e73d17cba..c018a43d5 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.h@@ -180,9 +180,17 @@ public:void Copy(unsigned short* indices,unsigned start_index,unsigned index_count);inline IDirect3DIndexBuffer8* Get_DX8_Index_Buffer() { return index_buffer; }-++ // Plain memory standing in for the D3D buffer when there is no render device. Everything that+ // fills a buffer does so through the lock classes, and a run with no picture still fills them -+ // the terrain, the trees and the bridges all build theirs while the map loads, long before+ // anything would be drawn. Writing into this instead keeps every one of those callers honest+ // and costs a heap block that nothing ever reads.+ inline unsigned short* Get_Scratch_Indices() { return scratch_indices; }+private:IDirect3DIndexBuffer8* index_buffer; // actual dx8 index buffer+ unsigned short* scratch_indices; // used instead when there is no device};diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cppindex 31352d41f..c92a21a06 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cpp@@ -173,6 +173,11 @@ VertexBufferClass::WriteLockClass::WriteLockClass(VertexBufferClass* VertexBuffefvf_name));}#endif+ // No device means no D3D buffer; write into the scratch block instead.+ if (static_cast<DX8VertexBufferClass*>(VertexBuffer)->Get_DX8_Vertex_Buffer()==NULL) {+ Vertices=static_cast<DX8VertexBufferClass*>(VertexBuffer)->Get_Scratch_Vertices();+ break;+ }DX8_Assert();DX8_ErrorCode(static_cast<DX8VertexBufferClass*>(VertexBuffer)->Get_DX8_Vertex_Buffer()->Lock(0,@@ -200,6 +205,7 @@ VertexBufferClass::WriteLockClass::~WriteLockClass()WWDEBUG_SAY(("VertexBuffer->Unlock()\n"));#endifDX8_Assert();+ if (static_cast<DX8VertexBufferClass*>(VertexBuffer)->Get_DX8_Vertex_Buffer()==NULL) break;DX8_ErrorCode(static_cast<DX8VertexBufferClass*>(VertexBuffer)->Get_DX8_Vertex_Buffer()->Unlock());break;case BUFFER_TYPE_SORTING:@@ -239,6 +245,11 @@ VertexBufferClass::AppendLockClass::AppendLockClass(VertexBufferClass* VertexBuffvf_name));}#endif+ if (static_cast<DX8VertexBufferClass*>(VertexBuffer)->Get_DX8_Vertex_Buffer()==NULL) {+ Vertices=static_cast<DX8VertexBufferClass*>(VertexBuffer)->Get_Scratch_Vertices()+ +start_index*VertexBuffer->FVF_Info().Get_FVF_Size();+ break;+ }DX8_Assert();DX8_ErrorCode(static_cast<DX8VertexBufferClass*>(VertexBuffer)->Get_DX8_Vertex_Buffer()->Lock(start_index*VertexBuffer->FVF_Info().Get_FVF_Size(),@@ -266,6 +277,7 @@ VertexBufferClass::AppendLockClass::~AppendLockClass()#ifdef VERTEX_BUFFER_LOGWWDEBUG_SAY(("VertexBuffer->Unlock()\n"));#endif+ if (static_cast<DX8VertexBufferClass*>(VertexBuffer)->Get_DX8_Vertex_Buffer()==NULL) break;DX8_ErrorCode(static_cast<DX8VertexBufferClass*>(VertexBuffer)->Get_DX8_Vertex_Buffer()->Unlock());break;case BUFFER_TYPE_SORTING:@@ -404,7 +416,8 @@ DX8VertexBufferClass::~DX8VertexBufferClass()_DX8VertexBufferCount--;WWDEBUG_SAY(("Current vertex buffer count: %d\n",_DX8VertexBufferCount));#endif- VertexBuffer->Release();+ if (VertexBuffer) VertexBuffer->Release();+ if (ScratchVertices) delete [] ScratchVertices;}// ----------------------------------------------------------------------------@@ -432,6 +445,16 @@ void DX8VertexBufferClass::Create_Vertex_Buffer(UsageType usage)WWDEBUG_SAY(("Current vertex buffer count: %d\n",_DX8VertexBufferCount));#endif+ // A run with no render device has nothing to put a vertex buffer on. Hand out a plain heap+ // block instead: the terrain, the trees and the bridges all fill their buffers while the map+ // loads, long before anything would be drawn, and they have to write somewhere.+ if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ VertexBuffer=NULL;+ ScratchVertices=W3DNEWARRAY unsigned char[FVF_Info().Get_FVF_Size()*VertexCount];+ return;+ }+ ScratchVertices=NULL;+unsigned usage_flags=D3DUSAGE_WRITEONLY|((usage&USAGE_DYNAMIC) ? D3DUSAGE_DYNAMIC : 0)|diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.hindex fdf3ad1cb..156c84b41 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.h@@ -225,6 +225,10 @@ public:IDirect3DVertexBuffer8* Get_DX8_Vertex_Buffer() { return VertexBuffer; }+ // Plain memory standing in for the D3D buffer when there is no render device - see+ // DX8IndexBufferClass::Get_Scratch_Indices for why a run with no picture still fills buffers.+ unsigned char* Get_Scratch_Vertices() { return ScratchVertices; }+void Copy(const Vector3* loc, unsigned first_vertex, unsigned count);void Copy(const Vector3* loc, const Vector2* uv, unsigned first_vertex, unsigned count);void Copy(const Vector3* loc, const Vector3* norm, unsigned first_vertex, unsigned count);@@ -234,6 +238,7 @@ public:protected:IDirect3DVertexBuffer8* VertexBuffer;+ unsigned char* ScratchVertices; // used instead when there is no devicevoid Create_Vertex_Buffer(UsageType usage);};diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cppindex c8fade018..423592182 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp@@ -413,6 +413,26 @@ void DX8Wrapper::Do_Onetime_Device_Dependent_Inits(void)Set_Default_Global_Render_States();}+/*+** The subset of the list above that never calls D3D, for a run started with no render device.+** Deliberately a second list rather than a piece factored out of the first: the order in+** Do_Onetime_Device_Dependent_Inits is EA's and nothing here is worth the risk of disturbing it on+** the path that every player takes.+**+** What makes the subset necessary is that the rest of WW3D2 assumes all of it exists the moment+** anything is built - VertexMaterialClass::Get_Preset is reached from the constructor of almost+** every render object, and without Init() it walks an empty preset table.+*/+void DX8Wrapper::Do_Onetime_Device_Independent_Inits(void)+{+ TheDX8MeshRenderer.Init();+ BoxRenderObjClass::Init();+ VertexMaterialClass::Init();+ PointGroupClass::_Init(); // This needs the VertexMaterialClass to be initted+ ShatterSystem::Init();+ TextureLoader::Init();+}+inline DWORD F2DW(float f) { return *((unsigned*)&f); }void DX8Wrapper::Set_Default_Global_Render_States(void){diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.hindex 142801fd0..24cc0d527 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h@@ -264,6 +264,10 @@ public:** before the device is released.*/static void Do_Onetime_Device_Dependent_Inits(void);+ // The half of the above that never touches D3D: preset materials, the mesh renderer's+ // containers, the texture loader's thread. A run with no render device still needs these,+ // because the rest of WW3D2 assumes they exist the moment anything is built.+ static void Do_Onetime_Device_Independent_Inits(void);static void Do_Onetime_Device_Dependent_Shutdowns(void);static bool Is_Device_Lost() { return IsDeviceLost; }diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/missingtexture.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/missingtexture.cppindex 15cd73d02..b9715bc90 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/missingtexture.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/missingtexture.cpp@@ -33,13 +33,23 @@ static IDirect3DTexture8 * _MissingTexture = NULL;IDirect3DTexture8* MissingTexture::_Get_Missing_Texture(){- WWASSERT(_MissingTexture);+ // The stand-in checkerboard is a D3D texture built when the device was created. A run with no+ // device never built one, and every texture load in it ends up here, so hand back nothing+ // rather than dereferencing the null it used to. Nothing in such a run draws with the result.+ if (_MissingTexture == NULL) {+ return NULL;+ }+_MissingTexture->AddRef();return _MissingTexture;}IDirect3DSurface8* MissingTexture::_Create_Missing_Surface(){+ if (_MissingTexture == NULL) {+ return NULL;+ }+IDirect3DSurface8 *texture_surface = NULL;DX8_ErrorCode(_MissingTexture->GetSurfaceLevel(0, &texture_surface));D3DSURFACE_DESC texture_surface_desc;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cppindex c3e086050..b8b745397 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp@@ -1181,14 +1181,22 @@ Render2DSentenceClass::Build_Sentence (const WCHAR *text, int *hkX, int *hkY)return ;}+ // With no render device there is nowhere to rasterize a glyph: Allocate_New_Surface would ask+ // CreateImageSurface of a null device and take the process with it. Measure the text and stop+ // there, which is what justCalcExtents already exists to do - callers size their windows off+ // the extent and nothing is ever asked to draw the result.+ if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ Build_Sentence_Not_Centered(text, hkX, hkY, true);+ return;+ }if(Centered && (WrapWidth > 0 || wcschr(text,L'\n')))Build_Sentence_Centered(text, hkX, hkY);elseBuild_Sentence_Not_Centered(text, hkX, hkY);-+return;-+}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.cppindex f7068d95a..5e9a3db60 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.cpp@@ -930,6 +930,14 @@ void TextureClass::Apply_New_Surfaceif (d3d_tex) d3d_tex->Release();Poke_Texture(d3d_texture);//TextureLoadTask->Peek_D3D_Texture();++ // A run with no render device has no surface to hand over and no missing-texture stand-in+ // either, so this arrives null. Take it and stop: the size and format below are read off a+ // surface that does not exist.+ if (d3d_texture == NULL) {+ return;+ }+d3d_texture->AddRef();if (initialized) Initialized=true;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cppindex 70de2b9e9..303207f51 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp@@ -653,6 +653,11 @@ IDirect3DSurface8* TextureLoader::Load_Surface_Immediate(void TextureLoader::Request_Thumbnail(TextureBaseClass *tc){+ // See Request_Foreground_Loading: nothing to load into without a device.+ if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ return;+ }+// Grab the foreground lock. This prevents the foreground thread// from retiring any tasks related to this texture. It also// serializes calls to Request_Thumbnail from multiple threads.@@ -695,6 +700,12 @@ void TextureLoader::Request_Thumbnail(TextureBaseClass *tc)void TextureLoader::Request_Background_Loading(TextureBaseClass *tc){WWPROFILE(("TextureLoader::Request_Background_Loading()"));++ // See Request_Foreground_Loading: nothing to load into without a device.+ if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ return;+ }+// Grab the foreground lock. This prevents the foreground thread// from retiring any tasks related to this texture. It also// serializes calls to Request_Background_Loading from other@@ -726,6 +737,14 @@ void TextureLoader::Request_Background_Loading(TextureBaseClass *tc)void TextureLoader::Request_Foreground_Loading(TextureBaseClass *tc){WWPROFILE(("TextureLoader::Request_Foreground_Loading()"));++ // A run with no render device has nowhere to put a texture, and no missing-texture stand-in to+ // fall back on either - that one is built when the device is. Leaving the texture+ // uninitialised is correct here: nothing in such a run ever binds it.+ if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ return;+ }+// Grab the foreground lock. This prevents the foreground thread// from retiring the load tasks for this texture. It also// serializes calls to Request_Foreground_Loading from other@@ -1203,6 +1222,13 @@ bool TextureLoadTaskClass::Begin_Load(void){WWASSERT(TextureLoader::Is_DX8_Thread());+ // With no render device there is nothing to load a texture into, and the caps this would size+ // it against were never filled in. Refusing here leaves the texture object in place with no+ // surface behind it, which is what a run that never draws needs.+ if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ return false;+ }+bool loaded = false;// if allowed, begin a compressed load@@ -1289,6 +1315,12 @@ void TextureLoadTaskClass::End_Load(void)void TextureLoadTaskClass::Finish_Load(void){+ // No device, so no load and no missing-texture substitute either - that one is a D3D texture+ // built when the device was created, and without a device it was never built.+ if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ return;+ }+switch (State) {// NOTE: fall-through below is intentional.