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(milesaudio): a looping sound with no info no longer crashes the mix

Olcay Seyganb0e2ea426986
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c77c3f7f1..58d6effd6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -936,6 +936,8 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- Blowing up a full transport is survivable now, in every remaining variant.
- A unit can no longer load into a vehicle that no longer exists.
- Selling or losing an airfield under a jet on its takeoff roll no longer takes the game down. The jet takes off.
+- A looping sound coming round for its next pass no longer takes the game down. v2.0.0 lifted unit replies over the battle, and the check for whether a sound is a reply read a part of the sound that a looping one can have lost by then. A player's skirmish ended on "Technical Difficulties" twelve hundred frames in. A sound with nothing to say about itself now plays at the effects volume.
+- When the game does go down, the reason and where it happened are written into the game log beside the game as well as into the crash file under Documents. Two players on v2.0.0 saw "Technical Difficulties" and their crash file never turned up, so the report that reached us said nothing about why.
- A Particle Uplink Cannon fired by a script along a path no longer crashes at the path's last waypoint.
- A damage effect whose attacker died first no longer crashes the game, and neither does a flash-bang into a building with fewer soldiers than it was meant to kill.
- A disguised bomb truck losing its disguise used to rebuild itself onto the image it had just thrown away. It gets a fresh one now.
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp
index 803d2b104..ad1db1cc4 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp
@@ -705,6 +705,11 @@ double SimpleProfiler::getAverageTime()
static FILE *theReleaseCrashLogFile = NULL;
+ /* Everything the crash file gets goes into DebugLogFile.txt as well. The crash file lives under
+ Documents and is opened through an ANSI path in a MAX_PATH buffer, so a redirected or non-ASCII
+ Documents folder loses it, and two players on v2.0.0 sent reports with the "Technical
+ Difficulties" box on screen and no crash file at all. The log sits beside the exe and the
+ launcher always sends its tail. */
static void releaseCrashLogOutput(const char *buffer)
{
if (theReleaseCrashLogFile)
@@ -712,6 +717,38 @@ double SimpleProfiler::getAverageTime()
fprintf(theReleaseCrashLogFile, "%s", buffer); // note, no \n (should be there already)
fflush(theReleaseCrashLogFile);
}
+#ifdef DEBUG_LOGGING
+ if (theLogFile)
+ {
+ fprintf(theLogFile, "%s", buffer);
+ fflush(theLogFile);
+ }
+#endif
+ }
+
+ static const int RELEASECRASH_STACK_SIZE = 12;
+ // 1, not 6: FillStackAddresses drops its own frame itself now, so 6 skipped
+ // past everything the game did and logged two ntdll frames instead.
+ static const int RELEASECRASH_STACK_SKIP = 1;
+
+ static void releaseCrashStackOutput(void)
+ {
+ void* stacktrace[RELEASECRASH_STACK_SIZE];
+ ::FillStackAddresses(stacktrace, RELEASECRASH_STACK_SIZE, RELEASECRASH_STACK_SKIP);
+ ::StackDumpFromAddresses(stacktrace, RELEASECRASH_STACK_SIZE, releaseCrashLogOutput);
+ }
+
+ /// The reason and the registers go into the log before the crash file is even opened.
+ static void releaseCrashToLog(const char *reason)
+ {
+#ifdef DEBUG_LOGGING
+ if (theLogFile)
+ {
+ fprintf(theLogFile, "\nRelease Crash at %s; Reason %s\n\nLast error:\n%s\n\nCurrent stack:\n",
+ getCurrentTimeString(), reason, g_LastErrorDump.str());
+ fflush(theLogFile);
+ }
+#endif
}
void ReleaseCrash(const char *reason)
@@ -721,6 +758,7 @@ void ReleaseCrash(const char *reason)
if (theLogFile)
fflush(theLogFile);
#endif
+ releaseCrashToLog(reason);
/// do additional reporting on the crash, if possible
@@ -768,14 +806,14 @@ void ReleaseCrash(const char *reason)
fprintf(theReleaseCrashLogFile, "\nLast error:\n%s\n\nCurrent stack:\n", g_LastErrorDump.str());
// The stack walk below can fault, and the reason and the registers above it must survive that.
fflush(theReleaseCrashLogFile);
- const int STACKTRACE_SIZE = 12;
- // 1, not 6: FillStackAddresses drops its own frame itself now, so 6 skipped
- // past everything the game did and logged two ntdll frames instead.
- const int STACKTRACE_SKIP = 1;
- void* stacktrace[STACKTRACE_SIZE];
- ::FillStackAddresses(stacktrace, STACKTRACE_SIZE, STACKTRACE_SKIP);
- ::StackDumpFromAddresses(stacktrace, STACKTRACE_SIZE, releaseCrashLogOutput);
-
+ }
+ else
+ {
+ DEBUG_LOG(("ReleaseCrash - could not write %s\n", curbuf));
+ }
+ releaseCrashStackOutput();
+ if (theReleaseCrashLogFile)
+ {
fflush(theReleaseCrashLogFile);
fclose(theReleaseCrashLogFile);
theReleaseCrashLogFile = NULL;
@@ -826,6 +864,7 @@ void ReleaseCrashLocalized(const AsciiString& p, const AsciiString& m)
return;
}
+ releaseCrashToLog(m.str());
UnicodeString prompt = TheGameText->fetch(p);
UnicodeString mesg = TheGameText->fetch(m);
@@ -876,18 +915,17 @@ void ReleaseCrashLocalized(const AsciiString& p, const AsciiString& m)
theReleaseCrashLogFile = fopen(curbuf, "w");
if (theReleaseCrashLogFile)
{
- fprintf(theReleaseCrashLogFile, "Release Crash at %s; Reason %s\n", getCurrentTimeString(), mesg.str());
+ fprintf(theReleaseCrashLogFile, "Release Crash at %s; Reason %ls\n", getCurrentTimeString(), mesg.str());
if (hadPreviousCrashLog && rotated != 0)
fprintf(theReleaseCrashLogFile, "(the previous crash report could not be rotated aside; %s is older than it looks)\n", prevbuf);
-
- const int STACKTRACE_SIZE = 12;
- // 1, not 6: FillStackAddresses drops its own frame itself now, so 6 skipped
- // past everything the game did and logged two ntdll frames instead.
- const int STACKTRACE_SKIP = 1;
- void* stacktrace[STACKTRACE_SIZE];
- ::FillStackAddresses(stacktrace, STACKTRACE_SIZE, STACKTRACE_SKIP);
- ::StackDumpFromAddresses(stacktrace, STACKTRACE_SIZE, releaseCrashLogOutput);
-
+ }
+ else
+ {
+ DEBUG_LOG(("ReleaseCrashLocalized - could not write %s\n", curbuf));
+ }
+ releaseCrashStackOutput();
+ if (theReleaseCrashLogFile)
+ {
fflush(theReleaseCrashLogFile);
fclose(theReleaseCrashLogFile);
theReleaseCrashLogFile = NULL;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
index 3aad6fa7f..c1d710d78 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
@@ -2167,8 +2167,11 @@ Real MilesAudioManager::getVoiceMixedVolume( const AudioEventRTS *event, Real sl
{
static const Real VOICE_BOOST = 1.6f;
+ // A sound can reach here with no info (see audioIsType): v2.0.0 read m_type through it and a
+ // looping sound's next pass died at address 0x40 on the XAudio2 service thread.
+ const AudioEventInfo *info = event->getAudioEventInfo();
const Real eventVolume = event->getVolume() * event->getVolumeShift();
- if (event->getAudioEventInfo()->m_type & ST_VOICE) {
+ if (info != NULL && (info->m_type & ST_VOICE)) {
return min( 1.0f, eventVolume * max( sliderVolume, m_speechVolume ) * VOICE_BOOST );
}