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(gameengine): survive v3.3.0 mod crashes, logic thread off again

Olcay Seygan14d2496d2bcb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d275d9269..ab3d2a9e2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -191,7 +191,8 @@ found and fixed — EA's own, not port damage.**
- The match plays at the speed it always did. Every speed, delay, reload and build time in the game's data was converted to the shorter step, so a Crusader still fires every two seconds. The balance is the one you know.
- Mission timers keep EA's clock. A map's countdown still ticks 30 times a second, because the missions read a running timer's number and act on it: the second American mission declares victory when its "Win" timer drops below 1700, and on the first 60-step builds that came after 38 seconds instead of 10. The cutscene cues, the random music pick in the campaigns and the generals' challenges, the shell map's camera loop and the lightning on Eastern Everglades and Rocky Rampage were off the same way, 30 maps in all, and run on their original timing again. Custom maps get the same.
- Normal speed is 60 steps a second. Turbo mode, the one other speed a match can have, runs 120 of the same steps a second (see Turbo mode above). Replays still play as fast as you ask.
-- The battle's arithmetic now runs on a thread of its own, beside the drawing. The game used to work out a step and then draw, one after the other, so a heavy step stalled the picture. Now the screen keeps drawing while the next step is worked out, and it pays most in the late game, where the steps are heaviest. In a late 4-player match, uncapped, frames slower than 16.7 ms (one 60 Hz refresh) fell from 23% to 0.8%, the slowest one frame in a hundred fell from 24.0 to 16.5 ms live and from 16.0-16.5 to 10.6-12.5 ms in a replay, and the average frame went from 15.2 to 11.8 ms. The battle still takes 60 steps a second, no more and no fewer. Network games keep each step in step with the other machines as before and do not overlap yet. If you want the old one-after-the-other loop back, start the game with `-logicthread 0`.
+- The battle's arithmetic can run on a thread of its own, beside the drawing. The game works out a step and then draws, one after the other, so a heavy step stalls the picture; start it with `-logicthread 1` and the screen keeps drawing while the next step is worked out, which pays most in the late game, where the steps are heaviest. In a late 4-player match, uncapped, frames slower than 16.7 ms (one 60 Hz refresh) fell from 23% to 0.8%, the slowest one frame in a hundred fell from 24.0 to 16.5 ms live and from 16.0-16.5 to 10.6-12.5 ms in a replay, and the average frame went from 15.2 to 11.8 ms. The battle still takes 60 steps a second, no more and no fewer. Network games keep each step in step with the other machines as before and do not overlap yet.
+- That thread is off by default again. It was on from 3.2.0, and the crash reports from 3.3.0 traced the random crashes in the middle of a match to the drawing and the battle writing to the same memory at the same moment. The game works a step out between frames now, as it did before 3.2.0. Two of those collisions are fixed, one over the smoke and fire both sides create and one in the work a step leaves for the screen, which could run twice. The rest are still being hunted, so `-logicthread 1` is for whoever wants the smoother late game and accepts the risk.
- Opening the pause menu no longer makes boats snap to a different angle or parked aircraft sink into the carrier deck. Boats keep their rocking angle and aircraft remain above the deck while the game is paused.
- Replays and games saved in the middle of a match from earlier versions will not load in this one. The "Mission Start" saves a campaign makes between missions do, and every campaign mission can be picked from the campaign menu. A player on an earlier version cannot join a match with a player on this version, whichever of them hosts, so a LAN party needs everyone on the same build.
- Guns fire at their 2003 rate again. After a shot the game goes back to aiming for a step before it can fire again, which at 30 steps put a 100 millisecond Quad Cannon on a shot every 0.133 seconds; at 60 the same loop fired it every 0.100, a third faster. Shot delays and reloads are rounded to the old step and a gun's next shot is held to the old rhythm, so every weapon fires on the frames it did in 2003. A turret with no turning speed in its data rose twice as fast as it should, aircraft weighed their thrust against gravity at half strength, and a unit hit on the step before still counted as untouched for stealth. All three keep EA's timing now.
@@ -271,6 +272,16 @@ found and fixed — EA's own, not port damage.**
- A `-mod` path with `.` or `..` in it is refused. An archive counts as your mod's only when it was loaded for that mod. Two mods under `-modfactions` that define a command set with the same name both load now, and the later one wins.
- A computer player on a mod's Helix no longer crashes the match when it sends the Helix on a bombing raid. The AI picked its raiders by the bomb upgrade on the Helix's buttons, and Contra's Nuke General Helix (under `-modfactions` beside ShockWave) has that upgrade without the napalm bomb the raid drops. A Helix without that bomb now stays with the army.
- Under `-modfactions` a plain number in a model or sound line stays a number. A mod's own art gets the mod's mark in front of its name, and a mod file named with nothing but a number, a 6.dds say, had an animation's repeat count, the 6 in "0 6", marked as if it named that file, after which it no longer read as a number. That is our best reading of why ShockWave and Project Raptor together stopped while loading Project Raptor's Air Force General; we do not have that mod to check.
+- A mod no longer crashes the match in its first second when Turkiye (Experimental) sits in a seat. Turkiye's buildings are made from America's, and under a mod without the American base they come from Turkiye had no command center to start with. Such a mod now leaves Turkiye out of the army list and out of every Random draw.
+- Generals' Challenge leaves out a general the mod cannot field. A mod's Challenge list can name a general whose campaign, maps, opponents or army are missing from its files, and picking him crashed the game as the battle started. His portrait stays off the screen now.
+- A mission saved under a different mod, or under game data that has changed since, says it cannot be loaded instead of crashing the game.
+- An INI file that stops the game at startup names itself. The crash report gives the file and the line it stopped on, with what it found there, where it used to say only "Uncaught Exception during initialization." A file saved with a UTF-8 byte order mark, which some editors add, loads; the mark used to hide the first block's name and the whole file was refused.
+- A mod that keeps command buttons or command sets among its unit files gets a crash report naming the file and where those blocks belong. The game used to go down reading them with nothing to say.
+- Under `-modfactions` a mod's own lists named after a keyword, such as `OCL:` or `FX:`, are found. The name behind the keyword went without the mod's mark, so the game looked for a list of that name outside the mod.
+- A mod's helicopter that has nothing to fly with in the state it is shot down in falls and spins to the ground like any other, instead of crashing the game.
+- A build button whose requirement names a unit the mod never made shows its tooltip with the requirement listed by name. Hovering it used to crash the game.
+- A vehicle a mod gives two passenger holds no longer crashes the game. The second hold took riders in where nothing else looked, so a passenger who died stayed aboard, and the next time the vehicle seated its riders it reached for him.
+- A network game or a replay on a map this machine cannot read goes back to the menu. It used to deal out the start positions as if the map had eight, while the machines that had it dealt over the map's own, and the game split from the first second.
## One interface
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/INI.h b/GeneralsMD/Code/GameEngine/Include/Common/INI.h
index e5277ba77..e53f7bb57 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/INI.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/INI.h
@@ -229,6 +229,7 @@ private:
};
static Bool isAsset( const Names &names, const std::string &word );
static Bool isAssetField( const std::string &field ); ///< a field whose value names a model, animation, texture or sound file
+ static size_t namedAfterKeyword( const std::string &word ); ///< "OCL:X" gives 4, where the name starts; 0 for any other word
typedef Bool (ModNamespace::*WordTest)( const std::string &word, Bool assetField ) const;
Bool isNameOrAsset( const std::string &word, Bool assetField ) const;
Bool isModLabel( const std::string &word, Bool assetField ) const;
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/INIException.h b/GeneralsMD/Code/GameEngine/Include/Common/INIException.h
index ecd9b7353..915ea5df9 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/INIException.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/INIException.h
@@ -43,10 +43,13 @@ public:
}
}
+ // The compiler's copy shared the buffer, and a catch by value deleted it twice
+ INIException(const INIException& other) : INIException(other.mFailureMessage) {}
+
+ INIException& operator=(const INIException&) = delete;
+
~INIException()
{
- if (mFailureMessage) {
- delete [] mFailureMessage;
- }
+ delete [] mFailureMessage;
}
};
\ No newline at end of file
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
index 09c15b92d..2686af56c 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
@@ -38,8 +38,8 @@ class Drawable;
class Player;
/**
- * `-logicthread 0` runs the tick on the main thread, as it always ran.
- * `-logicthread 1`, the default, hands every tick to a dedicated thread; outside a network game
+ * `-logicthread 0`, the default since v3.3.0's crash reports, runs the tick on the main thread.
+ * `-logicthread 1` hands every tick to a dedicated thread; outside a network game
* the render draws beside it (phases 3 and 4), reading only the copies taken at the sync point.
* `-logicthread 2` adds jitter to the tick to shake out races.
*
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/PlayerTemplate.h b/GeneralsMD/Code/GameEngine/Include/Common/PlayerTemplate.h
index 3fa0be7cf..9ed0909b8 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/PlayerTemplate.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/PlayerTemplate.h
@@ -157,6 +157,8 @@ protected:
private:
+ friend class PlayerTemplateStore; ///< postProcessLoad empties a start template the loaded objects lack
+
NameKeyType m_nameKey;
Int m_modIndex;
UnicodeString m_displayName;
@@ -221,6 +223,7 @@ public:
virtual void init();
virtual void reset();
virtual void update();
+ virtual void postProcessLoad();
static void parsePlayerTemplateDefinition( INI* ini );
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/CampaignManager.h b/GeneralsMD/Code/GameEngine/Include/GameClient/CampaignManager.h
index ec76111d4..1248eef31 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/CampaignManager.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/CampaignManager.h
@@ -131,6 +131,7 @@ public:
Mission *getCurrentMission( void ); ///< Returns a point to the current mission
Mission *gotoNextMission( void ); ///< Set the next mission as the current Mission, and returns a point to it
void setCampaignAndMission( AsciiString campaign, AsciiString mission ); ///< Sets the campaing and Mission we're on
+ Campaign *findCampaign( AsciiString campaign ); ///< the campaign of that name, NULL when the data has none; changes nothing
void setCampaign( AsciiString campaign ); ///< sets the campaign and set's it's first mission
AsciiString getCurrentMap( void ); ///< Get the map located in m_currentMission;
enum { INVALID_MISSION_NUMBER = -1 };
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h
index dd00b15ad..4284421b6 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h
@@ -1075,6 +1075,9 @@ public:
void friend_renumberParticleSystem( ParticleSystem *particleSystem, ParticleSystemID oldID );
/// a system a tick made waits here for its build after the tick (ParticleSystem::buildClientPart)
void friend_addShell( ParticleSystem *shell, Bool createSlaves );
+ /// LogicThread::OverlapWindow::close, once the tick beside the render is done: what the render
+ /// made inside the window joins the list and the lookup
+ void friend_fileWindowSystems( void );
protected:
@@ -1101,6 +1104,7 @@ protected:
Int m_localPlayerIndex; ///<used to tell particle systems which particles can be skipped due to player shroud status
std::vector<ParticleSystem *> m_independentUpdates; ///< this update's systems whose particles go to the job pool; kept so it does not reallocate
std::vector<ParticleSystem *> m_shells; ///< made inside this tick, built after it; reset() deletes any a cleared game left
+ std::vector<ParticleSystem *> m_windowSystems; ///< built by the main thread inside the overlap window, filed when it closes; the tick reads the list and the lookup beside the render
private:
TemplateMap m_templateMap; ///< a hash map of all particle system templates
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index 2573de4ef..ad5118cb1 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -1516,7 +1516,7 @@ void GameEngine::init( int argc, char *argv[] )
why.format("GameEngine::init failed with ErrorCode 0x%08x.", (UnsignedInt)ec);
RELEASE_CRASH((why.str()));
}
- catch (INIException e)
+ catch (const INIException &e)
{
if (e.mFailureMessage)
RELEASE_CRASH((e.mFailureMessage));
@@ -3432,7 +3432,7 @@ void GameEngine::execute( void )
// compute a frame
update();
}
- catch (INIException e)
+ catch (const INIException &e)
{
// Release CRASH doesn't return, so don't worry about executing additional code.
if (e.mFailureMessage)
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
index 9645f88eb..ba828431b 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
@@ -289,14 +289,13 @@ void INI::prepFile( AsciiString filename, INILoadType loadType )
if( m_file == NULL )
{
- // These INI_* constants live in an *unnamed* enum, so GameEngine::init's
- // catch (ErrorCode) never matches them and they all end up in its catch (...),
- // which reports "Uncaught Exception during initialization." and nothing else.
- // Leave a trace in g_LastErrorDump so ReleaseCrashInfo.txt names the file --
- // in a Release build DEBUG_CRASH above compiles to nothing.
- g_LastErrorDump.format("INI::prepFile could not open '%s'\n", filename.str());
+ // The INI_* codes live in an *unnamed* enum, so GameEngine::init's catch (ErrorCode)
+ // never matched INI_CANT_OPEN_FILE and its catch (...) said only "Uncaught Exception
+ // during initialization.". An INIException carries the name to the crash report.
DEBUG_CRASH(( "INI::load, cannot open file '%s'\n", filename.str() ));
- throw INI_CANT_OPEN_FILE;
+ char buff[1024];
+ snprintf(buff, ARRAY_SIZE(buff), "Could not open INI file '%s'\n", filename.str());
+ throw INIException(buff);
} // end if
@@ -474,20 +473,33 @@ void INI::load( AsciiString filename, INILoadType loadType, Xfer *pXfer )
{
DEBUG_ASSERTCRASH( 0, ("[LINE: %d - FILE: '%s'] Unknown block '%s'\n",
getLineNum(), getFilename().str(), token ) );
- throw INI_UNKNOWN_TOKEN;
+ // a stray End, a misspelt block name: name it, since the catch below cannot
+ char buff[1024];
+ snprintf(buff, ARRAY_SIZE(buff), "Error parsing INI file '%s' (line %d: unknown block '%s')\n",
+ m_filename.str(), m_lineNum, token);
+ throw INIException(buff);
}
-
- } // end if
-
+
+ } // end if
+
} // end while
}
- catch (...)
+ catch (INIException &)
{
unPrepFile();
-
- // propagate the exception.
throw;
}
+ catch (...)
+ {
+ /* Anything else thrown between blocks (a bare INI_* code from readLine, a fault the SEH
+ translator turned into a throw) used to reach GameEngine::init's catch (...) as
+ "Uncaught Exception during initialization." with no file named. */
+ char buff[1024];
+ snprintf(buff, ARRAY_SIZE(buff), "Error reading INI file '%s' (reached line %d: '%s')\n",
+ m_filename.str(), m_lineNum, m_buffer);
+ unPrepFile();
+ throw INIException(buff);
+ }
unPrepFile();
@@ -576,6 +588,9 @@ void ModNamespace::scanMods( void )
char *contents = file->readEntireAndClose();
std::string text( contents, size );
delete [] contents;
+ // as INI::readLine: a byte order mark would hide the first block's name
+ if (text.compare( 0, 3, "\xEF\xBB\xBF" ) == 0)
+ text.erase( 0, 3 );
for (size_t start = 0; start < text.size(); )
{
size_t end = text.find( '\n', start );
@@ -818,8 +833,9 @@ Bool ModNamespace::prefixWords( char *line, size_t capacity, WordTest test ) con
first = FALSE;
continue;
}
- // a file field may name a subfolder ("Sub\x.mp3"); the file is its last part
- const size_t at = assetField ? lastPathPart( word ) : 0;
+ // a file field may name a subfolder ("Sub\x.mp3"); the file is its last part. "OCL:OCL_X" is a
+ // parser's keyword and a name: only the name may be the mod's
+ const size_t at = assetField ? lastPathPart( word ) : namedAfterKeyword( word );
out.append( word, 0, at );
if ((this->*test)( word.substr( at ), assetField ))
out += prefix;
@@ -837,6 +853,23 @@ size_t ModNamespace::lastPathPart( const std::string &word )
return slash == std::string::npos ? 0 : slash + 1;
}
+size_t ModNamespace::namedAfterKeyword( const std::string &word )
+{
+ // the keywords the colon parsers (OCLUpdate, BridgeBehavior, BoneFXUpdate, TransitionDamageFX,
+ // AutoDepositUpdate) read before a name; a CSF label such as "OBJECT:Ranger" is none of them
+ static const char *const Keywords[] = { "Faction", "OCL", "FX", "FXList", "PSys", "UpgradeType" };
+ const size_t colon = word.find( ':' );
+ if (colon == std::string::npos)
+ return 0;
+ const std::string keyword = word.substr( 0, colon );
+ for (size_t i = 0; i < ARRAY_SIZE( Keywords ); ++i)
+ {
+ if (strcasecmp( keyword.c_str(), Keywords[ i ] ) == 0)
+ return colon + 1;
+ }
+ return 0;
+}
+
Bool ModNamespace::findRetailName( const AsciiString &name, ModNameType type, AsciiString *retailName ) const
{
const char *text = name.str();
@@ -926,6 +959,11 @@ void INI::readLine( void )
// increase our line count
m_lineNum++;
+ // A UTF-8 byte order mark, which some editors write, glued itself to the first word and the
+ // block was unknown. No file that had one ever loaded, so dropping it moves no checksum.
+ if (m_lineNum == 1 && strncmp(m_buffer, "\xEF\xBB\xBF", 3) == 0)
+ memmove(m_buffer, m_buffer + 3, strlen(m_buffer + 3) + 1);
+
// check for at the max
if ( p == m_buffer+INI_MAX_CHARS_PER_LINE )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandButton.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandButton.cpp
index a53e289ef..8f7c53da5 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandButton.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandButton.cpp
@@ -36,12 +36,22 @@
#include "Common/SpecialPower.h"
#include "Common/CommandStore.h"
#include "GameClient/ControlBar.h"
+#include "Common/StackDump.h" // g_LastErrorDump
//-------------------------------------------------------------------------------------------------
/** Parse a command button */
//-------------------------------------------------------------------------------------------------
void INI::parseCommandButtonDefinition( INI *ini )
{
+ /* A mod's Data\INI\Object\ folder is read with the objects, before TheCommandStore exists, and a
+ CommandButton block in it (ZH 1944's zz_WW2_40_CommandSet.ini) read through a NULL store. The
+ block parse's catch names the file and line; this says why. */
+ if( TheCommandStore == NULL )
+ {
+ g_LastErrorDump.format( "A CommandButton block in '%s' is read before command buttons exist; it belongs in Data\\INI\\CommandButton.ini\n",
+ ini->getFilename().str() );
+ throw INI_INVALID_DATA;
+ }
CommandStore::parseCommandButtonDefinition(ini);
}
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandSet.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandSet.cpp
index 5322644f0..4941f5796 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandSet.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandSet.cpp
@@ -34,11 +34,19 @@
#include "Common/INI.h"
#include "Common/CommandStore.h"
+#include "Common/StackDump.h" // g_LastErrorDump
//-------------------------------------------------------------------------------------------------
/** Parse a command set */
//-------------------------------------------------------------------------------------------------
void INI::parseCommandSetDefinition( INI *ini )
{
+ // as a CommandButton block: one a mod put among its objects comes before the store exists
+ if( TheCommandStore == NULL )
+ {
+ g_LastErrorDump.format( "A CommandSet block in '%s' is read before command sets exist; it belongs in Data\\INI\\CommandSet.ini\n",
+ ini->getFilename().str() );
+ throw INI_INVALID_DATA;
+ }
CommandStore::parseCommandSetDefinition(ini);
} // end parseCommandSetDefinition
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerTemplate.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerTemplate.cpp
index d9baeb494..f437432cc 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerTemplate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerTemplate.cpp
@@ -52,6 +52,7 @@
#include "Common/Player.h"
#include "Common/INI.h"
#include "Common/Science.h"
+#include "Common/ThingFactory.h"
#include "GameClient/Image.h"
#ifdef _INTERNAL
@@ -305,6 +306,35 @@ void PlayerTemplateStore::update()
// nothing
}
+//-----------------------------------------------------------------------------
+/** A faction whose start building is not among the loaded objects cannot start a match: Turkiye's
+ * command center is an ObjectReskin of America's, skipped under a mod that has none, and the match
+ * stopped at frame 0 placing it. The name is emptied, as Civilian's and Observer's are, and every
+ * faction list and the Random draw already leave those out. A missing start unit is dropped the
+ * same way. The data alone decides it, so every machine with the same files agrees. */
+//-----------------------------------------------------------------------------
+void PlayerTemplateStore::postProcessLoad()
+{
+ for (PlayerTemplateVector::iterator it = m_playerTemplates.begin(); it != m_playerTemplates.end(); ++it)
+ {
+ if (it->m_startingBuilding.isNotEmpty() && !TheThingFactory->findTemplate(it->m_startingBuilding, FALSE))
+ {
+ DEBUG_LOG(("PlayerTemplate %s: start building %s does not exist, the faction is not offered\n",
+ it->getName().str(), it->m_startingBuilding.str()));
+ it->m_startingBuilding.clear();
+ }
+ for (Int i = 0; i < MAX_MP_STARTING_UNITS; ++i)
+ {
+ if (it->m_startingUnits[i].isNotEmpty() && !TheThingFactory->findTemplate(it->m_startingUnits[i], FALSE))
+ {
+ DEBUG_LOG(("PlayerTemplate %s: start unit %s does not exist, it is left out\n",
+ it->getName().str(), it->m_startingUnits[i].str()));
+ it->m_startingUnits[i].clear();
+ }
+ }
+ }
+}
+
Int PlayerTemplateStore::getTemplateNumByName(AsciiString name) const
{
@@ -313,7 +343,7 @@ Int PlayerTemplateStore::getTemplateNumByName(AsciiString name) const
if (m_playerTemplates[num].getName().compareNoCase(name.str()) == 0)
return num;
}
- DEBUG_ASSERTCRASH(NULL, ("Template doesn't exist for given name"));
+ // a query: -side and the challenge menu ask with names a mod's data may not have
return -1;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/ProductionPrerequisite.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/ProductionPrerequisite.cpp
index 5ff829bbf..b358e5a68 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/ProductionPrerequisite.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/ProductionPrerequisite.cpp
@@ -98,7 +98,11 @@ void ProductionPrerequisite::resolveNames()
aren't yet loaded in the world builder but will all go away later anyway etc */
DEBUG_ASSERTCRASH(m_prereqUnits[i].unit,("could not find prereq %s\n",m_prereqUnits[i].name.str()));
- m_prereqUnits[i].name.clear(); // we're done with it
+ // a mod can name an Object it never defines; the name stays so a later load can still
+ // resolve it and the build tooltip can say what is missing. Until then the prereq is
+ // unsatisfiable: nothing a player owns matches a NULL template.
+ if( m_prereqUnits[i].unit )
+ m_prereqUnits[i].name.clear(); // we're done with it
}
}
@@ -225,6 +229,18 @@ void ProductionPrerequisite::addUnitPrereq( const std::vector<AsciiString>& unit
} // end addUnitPrereq
+//-------------------------------------------------------------------------------------------------
+// a prereq a mod names but never defines has no template, only its INI name (resolveNames)
+static UnicodeString prereqDisplayName(const ThingTemplate *unit, const AsciiString &name)
+{
+ if (unit)
+ return unit->getDisplayName();
+
+ UnicodeString missing;
+ missing.translate(name);
+ return missing;
+}
+
//-------------------------------------------------------------------------------------------------
// returns an asciistring which is a list of all the prerequisites
// not satisfied yet
@@ -263,7 +279,6 @@ UnicodeString ProductionPrerequisite::getRequiresList(const Player *player) cons
}
// check to see if anything is required
- const ThingTemplate *unit;
UnicodeString unitName;
Bool firstRequirement = true;
for (i = 0; i < cnt; i++)
@@ -273,8 +288,7 @@ UnicodeString ProductionPrerequisite::getRequiresList(const Player *player) cons
if(orRequirements[i])
{
- unit = m_prereqUnits[i-1].unit;
- unitName = unit->getDisplayName();
+ unitName = prereqDisplayName(m_prereqUnits[i-1].unit, m_prereqUnits[i-1].name);
unitName.concat( u" " );
unitName.concat(TheGameText->fetch("CONTROLBAR:OrRequirement", NULL));
unitName.concat( u" " );
@@ -282,8 +296,7 @@ UnicodeString ProductionPrerequisite::getRequiresList(const Player *player) cons
}
// get the requirement and then its name
- unit = m_prereqUnits[i].unit;
- unitName = unit->getDisplayName();
+ unitName = prereqDisplayName(m_prereqUnits[i].unit, m_prereqUnits[i].name);
// gets command button, and then modifies unitName
//CommandButton *cmdButton = TheControlBar->findCommandButton(unit->getName());
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp
index 0fec12d7d..9f5de2b12 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp
@@ -33,6 +33,7 @@
#include "GameClient/Drawable.h"
#include "GameClient/GameClient.h"
#include "GameClient/InGameUI.h"
+#include "GameClient/ParticleSys.h"
#include "GameClient/View.h"
#include "GameLogic/Object.h"
#include "GameLogic/FPUControl.h"
@@ -185,10 +186,13 @@ namespace
TheGameClient->linkDrawablesOfTick();
Drawable::flushPendingClientWork();
runViewCalls();
- // an effect queues nothing more: none of them runs inside a tick
- for( size_t i = 0; i < s_effects.size(); ++i )
- s_effects[ i ]();
- s_effects.clear();
+ // an effect queues nothing more: none of them runs inside a tick. Swapped out first, as the view
+ // calls are: an effect that pumps a frame (a modal message box) or throws ran the effects before it
+ // a second time, and an appended message twice was a double delete in the message stream
+ std::vector< std::function<void()> > effects;
+ effects.swap( s_effects );
+ for( size_t i = 0; i < effects.size(); ++i )
+ effects[ i ]();
AudioEventRTS::forgetHeldCallers();
TheGameClient->flushDestroyedDrawables();
ControlBar::flushLogicCalls();
@@ -298,6 +302,8 @@ static void startOverlap( void )
TheGameClient->setFrame( TheGameLogic->getFrame() );
jitter();
s_overlapStart = LogicClock::now();
+ // open before the tick wakes, so nothing the main thread does beside it reads as outside the window
+ LogicThread::g_windowOpen.store( 1, std::memory_order_relaxed );
{
std::lock_guard<std::mutex> lock( s_lock );
s_tickPending = TRUE;
@@ -380,6 +386,8 @@ void LogicThread::OverlapWindow::close( void )
g_windowOpen.store( 0, std::memory_order_relaxed );
if( s_overlapRunning )
waitOverlap();
+ // the tick no longer reads the manager's list and lookup
+ TheParticleSystemManager->friend_fileWindowSystems();
}
//-------------------------------------------------------------------------------------------------
@@ -425,8 +433,9 @@ void LogicThread::takeOverlapTimes( Real &tickMS, Real &waitMS )
//-------------------------------------------------------------------------------------------------
void LogicThread::init( void )
{
- // 1 unless the command line asks otherwise; -logicthread 0 keeps the tick on the main thread
- char value[ 32 ] = "1";
+ // 0 unless the command line asks otherwise, since v3.3.0's crash reports showed the heap corrupted
+ // by the tick beside the render; -logicthread 1 hands it to its own thread
+ char value[ 32 ] = "0";
findEarlyCommandLineValue( L"-logicthread", value, sizeof(value) );
if( atoi( value ) == 0 )
return;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ChallengeMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ChallengeMenu.cpp
index a161b55e2..107a6d2a7 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ChallengeMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ChallengeMenu.cpp
@@ -49,6 +49,7 @@
#include "GameClient/GameWindowManager.h"
#include "GameClient/GameWindowTransitions.h"
#include "GameClient/KeyDefs.h"
+#include "GameClient/MapUtil.h"
#include "GameClient/MessageBox.h"
#include "GameClient/Shell.h"
#include "GameClient/WindowLayout.h"
@@ -143,6 +144,44 @@ Int findPositionButton( Int controlID )
}
+//-------------------------------------------------------------------------------------------------
+// A general the loaded data cannot field: a mod's ChallengeMode.ini names a player template, a
+// campaign, a map or an opponent its files lack, and the game found out only at the start, in a
+// crash. The data does not change while the game runs, so each is decided and logged once.
+//-------------------------------------------------------------------------------------------------
+static Bool canPlayGeneral( Int index )
+{
+ static Bool s_checked[NUM_GENERALS];
+ static Bool s_playable[NUM_GENERALS];
+ if (s_checked[index])
+ return s_playable[index];
+ s_checked[index] = TRUE;
+
+ const GeneralPersona &general = TheChallengeGenerals->getChallengeGenerals()[index];
+ const PlayerTemplate *playerTemplate = ThePlayerTemplateStore->getNthPlayerTemplate(ThePlayerTemplateStore->getTemplateNumByName(general.getPlayerTemplateName()));
+ Campaign *campaign = TheCampaignManager->findCampaign(general.getCampaign());
+ AsciiString missing;
+ if (playerTemplate == NULL || playerTemplate->getStartingBuilding().isEmpty())
+ missing.format("player template %s", general.getPlayerTemplateName().str());
+ else if (campaign == NULL || campaign->getNextMission(NULL) == NULL)
+ missing.format("campaign %s", general.getCampaign().str());
+ else
+ {
+ for (Campaign::MissionListIt it = campaign->m_missions.begin(); missing.isEmpty() && it != campaign->m_missions.end(); ++it)
+ {
+ if (!TheFileSystem->doesFileExist((*it)->m_mapName.str()))
+ missing.format("map %s", (*it)->m_mapName.str());
+ else if (TheChallengeGenerals->getGeneralByGeneralName((*it)->m_generalName) == NULL)
+ missing.format("opponent %s", (*it)->m_generalName.str());
+ }
+ }
+ if (missing.isNotEmpty())
+ DEBUG_LOG(("ChallengeMenu: general %d is left out, the data has no %s\n", index, missing.str()));
+
+ s_playable[index] = missing.isEmpty();
+ return s_playable[index];
+}
+
//-------------------------------------------------------------------------------------------------
// enable the appropriate buttons, make sure they aren't hidden, and set the correct images
//-------------------------------------------------------------------------------------------------
@@ -151,8 +190,9 @@ void setEnabledButtons()
for (Int i = 0; i < NUM_GENERALS; i++)
{
const GeneralPersona* generals = TheChallengeGenerals->getChallengeGenerals();
- buttonGeneralPosition[i]->winEnable(generals[i].isStartingEnabled());
- buttonGeneralPosition[i]->winHide(! generals[i].isStartingEnabled());
+ const Bool playable = generals[i].isStartingEnabled() && canPlayGeneral(i);
+ buttonGeneralPosition[i]->winEnable(playable);
+ buttonGeneralPosition[i]->winHide(!playable);
Int templateNum = ThePlayerTemplateStore->getTemplateNumByName(generals[i].getPlayerTemplateName());
const PlayerTemplate *playerTemplate = ThePlayerTemplateStore->getNthPlayerTemplate(templateNum);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/System/CampaignManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/System/CampaignManager.cpp
index 828e88700..9aa28c0bc 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/System/CampaignManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/System/CampaignManager.cpp
@@ -294,21 +294,22 @@ void CampaignManager::setCampaignAndMission( AsciiString campaign, AsciiString m
setCampaign(campaign);
return;
}
- CampaignListIt it;
- it = m_campaignList.begin();
+ // a name this data lacks clears both, rather than leaving the last game's campaign current
+ m_currentCampaign = findCampaign( campaign );
+ m_currentMission = m_currentCampaign ? m_currentCampaign->getMission( mission ) : NULL;
+}
+
+//-----------------------------------------------------------------------------
+Campaign *CampaignManager::findCampaign( AsciiString campaign )
+{
campaign.toLower();
- while ( it != m_campaignList.end())
+ for( CampaignListIt it = m_campaignList.begin(); it != m_campaignList.end(); ++it )
{
- Campaign *camp = *it;
- if(camp->m_name.compare(campaign) == 0)
- {
- m_currentCampaign = camp;
- m_currentMission = camp->getMission( mission );
- return;
- }
- ++it;
+ if( (*it)->m_name.compare( campaign ) == 0 )
+ return *it;
}
-}
+ return NULL;
+}
//-----------------------------------------------------------------------------
void CampaignManager::setCampaign( AsciiString campaign )
@@ -463,7 +464,17 @@ void CampaignManager::xfer( Xfer *xfer )
// when loading, need to set the current campaign and mission
if( xfer->getXferMode() == XFER_LOAD )
+ {
setCampaignAndMission( currentCampaign, currentMission );
+ // a save from other data (a mod's, or one since changed) names a campaign or a mission this
+ // Campaign.ini lacks; the load fails with the error box instead of a mission that is not there
+ if( currentCampaign.isNotEmpty() && ( m_currentCampaign == NULL || ( currentMission.isNotEmpty() && m_currentMission == NULL ) ) )
+ {
+ DEBUG_LOG(( "CampaignManager: the save's campaign '%s' mission '%s' is not in this game's data\n",
+ currentCampaign.str(), currentMission.str() ));
+ throw XFER_UNKNOWN_STRING;
+ }
+ }
if( version >= 4 )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp
index 1077d42c4..6a996c82b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp
@@ -33,6 +33,7 @@
#include "Common/LogicThread.h"
#include <algorithm>
+#include <mutex>
#define DEFINE_PARTICLE_SYSTEM_NAMES
@@ -4093,8 +4094,18 @@ ParticleSystem *ParticleSystemManager::createParticleSystem( const ParticleSyste
if (sysTemplate == NULL)
return NULL;
- m_uniqueSystemID = (ParticleSystemID)((UnsignedInt)m_uniqueSystemID + 1);
- ParticleSystem *sys = newInstance(ParticleSystem)( sysTemplate, m_uniqueSystemID, createSlaves );
+ // The tick's shells and the render's own systems (a model state's bone systems, a truck's dust)
+ // take ids at the same time while the two overlap. Particle ids are client handles; no logic CRC
+ // reads them.
+ // ponytail: one global lock on the counter, uncontended outside the overlap; an atomic if it ever shows in a profile
+ static std::mutex s_idLock;
+ ParticleSystemID id;
+ {
+ std::lock_guard<std::mutex> lock( s_idLock );
+ m_uniqueSystemID = (ParticleSystemID)((UnsignedInt)m_uniqueSystemID + 1);
+ id = m_uniqueSystemID;
+ }
+ ParticleSystem *sys = newInstance(ParticleSystem)( sysTemplate, id, createSlaves );
return sys;
}
@@ -4120,10 +4131,20 @@ ParticleSystem *ParticleSystemManager::findParticleSystem( ParticleSystemID id )
if (id == INVALID_PARTICLE_SYSTEM_ID)
return NULL; // my, that was easy
- // a system this tick made is the tick's own until it is built
- for (size_t i = 0; i < m_shells.size(); ++i)
- if (m_shells[ i ]->getSystemID() == id)
- return m_shells[ i ];
+ // A system this tick made is the tick's own until it is built, and the logic thread fills the list
+ // beside the render: the main thread inside the window looks only at what it made there itself.
+ if (LogicThread::isInsideWindow())
+ {
+ for (size_t i = 0; i < m_windowSystems.size(); ++i)
+ if (m_windowSystems[ i ]->getSystemID() == id)
+ return m_windowSystems[ i ];
+ }
+ else
+ {
+ for (size_t i = 0; i < m_shells.size(); ++i)
+ if (m_shells[ i ]->getSystemID() == id)
+ return m_shells[ i ];
+ }
LOGIC_CENSUS( CENSUS_PARTICLES );
ParticleSystemIDMap::const_iterator it = m_allParticleSystemMap.find( id );
@@ -4331,12 +4352,27 @@ void ParticleSystemManager::removeParticle( Particle *particleToRemove)
// ------------------------------------------------------------------------------------------------
void ParticleSystemManager::friend_addParticleSystem( ParticleSystem *particleSystemToAdd )
{
+ // the tick beside the render reads the list and the lookup; filed once the window closes
+ if (LogicThread::isInsideWindow())
+ {
+ m_windowSystems.push_back(particleSystemToAdd);
+ return;
+ }
m_allParticleSystemList.push_back(particleSystemToAdd);
particleSystemToAdd->m_managerListIt = --m_allParticleSystemList.end();
m_allParticleSystemMap[ particleSystemToAdd->getSystemID() ] = particleSystemToAdd;
++m_particleSystemCount;
}
+// ------------------------------------------------------------------------------------------------
+void ParticleSystemManager::friend_fileWindowSystems( void )
+{
+ // outside the window now, so each one files itself as it would have at its build, in the order made
+ for (size_t i = 0; i < m_windowSystems.size(); ++i)
+ friend_addParticleSystem( m_windowSystems[ i ] );
+ m_windowSystems.clear();
+}
+
// ------------------------------------------------------------------------------------------------
/** Remove a particle system from the master particle system list. */
// ------------------------------------------------------------------------------------------------
@@ -4344,6 +4380,12 @@ void ParticleSystemManager::friend_removeParticleSystem( ParticleSystem *particl
{
// The constructor filed it and only the destructor calls this, so the iterator is ours and
// still good; EA scanned the whole list for it on every single system that died.
+ std::vector<ParticleSystem *>::iterator unfiled = std::find( m_windowSystems.begin(), m_windowSystems.end(), particleSystemToRemove );
+ if (unfiled != m_windowSystems.end())
+ {
+ m_windowSystems.erase( unfiled );
+ return;
+ }
m_allParticleSystemList.erase( particleSystemToRemove->m_managerListIt );
m_allParticleSystemMap.erase( particleSystemToRemove->getSystemID() );
--m_particleSystemCount;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp
index dc4c89a8a..17a2f7c31 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp
@@ -290,6 +290,22 @@ void OpenContain::addOrRemoveObjFromWorld(Object* obj, Bool add)
//-------------------------------------------------------------------------------------------------
void OpenContain::addToContain( Object *rider )
{
+ //
+ // Only the object's own contain module may hold riders. A mod that gives an object two contain
+ // modules gets both onCollide calls, and the one Object::getContain() does not name took the
+ // rider into a list nothing else looks at: the rider's exit, death and destruction all go through
+ // getContain(), so it was deleted while still on that list, and the next redeployOccupants put a
+ // freed object at a fire point. That is the shape of the RebornV5 crash, a Lazr_AmericaVehicleHumvee
+ // taking a pilot.
+ //
+ if( getObject()->getContain() != this )
+ {
+ DEBUG_LOG(( "'%s' has more than one contain module; '%s' goes only into the one getContain() names\n",
+ getObject()->getTemplate()->getName().str(),
+ rider->getTemplate()->getName().str() ));
+ return;
+ }
+
if( getObject()->checkAndDetonateBoobyTrap(rider) )
{
// Whoops, I was mined. Cancel if I (or they) am now dead.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp
index 503b152dc..da6d70439 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp
@@ -90,7 +90,7 @@ void parseUpgradePair( INI *ini, void *instance, void *store, const void *userDa
throw INI_INVALID_DATA;
- token = ini->getNextTokenOrNull( ini->getSepsColon() );
+ token = ini->getNextToken( ini->getSepsColon() ); // as OCLUpdate's: a short line throws, not reads NULL
if ( strcasecmp(token, "Boost") == 0 )
info.amount = INI::scanInt(ini->getNextToken( ini->getSepsColon() ));
else
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp
index c7dd7b22b..71c8c2263 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp
@@ -234,9 +234,14 @@ void HelicopterSlowDeathBehavior::beginSlowDeath( const DamageInfo *damageInfo )
{
return;
}
+ // a mod helicopter can die with no locomotor chosen (its set names none for the current
+ // condition); nothing holds it up then, so it drops on plain gravity and the spiral still runs
Locomotor *locomotor = getObject()->getAIUpdateInterface()->getCurLocomotor();
- locomotor->setMaxLift( -TheGlobalData->m_gravity * (1.0f - modData->m_fallHowFast) );
- locomotor->setMaxBraking( modData->m_maxBraking );
+ if( locomotor )
+ {
+ locomotor->setMaxLift( -TheGlobalData->m_gravity * (1.0f - modData->m_fallHowFast) );
+ locomotor->setMaxBraking( modData->m_maxBraking );
+ }
// attach particle system to bone if present
if( modData->m_attachParticleSystem )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/OCLUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/OCLUpdate.cpp
index bd7f28a57..423b63b4d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/OCLUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/OCLUpdate.cpp
@@ -64,7 +64,8 @@ void parseFactionObjectCreationList( INI *ini, void *instance, void *store, cons
throw INI_INVALID_DATA;
- token = ini->getNextTokenOrNull( ini->getSepsColon() );
+ // getNextToken throws on a line that ends here, where strcasecmp read NULL
+ token = ini->getNextToken( ini->getSepsColon() );
if ( strcasecmp(token, "OCL") == 0 )
ini->parseObjectCreationList( ini, instance, &info.m_ocl, NULL );
else
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
index 40a1333c5..a110628cb 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
@@ -846,8 +846,18 @@ static void populateRandomStartPosition( GameInfo *game )
Int numPlayers = MAX_SLOTS;
const MapMetaData *md = TheMapCache->findMap( game->getMap() );
DEBUG_ASSERTCRASH( md , ("Could not find map %s in the mapcache", game->getMap().str()));
+ /* The map cache is this machine's own. Without the map it deals over all MAX_SLOTS spots where a
+ machine that has it deals over the map's, so a network game or a replay refuses the start (the
+ corrupt-map path in update) instead of splitting into two games on the first draw. */
+ if (md == NULL && (TheGameLogic->isInMultiplayerGame() || TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK))
+ {
+ DEBUG_LOG(("populateRandomStartPosition: no map %s in the cache, a network game or replay is refused\n", game->getMap().str()));
+ throw ERROR_CORRUPT_FILE_FORMAT;
+ }
if (md)
numPlayers = md->m_numPlayers;
+ else
+ DEBUG_LOG(("populateRandomStartPosition: no map %s, start spots are dealt without distances\n", game->getMap().str()));
// generate a map of start spot distances
Real startSpotDistance[MAX_SLOTS][MAX_SLOTS];
@@ -855,7 +865,7 @@ static void populateRandomStartPosition( GameInfo *game )
{
for (Int j=0; j<MAX_SLOTS; ++j)
{
- if (i != j && (i<numPlayers && j<numPlayers))
+ if (md && i != j && (i<numPlayers && j<numPlayers))
{
AsciiString w1, w2;
w1.format("Player_%d_Start", i+1);
diff --git a/GeneralsMD/Code/Main/PosixMain.cpp b/GeneralsMD/Code/Main/PosixMain.cpp
index 2b6b97124..e220d0268 100644
--- a/GeneralsMD/Code/Main/PosixMain.cpp
+++ b/GeneralsMD/Code/Main/PosixMain.cpp
@@ -598,7 +598,7 @@ int main( int argc, char *argv[] )
DEBUG_SHUTDOWN();
}
// As WinMain: name what escaped the engine, and leave through ReleaseCrash so no destructor runs.
- catch (INIException e)
+ catch (const INIException &e)
{
RELEASE_CRASH((e.mFailureMessage ? e.mFailureMessage : "Uncaught INI exception in main"));
}
diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cpp
index 2a4cd4592..81c1d5f89 100644
--- a/GeneralsMD/Code/Main/WinMain.cpp
+++ b/GeneralsMD/Code/Main/WinMain.cpp
@@ -1563,7 +1563,7 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
running: the thread list was destroyed first, and the mouse or texture loader thread faulted
taking itself off it (Except.cpp, Unregister_Thread_ID), which is all a player's report ever
showed. Name what was thrown, and leave through ReleaseCrash's _exit so no destructor runs. */
- catch (INIException e)
+ catch (const INIException &e)
{
RELEASE_CRASH((e.mFailureMessage ? e.mFailureMessage : "Uncaught INI exception in WinMain"));
}
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 60e188149..f33186341 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -604,10 +604,12 @@ TEST(zero_hour_language_is_the_one_its_language_archive_names)
std::filesystem::remove_all( dir );
}
-/* An unknown block name aborts the whole file - INI::load throws
- INI_UNKNOWN_TOKEN and the blocks after it never get read. Worth pinning:
- nothing in the loader skips unknown blocks, so an INI written for a newer
- build breaks an older one outright. */
+/* An unknown block name aborts the whole file - INI::load throws and the
+ blocks after it never get read. Worth pinning: nothing in the loader skips
+ unknown blocks, so an INI written for a newer build breaks an older one
+ outright. The throw is an INIException naming the file and the block: a
+ bare INI_UNKNOWN_TOKEN reached GameEngine::init as "Uncaught Exception
+ during initialization." (v3.3.0 crash reports, a mod's Rank.ini). */
TEST(ini_unknown_block_aborts_the_file)
{
CHECK( bootOnce() );
@@ -625,6 +627,36 @@ TEST(ini_unknown_block_aborts_the_file)
CHECK( loadIni( TEST_INI ) == FALSE );
CHECK_EQ( WaterSettings[ TIME_OF_DAY_EVENING ].m_waterRepeatCount, -1 );
+ Bool named = FALSE;
+ try
+ {
+ INI ini;
+ ini.load( AsciiString( TEST_INI ), INI_LOAD_OVERWRITE, NULL );
+ }
+ catch( const INIException &e )
+ {
+ named = e.mFailureMessage && strstr( e.mFailureMessage, TEST_INI ) && strstr( e.mFailureMessage, "ThisBlockTypeDoesNotExist" );
+ }
+ CHECK( named );
+
+ remove( TEST_INI );
+}
+
+/* Some editors start a file with a UTF-8 byte order mark, which glued itself
+ to the first block's name and made it unknown. */
+TEST(ini_utf8_bom_is_skipped)
+{
+ CHECK( bootOnce() );
+
+ writeFile( TEST_INI,
+ "\xEF\xBB\xBFWaterSet EVENING\r\n"
+ " WaterRepeatCount = 5\r\n"
+ "End\r\n" );
+
+ WaterSettings[ TIME_OF_DAY_EVENING ].m_waterRepeatCount = -1;
+ CHECK( loadIni( TEST_INI ) );
+ CHECK_EQ( WaterSettings[ TIME_OF_DAY_EVENING ].m_waterRepeatCount, 5 );
+
remove( TEST_INI );
}
@@ -19449,6 +19481,7 @@ TEST(modfactions_prefix_only_the_mods_own_names)
names.scanLine( 0, " Weapon = PRIMARY RetailGun" ); // a field, not a definition
names.scanLine( 0, "CommandSet GLA CommandSet" ); // The End of Days really has this line
names.scanLine( 0, " Side = GLA" );
+ names.scanLine( 0, "ObjectCreationList OCL_Mine" );
names.finishScan( 0 );
names.setActive( 0 );
@@ -19456,6 +19489,13 @@ TEST(modfactions_prefix_only_the_mods_own_names)
strcpy( line, "Object AmericaRanger" );
CHECK( names.rewriteLine( line, sizeof( line ) ) );
CHECK_STR( line, "Object M1~AmericaRanger" );
+ // a colon parser's keyword stays the parser's, the name after it is the mod's; a label is neither
+ strcpy( line, " FactionOCL = Faction:GLA OCL:OCL_Mine" );
+ CHECK( names.rewriteLine( line, sizeof( line ) ) );
+ CHECK_STR( line, " FactionOCL = Faction:GLA OCL:M1~OCL_Mine" );
+ strcpy( line, " DisplayName = OBJECT:OCL_Mine" );
+ CHECK( names.rewriteLine( line, sizeof( line ) ) );
+ CHECK_STR( line, " DisplayName = OBJECT:OCL_Mine" );
strcpy( line, " Weapon = PRIMARY RangerGun" );
CHECK( names.rewriteLine( line, sizeof( line ) ) );
CHECK_STR( line, " Weapon = PRIMARY M1~RangerGun" );
diff --git a/README.md b/README.md
index c73645a8a..86f6a2659 100644
--- a/README.md
+++ b/README.md
@@ -98,7 +98,7 @@ yet. [CHANGELOG.md](CHANGELOG.md) has the measurements behind every line.
| Veterancy is shared by everyone who hurt the target in the last ten seconds; healing earns too | 2.4.0 |
| The three sides mine a supply pile at the same pace, near the drop-off or far from it | 3.0.0 |
| The battle runs 60 steps a second, double the 30 of 2003; every speed, delay and reload was converted, so a Crusader still fires every two seconds | 3.0.0 |
-| The battle is worked out on its own thread beside the drawing; `-logicthread 0` brings back the one-after-the-other loop | 3.2.0 |
+| `-logicthread 1` works the battle out on its own thread beside the drawing; off by default again after 3.3.0's crashes | 3.2.0 |
| Turbo mode replaces the speed dropdown: one lobby box, set by the host in a network game, two seconds of battle in every real one | 3.2.0 |
| Jets bank into turns, sweep wide at speed, take off down the runway, fly a landing circuit and taxi on their wheels | 3.2.0 |
| A jet shot down hits for 80 where it lands, 160 for a B-52 or a cargo plane, and leaves fire for about six seconds; its owner and allies are spared | 3.2.0 |
@@ -267,7 +267,7 @@ Discs carry 1.00 and the engine is 1.04's, so files from a 1.04 install (Steam,
| `-quickstart` | skips the intro movie, the shell map and the menu animations |
| `-nologo`, `-novideo` | skip the EA logo, or every movie |
| `-noaudio` | starts with every sound off |
-| `-logicthread 0` | works the battle out between frames, as before 3.2.0 |
+| `-logicthread 1` | works the battle out on its own thread beside the drawing; the default 0 works it out between frames |
<details>
<summary>For testing: unattended computer matches</summary>