diff --git a/Source/Core/Editing/EditMode.cs b/Source/Core/Editing/EditMode.cs index cbc25c2cf26cad838915d7e6581f20d231174130..1524d0bf78ae0cd6c389aba499eac92e8447d6ac 100644 --- a/Source/Core/Editing/EditMode.cs +++ b/Source/Core/Editing/EditMode.cs @@ -179,8 +179,8 @@ namespace CodeImp.DoomBuilder.Editing // Called when the marked geometry has been copied. public virtual void OnCopyEnd() { } - // Called before pasting. Return false when paste should be cancelled. - public virtual bool OnPasteBegin(PasteOptions options) { return true; } + // Called before pasting. Override this and return true to indicate that paste is allowed to contiue. + public virtual bool OnPasteBegin(PasteOptions options) { return false; } // Called after new geometry has been pasted in. The new geometry is marked. public virtual void OnPasteEnd(PasteOptions options) { } diff --git a/Source/Core/General/MapManager.cs b/Source/Core/General/MapManager.cs index d493185c54a1f9015f7ee08521088390a951a62b..82a90a15a5a202a880372f56455d533812aff9b0 100644 --- a/Source/Core/General/MapManager.cs +++ b/Source/Core/General/MapManager.cs @@ -252,7 +252,16 @@ namespace CodeImp.DoomBuilder // Create temp wadfile tempfile = General.MakeTempFilename(temppath); General.WriteLogLine("Creating temporary file: " + tempfile); - tempwad = new WAD(tempfile); + #if DEBUG + tempwad = new WAD(tempfile); + #else + try { tempwad = new WAD(tempfile); } + catch(Exception e) + { + General.ShowErrorMessage("Error while creating a temporary wad file:\n" + e.GetType().Name + ": " + e.Message, MessageBoxButtons.OK); + return false; + } + #endif // Read the map from temp file General.WriteLogLine("Initializing map format interface " + config.FormatInterface + "..."); @@ -329,17 +338,35 @@ namespace CodeImp.DoomBuilder // Create temp wadfile tempfile = General.MakeTempFilename(temppath); General.WriteLogLine("Creating temporary file: " + tempfile); - tempwad = new WAD(tempfile); + #if DEBUG + tempwad = new WAD(tempfile); + #else + try { tempwad = new WAD(tempfile); } + catch(Exception e) + { + General.ShowErrorMessage("Error while creating a temporary wad file:\n" + e.GetType().Name + ": " + e.Message, MessageBoxButtons.OK); + return false; + } + #endif // Now open the map file General.WriteLogLine("Opening source file: " + filepathname); - mapwad = new WAD(filepathname, true); - + #if DEBUG + mapwad = new WAD(filepathname, true); + #else + try { mapwad = new WAD(filepathname, true); } + catch(Exception e) + { + General.ShowErrorMessage("Error while opening source wad file:\n" + e.GetType().Name + ": " + e.Message, MessageBoxButtons.OK); + return false; + } + #endif + // Copy the map lumps to the temp file General.WriteLogLine("Copying map lumps to temporary file..."); CopyLumpsByType(mapwad, options.CurrentName, tempwad, TEMP_MAP_HEADER, true, true, true, true); - + // Close the map file mapwad.Dispose(); @@ -678,8 +705,17 @@ namespace CodeImp.DoomBuilder // Make the temporary WAD file General.WriteLogLine("Creating temporary build file: " + tempfile1); - buildwad = new WAD(tempfile1); - + #if DEBUG + buildwad = new WAD(tempfile1); + #else + try { buildwad = new WAD(tempfile1); } + catch(Exception e) + { + General.ShowErrorMessage("Error while creating a temporary wad file:\n" + e.GetType().Name + ": " + e.Message, MessageBoxButtons.OK); + return false; + } + #endif + // Determine source file if(filepathname.Length > 0) sourcefile = filepathname; @@ -715,10 +751,19 @@ namespace CodeImp.DoomBuilder if(compiler.Run()) { // Open the output file - buildwad = new WAD(tempfile2); + try { buildwad = new WAD(tempfile2); } + catch(Exception e) + { + General.WriteLogLine(e.GetType().Name + " while reading build wad file: " + e.Message); + buildwad = null; + } + + if(buildwad != null) + { + // Output lumps complete? + lumpscomplete = VerifyNodebuilderLumps(buildwad, BUILD_MAP_HEADER); + } - // Output lumps complete? - lumpscomplete = VerifyNodebuilderLumps(buildwad, BUILD_MAP_HEADER); if(lumpscomplete) { // Copy nodebuilder lumps to temp file @@ -735,7 +780,7 @@ namespace CodeImp.DoomBuilder } // Done with the build wad - buildwad.Dispose(); + if(buildwad != null) buildwad.Dispose(); } // Clean up diff --git a/Source/Core/IO/WAD.cs b/Source/Core/IO/WAD.cs index a6dcf033f0af6f16c6010b7645b659fb282d42ba..1103c2992785019b83764f5f5f5bf2cd8c34225d 100644 --- a/Source/Core/IO/WAD.cs +++ b/Source/Core/IO/WAD.cs @@ -196,9 +196,11 @@ namespace CodeImp.DoomBuilder.IO // Number of lumps numlumps = reader.ReadInt32(); + if(numlumps < 0) throw new IOException("Invalid number of lumps in wad file."); // Lumps table offset lumpsoffset = reader.ReadInt32(); + if(lumpsoffset < 0) throw new IOException("Invalid lumps offset in wad file."); // Seek to the lumps table file.Seek(lumpsoffset, SeekOrigin.Begin); diff --git a/Source/Core/Map/MapSet.cs b/Source/Core/Map/MapSet.cs index 2dae09a9bcb8f3ed7e40e49c5021d1d84a9846e9..833c44e7716d85f511ba1a0e555bc183257697e1 100644 --- a/Source/Core/Map/MapSet.cs +++ b/Source/Core/Map/MapSet.cs @@ -2488,17 +2488,20 @@ namespace CodeImp.DoomBuilder.Map public List<int> GetMultipleNewTags(int count) { List<int> newtags = new List<int>(count); - Dictionary<int, bool> usedtags = new Dictionary<int, bool>(); - ForAllTags(NewTagHandler, false, usedtags); - ForAllTags(NewTagHandler, true, usedtags); - - // Find unused tags and add them - for(int i = 1; i <= General.Map.FormatInterface.MaxTag; i++) + if(count > 0) { - if(!usedtags.ContainsKey(i)) + Dictionary<int, bool> usedtags = new Dictionary<int, bool>(); + ForAllTags(NewTagHandler, false, usedtags); + ForAllTags(NewTagHandler, true, usedtags); + + // Find unused tags and add them + for(int i = 1; i <= General.Map.FormatInterface.MaxTag; i++) { - newtags.Add(i); - if(newtags.Count == count) break; + if(!usedtags.ContainsKey(i)) + { + newtags.Add(i); + if(newtags.Count == count) break; + } } } @@ -2509,19 +2512,22 @@ namespace CodeImp.DoomBuilder.Map public List<int> GetMultipleNewTags(int count, bool marked) { List<int> newtags = new List<int>(count); - Dictionary<int, bool> usedtags = new Dictionary<int, bool>(); - ForAllTags(NewTagHandler, marked, usedtags); - - // Find unused tags and add them - for(int i = 1; i <= General.Map.FormatInterface.MaxTag; i++) + if(count > 0) { - if(!usedtags.ContainsKey(i)) + Dictionary<int, bool> usedtags = new Dictionary<int, bool>(); + ForAllTags(NewTagHandler, marked, usedtags); + + // Find unused tags and add them + for(int i = 1; i <= General.Map.FormatInterface.MaxTag; i++) { - newtags.Add(i); - if(newtags.Count == count) break; + if(!usedtags.ContainsKey(i)) + { + newtags.Add(i); + if(newtags.Count == count) break; + } } } - + return newtags; } diff --git a/Source/Plugins/BuilderModes/ClassicModes/BaseClassicMode.cs b/Source/Plugins/BuilderModes/ClassicModes/BaseClassicMode.cs index 0575c1fd551e906a20b77393ac5e38d7e0851093..4e6467c323f21187b82ff1a8795f1b6b1e966991 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/BaseClassicMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/BaseClassicMode.cs @@ -91,7 +91,14 @@ namespace CodeImp.DoomBuilder.BuilderModes return (General.Map.Map.GetMarkedVertices(true).Count > 0) || (General.Map.Map.GetMarkedThings(true).Count > 0); } - + + // This is called when pasting begins + public override bool OnPasteBegin(PasteOptions options) + { + // These modes support pasting + return true; + } + // This is called when something was pasted. public override void OnPasteEnd(PasteOptions options) { diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs index dd9a250f924e65c09e09e6990dcfa01ec2b95f0f..2273f1b108205658e7e739257e54d21105938b60 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs @@ -32,6 +32,7 @@ using CodeImp.DoomBuilder.Geometry; using CodeImp.DoomBuilder.Editing; using CodeImp.DoomBuilder.Actions; using CodeImp.DoomBuilder.VisualModes; +using CodeImp.DoomBuilder.Config; #endregion