Fixed a crash when trying to load a map from the command line and specifying a non-existent map using the -map parameter. Fixes 934

Fixed a crash when trying to load a map from the command line when the game configuration specified in the DBS file does not exist
This commit is contained in:
biwa 2024-01-13 20:20:30 +01:00
parent 6fcb5d2f57
commit ce961501b9
3 changed files with 24 additions and 3 deletions

View file

@ -23,6 +23,7 @@ using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.AccessControl; using System.Security.AccessControl;
@ -293,6 +294,13 @@ namespace CodeImp.DoomBuilder
#region ================== Configurations #region ================== Configurations
/// <summary>
/// Checks if a given game configuration file exists.
/// </summary>
/// <param name="filename">The file name of the game configuration file.</param>
/// <returns>true if the game configuration exists, false if it doesn't</returns>
internal static bool ConfigurationInfoExist(string filename) => configs.Any(ci => string.Compare(Path.GetFileNameWithoutExtension(ci.Filename), Path.GetFileNameWithoutExtension(filename), true) == 0);
// This returns the game configuration info by filename // This returns the game configuration info by filename
internal static ConfigurationInfo GetConfigurationInfo(string filename) internal static ConfigurationInfo GetConfigurationInfo(string filename)
{ {

View file

@ -421,7 +421,16 @@ namespace CodeImp.DoomBuilder
// Copy the map lumps to the temp file // Copy the map lumps to the temp file
General.WriteLogLine("Copying map lumps to temporary file..."); General.WriteLogLine("Copying map lumps to temporary file...");
CopyLumpsByType(mapwad, options.CurrentName, tempwadreader.WadFile, TEMP_MAP_HEADER, true, true, true, true); if (!CopyLumpsByType(mapwad, options.CurrentName, tempwadreader.WadFile, TEMP_MAP_HEADER, true, true, true, true))
{
// Ooops, the map doesn't exit. This should only happend when run from the command line using the "-map" parameter
General.ErrorLogger.Add(ErrorType.Error, $"Map \"{options.CurrentName}\" does not exist in file \"{filepathname}\".");
// Close the map file
mapwad.Dispose();
return false;
}
// Close the map file // Close the map file
mapwad.Dispose(); mapwad.Dispose();
@ -1660,7 +1669,7 @@ namespace CodeImp.DoomBuilder
} }
// This copies specific map lumps from one WAD to another // This copies specific map lumps from one WAD to another
private void CopyLumpsByType(WAD source, string sourcemapname, private bool CopyLumpsByType(WAD source, string sourcemapname,
WAD target, string targetmapname, WAD target, string targetmapname,
bool copyrequired, bool copyblindcopy, bool copyrequired, bool copyblindcopy,
bool copynodebuild, bool copyscript, bool copynodebuild, bool copyscript,
@ -1734,7 +1743,11 @@ namespace CodeImp.DoomBuilder
target.WriteHeaders(); //mxd target.WriteHeaders(); //mxd
target.Compress(); // [ZZ] target.Compress(); // [ZZ]
return true;
} }
return false;
} }
// This finds a lump within the range of known lump names // This finds a lump within the range of known lump names

View file

@ -565,7 +565,7 @@ namespace CodeImp.DoomBuilder.Windows
configfile = General.AutoLoadConfig; configfile = General.AutoLoadConfig;
if (string.IsNullOrEmpty(configfile)) configfile = mapsettings.ReadSetting("gameconfig", ""); if (string.IsNullOrEmpty(configfile)) configfile = mapsettings.ReadSetting("gameconfig", "");
if(configfile.Trim().Length == 0) if(configfile.Trim().Length == 0 || !General.ConfigurationInfoExist(configfile))
{ {
showdialog = true; showdialog = true;
} }