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: five v2.1.0 crash reports, retail exe after a steam repair

Olcay Seyganfdd7df7e9477
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 500053374..46e4ce6b9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -641,6 +641,10 @@ found and fixed — EA's own, not port damage.**
- Pointing a worker at an ally's half-finished building no longer offers to finish it. The cursor promised to resume construction and the order it gave did nothing, because the check behind the cursor asked whether you were allied with whoever owned the site, and you are allied with yourself.
- Double-tapping 0 jumps the camera to that group.
- The mouse wheel no longer cancels a camera move already in progress.
+- The end of a match no longer crashes on the score screen when paratroopers were still in the air over water. Clearing the battlefield dropped them one last time, they drowned, and the debris they left behind went looking for a player who had already been cleared away.
+- Switching between fullscreen and windowed on Direct3D 9 no longer crashes. The graphics card can refuse a buffer for a moment while the screen changes, and the game wrote into the one it never got. It writes somewhere harmless now and asks again the next time it draws.
+- Closing the window while the game is still loading closes the game. The close was turned into a message stamped with your player, and no player exists that early.
+- Steam checking or repairing the game files no longer leaves you with a game that crashes the moment it starts. Steam puts its own original exe back and leaves this build's key bindings file in place, and the original read that file, found commands it had never heard of and gave up. The file has a name only this build looks for now, so the original starts as plain Zero Hour.
## The buildings nobody repairs, repair themselves
diff --git a/GeneralsMD/Code/Data/INI/CommandMap.ini b/GeneralsMD/Code/Data/INI/CommandMapReforged.ini
similarity index 96%
rename from GeneralsMD/Code/Data/INI/CommandMap.ini
rename to GeneralsMD/Code/Data/INI/CommandMapReforged.ini
index e8464e76f..d118684fd 100644
--- a/GeneralsMD/Code/Data/INI/CommandMap.ini
+++ b/GeneralsMD/Code/Data/INI/CommandMapReforged.ini
@@ -1,10 +1,16 @@
;//////////////////////////////////////////////////////////////////////////////
-;FILE: CommandMap.ini (SYSTEM) ////////////////////////////////////////////////
+;FILE: CommandMapReforged.ini (SYSTEM) ////////////////////////////////////////
;//////////////////////////////////////////////////////////////////////////////
;
; MASTER COPY - this is the tracked one. The build copies it to
-; Run/Data/INI/CommandMap.ini, which is where the game reads it from and which
-; is gitignored, so edit THIS file and rebuild (or copy it across by hand).
+; Run/Data/INI/CommandMapReforged.ini, which is where the game reads it from and
+; which is gitignored, so edit THIS file and rebuild (or copy it across by hand).
+;
+; It used to be Data\INI\CommandMap.ini, a name EA's own exe reads too. When
+; Steam put the retail generals.exe back over this build, that exe met the
+; commands below it has never heard of and died at start with "Error parsing
+; INI file 'Data\INI\CommandMap.ini'" - three crash reports on 2026-09-23 alone.
+; Under a name only this exe asks for, a retail exe starts as plain Zero Hour.
;
; Loose overlay, loaded after Data\<Language>\CommandMap.ini, so a block here
; overrides that file entry-for-entry and new commands can be added. Every
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index 12af71095..ccabf36a1 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -4,7 +4,7 @@
//
// Patch.str is the 1.04 string overlay from PatchData.big. The two original
// strings are kept; everything after them is this fork's, and every command
-// added to Data/INI/CommandMap.ini needs a pair here or Options > Keyboard
+// added to Data/INI/CommandMapReforged.ini needs a pair here or Options > Keyboard
// shows a blank row.
//
// Comments are '//' - GameText.cpp parseStringFile skips exactly that.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h b/GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h
index 25fad79c0..9f2b83b97 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h
@@ -388,7 +388,7 @@ public:
static void parseMetaMap(INI* ini);
/** Fill the Legacy list from the language's CommandMap.ini alone, which is the game's own map out
- * of its own archives. Everything this fork binds is in Data\INI\CommandMap.ini, and only the
+ * of its own archives. Everything this fork binds is in Data\INI\CommandMapReforged.ini, and only the
* Modern list reads that. */
void loadLegacyBindings( const AsciiString& languageMapFile );
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index e69766596..d94258a94 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -976,7 +976,7 @@ void GameEngine::init( int argc, char *argv[] )
AsciiString fname;
fname.format("Data\\%s\\CommandMap.ini", GetRegistryLanguage().str());
- initSubsystem(TheMetaMap,"TheMetaMap", MSGNEW("GameEngineSubsystem") MetaMap(), NULL, fname.str(), "Data\\INI\\CommandMap.ini");
+ initSubsystem(TheMetaMap,"TheMetaMap", MSGNEW("GameEngineSubsystem") MetaMap(), NULL, fname.str(), "Data\\INI\\CommandMapReforged.ini");
// Legacy mouse and keyboard answers to the game's own map and to nothing this fork binds
TheMetaMap->loadLegacyBindings(fname);
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cpp
index 8ae0b7f86..207b11bc5 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cpp
@@ -37,6 +37,8 @@
#include "GameLogic/GameLogic.h"
#include "GameLogic/Object.h"
+#include <typeinfo> // the machine's class name in the missing-state line, which is all Release logs
+
#ifdef _INTERNAL
// for occasional debugging...
@@ -537,8 +539,13 @@ State *StateMachine::internalGetState( StateID id )
if (i == m_stateMap.end())
{
DEBUG_CRASH( ("StateMachine::internalGetState(): Invalid state for object %s using state %d", m_owner->getTemplate()->getName().str(), id) );
- DEBUG_LOG(("Transisioning to state #d\n", (Int)id));
- DEBUG_LOG(("Attempting to recover - locating default state...\n"));
+ // DEBUG_CRASH is silent in Release, so this line is all a player's crash report carries: a
+ // v2.1.0 report came back naming neither the object nor the state, with "#d" for the number.
+ DEBUG_LOG(("%s on %s (id %d) has no state %d, in state %d, %d states defined, frame %d\n",
+ typeid(*this).name(), m_owner->getTemplate()->getName().str(), (Int)m_owner->getID(), (Int)id,
+ m_currentState ? (Int)m_currentState->getID() : -1, (Int)m_stateMap.size(),
+ (Int)TheGameLogic->getFrame()));
+ DEBUG_LOG(("Attempting to recover - locating default state %d...\n", (Int)m_defaultStateID));
i = m_stateMap.find(m_defaultStateID);
if (i == m_stateMap.end()) {
DEBUG_LOG(("Failed to located default state. Aborting...\n"));
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/ParachuteContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/ParachuteContain.cpp
index 024dee796..43ac24f02 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/ParachuteContain.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/ParachuteContain.cpp
@@ -472,7 +472,15 @@ void ParachuteContain::onContaining( Object *rider, Bool wasSelected )
//-------------------------------------------------------------------------------------------------
void ParachuteContain::onRemoving( Object *rider )
{
- OpenContain::onRemoving(rider);
+ OpenContain::onRemoving(rider);
+
+ // Ending a match deletes every object, and a paratrooper still over water left his chute
+ // through Object::onDestroy, "drowned" here, fired his death weapon and had it build debris for
+ // a player list already emptied: a null controller in Object's constructor, a v2.1.0 crash on
+ // the score screen. Only the clear-out is skipped. A rider deleted mid-match, by a script or
+ // with the plane he rode, still lands the way he did in v2.1.0, so its replays play back.
+ if (rider->isDestroyed() && TheGameLogic->isClearingGameData())
+ return;
const ParachuteContainModuleData* d = getParachuteContainModuleData();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
index ae899f343..4bd17ec5c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
@@ -4313,6 +4313,12 @@ void GameLogic::update( void )
#endif
}
+ /* A start held back by a movie has set the game mode and started the recorder, but the match
+ does not exist yet: TheGameInfo is still NULL and the CRC below reads it. A skirmish asked for
+ over -control while the EA logo was still playing faulted there on its first frame. */
+ if (isIntroMoviePlaying())
+ return;
+
// send the current time to the GameClient
DEBUG_ASSERTCRASH(TheGameLogic == this, ("hmm, TheGameLogic is not right"));
UnsignedInt now = TheGameLogic->getFrame();
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp
index 0f094a36a..a4023adde 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp
@@ -330,6 +330,10 @@ Int WaterTracksObj::render(DX8VertexBufferClass *vertexBuffer, Int batchStart)
unsigned byteOffset;
unsigned lockFlags;
+ // the buffer is made right after a device reset, which is when the card can refuse it
+ if (vertexBuffer->Get_DX8_Vertex_Buffer() == NULL)
+ return batchStart;
+
if (batchStart < (WATER_VB_PAGES*WATER_STRIP_X*WATER_STRIP_Y-m_x*m_y))
{ //we have room in current VB, append new verts
byteOffset = batchStart*vertexSize;
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cpp
index 1146aef67..245649cc7 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cpp
@@ -357,31 +357,40 @@ DX8IndexBufferClass::DX8IndexBufferClass(unsigned short index_count_,UsageType u
return;
}
- WWDEBUG_SAY(("Index buffer creation failed, trying to release assets...\n"));
-
- // Vertex buffer creation failed, so try releasing least used textures and flushing the mesh cache.
-
- // Free all textures that haven't been used in the last 5 seconds
- TextureClass::Invalidate_Old_Unused_Textures(5000);
-
- // Invalidate the mesh cache
- WW3D::_Invalidate_Mesh_Cache();
-
- // Try again...
- ret=DX8Wrapper::_Get_D3D_Device()->CreateIndexBuffer(
- sizeof(WORD)*index_count,
- usage_flags,
- D3DFMT_INDEX16,
- (usage&USAGE_DYNAMIC) ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED,
- &index_buffer,
- NULL); // pSharedHandle, D3D9's extra parameter, reserved and always null
-
- if (SUCCEEDED(ret)) {
- WWDEBUG_SAY(("...Index buffer creation succesful\n"));
+ // Not for a dynamic buffer, which is asked for mid-frame: see Create_Vertex_Buffer.
+ if (!(usage&USAGE_DYNAMIC)) {
+ WWDEBUG_SAY(("Index buffer creation failed, trying to release assets...\n"));
+
+ // Vertex buffer creation failed, so try releasing least used textures and flushing the mesh cache.
+
+ // Free all textures that haven't been used in the last 5 seconds
+ TextureClass::Invalidate_Old_Unused_Textures(5000);
+
+ // Invalidate the mesh cache
+ WW3D::_Invalidate_Mesh_Cache();
+
+ // Try again...
+ ret=DX8Wrapper::_Get_D3D_Device()->CreateIndexBuffer(
+ sizeof(WORD)*index_count,
+ usage_flags,
+ D3DFMT_INDEX16,
+ D3DPOOL_MANAGED,
+ &index_buffer,
+ NULL); // pSharedHandle, D3D9's extra parameter, reserved and always null
+
+ if (SUCCEEDED(ret)) {
+ WWDEBUG_SAY(("...Index buffer creation succesful\n"));
+ return;
+ }
}
- // If it still fails it is fatal
+ // Not fatal and never was; a refused buffer writes to scratch like Create_Vertex_Buffer's,
+ // and loses its Direct3D 11 twin for the same reason.
DX8_ErrorCode(ret);
+ index_buffer=NULL;
+ scratch_indices=W3DNEWARRAY unsigned short[index_count];
+ delete dx11_twin;
+ dx11_twin=NULL;
}
// ----------------------------------------------------------------------------
@@ -484,6 +493,11 @@ DynamicIBAccessClass::WriteLockClass::WriteLockClass(DynamicIBAccessClass* ib_ac
case BUFFER_TYPE_DYNAMIC_DX8:
WWASSERT(DynamicIBAccess);
// WWASSERT(!dynamic_dx8_index_buffer->Engine_Refs());
+ if (static_cast<DX8IndexBufferClass*>(DynamicIBAccess->IndexBuffer)->Get_DX8_Index_Buffer()==NULL) {
+ Indices=static_cast<DX8IndexBufferClass*>(DynamicIBAccess->IndexBuffer)->Get_Scratch_Indices();
+ Indices+=DynamicIBAccess->IndexBufferOffset;
+ break;
+ }
DX8_Assert();
DX8_ErrorCode(
static_cast<DX8IndexBufferClass*>(DynamicIBAccess->IndexBuffer)->Get_DX8_Index_Buffer()->Lock(
@@ -517,6 +531,7 @@ DynamicIBAccessClass::WriteLockClass::~WriteLockClass()
DX8_THREAD_ASSERT();
switch (DynamicIBAccess->Get_Type()) {
case BUFFER_TYPE_DYNAMIC_DX8:
+ if (static_cast<DX8IndexBufferClass*>(DynamicIBAccess->IndexBuffer)->Get_DX8_Index_Buffer()==NULL) break;
DX8_Assert();
DX11Lock.End();
DX8_ErrorCode(static_cast<DX8IndexBufferClass*>(DynamicIBAccess->IndexBuffer)->Get_DX8_Index_Buffer()->Unlock());
@@ -550,6 +565,14 @@ void DynamicIBAccessClass::Allocate_DX8_Dynamic_Buffer()
if (_DynamicDX8IndexBufferSize<DEFAULT_IB_SIZE) _DynamicDX8IndexBufferSize=DEFAULT_IB_SIZE;
}
+ // One made while the device refused buffers is a scratch block; try for a real one again, but
+ // only once the device says it is back, not on every draw while it still refuses
+ if (_DynamicDX8IndexBuffer && _DynamicDX8IndexBuffer->Get_DX8_Index_Buffer()==NULL
+ && DX8Wrapper::_Get_D3D_Device()!=NULL
+ && DX8Wrapper::_Get_D3D_Device()->TestCooperativeLevel()==D3D_OK) {
+ REF_PTR_RELEASE(_DynamicDX8IndexBuffer);
+ }
+
// Create a new vb if one doesn't exist currently
if (!_DynamicDX8IndexBuffer) {
unsigned usage=DX8IndexBufferClass::USAGE_DYNAMIC;
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cpp
index 86590f702..9901c01db 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cpp
@@ -510,36 +510,51 @@ void DX8VertexBufferClass::Create_Vertex_Buffer(UsageType usage)
return;
}
- WWDEBUG_SAY(("Vertex buffer creation failed, trying to release assets...\n"));
-
- // Vertex buffer creation failed, so try releasing least used textures and flushing the mesh cache.
-
- // Free all textures that haven't been used in the last 5 seconds
- TextureClass::Invalidate_Old_Unused_Textures(5000);
-
- // Invalidate the mesh cache
- WW3D::_Invalidate_Mesh_Cache();
-
- //@todo: Find some way to invalidate the textures too
- // D3D9 replaced ResourceManagerDiscardBytes with EvictManagedResources, which takes
- // no byte count and returns nothing useful to act on.
- DX8Wrapper::_Get_D3D_Device()->EvictManagedResources();
-
- // Try again...
- ret=DX8Wrapper::_Get_D3D_Device()->CreateVertexBuffer(
- FVF_Info().Get_FVF_Size()*VertexCount,
- usage_flags,
- FVF_Info().Get_FVF(),
- (usage&USAGE_DYNAMIC) ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED,
- &VertexBuffer,
- NULL); // pSharedHandle, D3D9's extra parameter, reserved and always null
-
- if (SUCCEEDED(ret)) {
- WWDEBUG_SAY(("...Vertex buffer creation succesful\n"));
+ // Not for a dynamic buffer. Those are asked for in the middle of a frame, from inside
+ // DX8MeshRendererClass::Flush, and _Invalidate_Mesh_Cache deletes the very container that is
+ // rendering and the list Flush is walking. Evicting managed memory does nothing for a
+ // D3DPOOL_DEFAULT buffer on a device that is refusing anyway.
+ if (!(usage&USAGE_DYNAMIC)) {
+ WWDEBUG_SAY(("Vertex buffer creation failed, trying to release assets...\n"));
+
+ // Vertex buffer creation failed, so try releasing least used textures and flushing the mesh cache.
+
+ // Free all textures that haven't been used in the last 5 seconds
+ TextureClass::Invalidate_Old_Unused_Textures(5000);
+
+ // Invalidate the mesh cache
+ WW3D::_Invalidate_Mesh_Cache();
+
+ //@todo: Find some way to invalidate the textures too
+ // D3D9 replaced ResourceManagerDiscardBytes with EvictManagedResources, which takes
+ // no byte count and returns nothing useful to act on.
+ DX8Wrapper::_Get_D3D_Device()->EvictManagedResources();
+
+ // Try again...
+ ret=DX8Wrapper::_Get_D3D_Device()->CreateVertexBuffer(
+ FVF_Info().Get_FVF_Size()*VertexCount,
+ usage_flags,
+ FVF_Info().Get_FVF(),
+ D3DPOOL_MANAGED,
+ &VertexBuffer,
+ NULL); // pSharedHandle, D3D9's extra parameter, reserved and always null
+
+ if (SUCCEEDED(ret)) {
+ WWDEBUG_SAY(("...Vertex buffer creation succesful\n"));
+ return;
+ }
}
- // If it still fails it is fatal
+ // It was never fatal: DX8_ErrorCode only logs. A device that is lost for a moment, which a
+ // window mode change on Direct3D 9 can leave it, refuses a D3DPOOL_DEFAULT buffer, and the next
+ // lock of the null buffer faulted. Writes go to a scratch block instead, the way they do with
+ // no device at all, and DX8Wrapper::Draw skips a draw from it on both devices. The twin goes
+ // too: nothing would ever fill it, and Direct3D 11 would draw it anyway.
DX8_ErrorCode(ret);
+ VertexBuffer=NULL;
+ ScratchVertices=W3DNEWARRAY unsigned char[FVF_Info().Get_FVF_Size()*VertexCount];
+ delete DX11Twin;
+ DX11Twin=NULL;
/* Old Code
DX8CALL(CreateVertexBuffer(
@@ -840,6 +855,14 @@ void DynamicVBAccessClass::Allocate_DX8_Dynamic_Buffer()
if (_DynamicDX8VertexBufferSize<DEFAULT_VB_SIZE) _DynamicDX8VertexBufferSize=DEFAULT_VB_SIZE;
}
+ // One made while the device refused buffers is a scratch block; try for a real one again, but
+ // only once the device says it is back, not on every draw while it still refuses
+ if (_DynamicDX8VertexBuffer && _DynamicDX8VertexBuffer->Get_DX8_Vertex_Buffer()==NULL
+ && DX8Wrapper::_Get_D3D_Device()!=NULL
+ && DX8Wrapper::_Get_D3D_Device()->TestCooperativeLevel()==D3D_OK) {
+ REF_PTR_RELEASE(_DynamicDX8VertexBuffer);
+ }
+
// Create a new vb if one doesn't exist currently
if (!_DynamicDX8VertexBuffer) {
unsigned usage=DX8VertexBufferClass::USAGE_DYNAMIC;
@@ -930,6 +953,12 @@ DynamicVBAccessClass::WriteLockClass::WriteLockClass(DynamicVBAccessClass* dynam
WWASSERT(_DynamicDX8VertexBuffer);
// WWASSERT(!_DynamicDX8VertexBuffer->Engine_Refs());
+ if (static_cast<DX8VertexBufferClass*>(DynamicVBAccess->VertexBuffer)->Get_DX8_Vertex_Buffer()==NULL) {
+ Vertices=(VertexFormatXYZNDUV2*)static_cast<DX8VertexBufferClass*>(DynamicVBAccess->VertexBuffer)->Get_Scratch_Vertices();
+ Vertices+=DynamicVBAccess->VertexBufferOffset;
+ break;
+ }
+
DX8_Assert();
// Lock with discard contents if the buffer offset is zero
DX8_ErrorCode(static_cast<DX8VertexBufferClass*>(DynamicVBAccess->VertexBuffer)->Get_DX8_Vertex_Buffer()->Lock(
@@ -972,6 +1001,7 @@ DynamicVBAccessClass::WriteLockClass::~WriteLockClass()
WWDEBUG_SAY(("DynamicVertexBuffer->Unlock()\n"));
*/
#endif
+ if (static_cast<DX8VertexBufferClass*>(DynamicVBAccess->VertexBuffer)->Get_DX8_Vertex_Buffer()==NULL) break;
DX8_Assert();
DX11Lock.End();
DX8_ErrorCode(static_cast<DX8VertexBufferClass*>(DynamicVBAccess->VertexBuffer)->Get_DX8_Vertex_Buffer()->Unlock());
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
index 26e79d0c4..0f2d4f334 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
@@ -2445,6 +2445,9 @@ void DX8Wrapper::Draw_Sorting_IB_VB(
}
}
+ // refused by the card, as in Draw: nothing to draw from on either device
+ if (static_cast<DX8VertexBufferClass*>(dyn_vb_access.VertexBuffer)->Get_DX8_Vertex_Buffer()==NULL) return;
+
DX8CALL(SetStreamSource(
0,
static_cast<DX8VertexBufferClass*>(dyn_vb_access.VertexBuffer)->Get_DX8_Vertex_Buffer(),
@@ -2487,6 +2490,8 @@ void DX8Wrapper::Draw_Sorting_IB_VB(
}
}
+ if (static_cast<DX8IndexBufferClass*>(dyn_ib_access.IndexBuffer)->Get_DX8_Index_Buffer()==NULL) return;
+
// D3D8 handed SetIndices the base vertex index; D3D9 takes it on the draw call
// instead, so it travels with the DrawIndexedPrimitive below.
DX8CALL(SetIndices(
@@ -2608,6 +2613,16 @@ void DX8Wrapper::Draw(
// Debug feature to disable triangle drawing...
if (!_Is_Triangle_Draw_Enabled()) return;
+ // A buffer the card refused is a scratch block with no Direct3D buffer and no twin behind it
+ // (Create_Vertex_Buffer), so neither device has anything to draw from; skip it on both.
+ const bool vertices_refused = render_state.vertex_buffers[0]
+ && (render_state.vertex_buffer_types[0]==BUFFER_TYPE_DX8 || render_state.vertex_buffer_types[0]==BUFFER_TYPE_DYNAMIC_DX8)
+ && static_cast<DX8VertexBufferClass*>(render_state.vertex_buffers[0])->Get_DX8_Vertex_Buffer()==NULL;
+ const bool indices_refused = render_state.index_buffer
+ && (render_state.index_buffer_type==BUFFER_TYPE_DX8 || render_state.index_buffer_type==BUFFER_TYPE_DYNAMIC_DX8)
+ && static_cast<DX8IndexBufferClass*>(render_state.index_buffer)->Get_DX8_Index_Buffer()==NULL;
+ if (vertices_refused || indices_refused) return;
+
#ifdef MESH_RENDER_SNAPSHOT_ENABLED
if (WW3D::Is_Snapshot_Activated()) {
unsigned long passes=0;
diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cpp
index 3dcec94fb..b24987eae 100644
--- a/GeneralsMD/Code/Main/WinMain.cpp
+++ b/GeneralsMD/Code/Main/WinMain.cpp
@@ -58,6 +58,7 @@
#include "Common/SafeDisc/CdaPfn.h"
#include "Common/StackDump.h"
#include "Common/MessageStream.h"
+#include "Common/PlayerList.h"
#include "Common/Registry.h"
#include "Common/Team.h"
#include "GameClient/InGameUI.h"
@@ -134,6 +135,15 @@ static Bool isCursorOverWindow( void )
return PtInRect( &windowRect, cursor ) != 0;
}
+//-------------------------------------------------------------------------------------------------
+/** A GameMessage stamps itself with the local player, so none can be made until the player list
+ * exists. A window closed while the game was still loading used to fault in that constructor. */
+//-------------------------------------------------------------------------------------------------
+static Bool canPostQuitMessage( void )
+{
+ return TheMessageStream != NULL && ThePlayerList != NULL && ThePlayerList->getLocalPlayer() != NULL;
+}
+
static HBITMAP gLoadScreenBitmap = NULL;
//#define DEBUG_WINDOWS_MESSAGES
@@ -427,17 +437,25 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
// guarded like the focus handlers below: these messages can arrive before the
// engine is up and, more often, while it is tearing down - a close or end-session
// that lands after TheMessageStream is gone used to fault right here.
- if (TheMessageStream)
+ if (canPostQuitMessage())
TheMessageStream->appendMessage(GameMessage::MSG_META_DEMO_INSTANT_QUIT);
return 0; //don't allow Windows to shutdown while game is running.
}
// ------------------------------------------------------------------------
case WM_CLOSE:
- if (TheGameEngine && !TheGameEngine->getQuitting() && TheMessageStream)
+ if (TheGameEngine && !TheGameEngine->getQuitting())
{
//user is exiting without using the menus
+ // Closed while still loading: nothing can carry a message yet, so the engine is
+ // told to stop and execute() never starts its loop.
+ if (!canPostQuitMessage())
+ {
+ TheGameEngine->setQuitting(TRUE);
+ return 0;
+ }
+
//This method didn't work in cinematics because we don't process messages.
//But it's the cleanest way to exit that's similar to using menus.
TheMessageStream->appendMessage(GameMessage::MSG_META_DEMO_INSTANT_QUIT);