Fixed, DB2 bug: temporary map file was growing in size after every map save/test, which eventually resulted in integer overflow exception when the file size reached ~2Gb.

Fixed, Draw Geometry modes: fixed a crash when moving the mouse cursor over a linedef while holding Alt-Shift keys when there were no new points drawn in current mode.
This commit is contained in:
MaxED 2016-06-30 17:57:51 +00:00
parent 7b54c0141d
commit 4f76483439
3 changed files with 92 additions and 21 deletions

View file

@ -788,6 +788,9 @@ namespace CodeImp.DoomBuilder
General.MainWindow.DisplayStatus(StatusType.Busy, "Building map nodes...");
includenodes = (!string.IsNullOrEmpty(nodebuildername) && BuildNodes(nodebuildername, true));
General.MainWindow.DisplayStatus(oldstatus);
//mxd. Compress temp file...
tempwadreader.WadFile.Compress();
}
else
{
@ -1152,6 +1155,9 @@ namespace CodeImp.DoomBuilder
result = false;
General.MainWindow.DisplayStatus(oldstatus);
//mxd. Compress temp file...
tempwadreader.WadFile.Compress();
return result;
}

View file

@ -85,6 +85,17 @@ namespace CodeImp.DoomBuilder.IO
#endregion
#region ================== Structs (mxd)
private struct LumpCopyData
{
public byte[] Data;
public byte[] FixedName;
public int Index;
}
#endregion
#region ================== Variables
// File objects
@ -334,6 +345,66 @@ namespace CodeImp.DoomBuilder.IO
}
}
//mxd. This rebuilds the WAD file, removing all "dead" entries
// Tech info: WAD.Remove() doesn't remove lump data, so MapManager.TemporaryMapFile slowly gets bigger
// with every map save/test, which leads to lumpsoffset overflowing when TemporaryMapFile size reaches
// int.MaxValue bytes in size (that's ~2Gb).
internal void Compress()
{
// No can't do...
if(isreadonly) return;
// Gather existing data
int totaldatalength = 0;
List<LumpCopyData> copydata = new List<LumpCopyData>(lumps.Count);
for(int i = 0; i < lumps.Count; i++)
{
// Copy lump...
LumpCopyData lcd = new LumpCopyData();
Lump l = lumps[i];
lcd.FixedName = l.FixedName;
lcd.Index = i;
lcd.Data = l.Stream.ReadAllBytes();
// Store data
copydata.Add(lcd);
// Track total length
totaldatalength += l.Length;
// Dispose lump
l.Dispose();
}
// Compression required?
if(totaldatalength >= lumpsoffset + 12) return;
// Set new file length
file.SetLength(totaldatalength + lumps.Count * 16);
// Reset lumpsoffset
lumpsoffset = 12;
// Reset lumps collection
lumps = new List<Lump>(copydata.Count);
numlumps = copydata.Count;
// Recreate all lumps
foreach(LumpCopyData lcd in copydata)
{
Lump l = new Lump(file, this, lcd.FixedName, lumpsoffset, lcd.Data.Length);
l.Stream.Write(lcd.Data, 0, lcd.Data.Length);
l.Stream.Seek(0, SeekOrigin.Begin);
lumps.Insert(lcd.Index, l);
lumpsoffset += lcd.Data.Length;
}
// Write new headers
WriteHeaders();
}
// This flushes writing changes
/*public void Flush()
{
@ -364,18 +435,9 @@ namespace CodeImp.DoomBuilder.IO
Lump lump = new Lump(file, this, Lump.MakeFixedName(name, ENCODING), lumpsoffset, datalength);
lumps.Insert(position, lump);
//dbg
int oldlumpoffset = lumpsoffset;
// Advance lumps table offset
lumpsoffset += datalength;
//dbg
if(lumpsoffset < 0)
{
throw new InvalidOperationException("Invalid lumpsoffset (" + lumpsoffset + ") after inserting lump \"" + name + "\" at position " + position + ", datalength=" + datalength + ". Previous lumpoffset was " + oldlumpoffset);
}
// Write the new headers
if(writeheaders) WriteHeaders();

View file

@ -376,6 +376,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
//mxd. Line angle must stay the same
if(snaptocardinal)
{
if(points.Count > 0)
{
Line2D ourline = new Line2D(points[points.Count - 1].pos, vm);
Line2D nearestline = new Line2D(nl.Start.Position, nl.End.Position);
@ -385,7 +387,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Intersection is on nearestline?
float u = Line2D.GetNearestOnLine(nearestline.v1, nearestline.v2, intersection);
if(u < 0f || u > 1f){}
if(u < 0f || u > 1f) { }
else
{
p.pos = new Vector2D((float)Math.Round(intersection.x, General.Map.FormatInterface.VertexDecimals),
@ -394,6 +396,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
}
}
}
// Snap to grid?
else if(snaptogrid)
{