Skip to content

Commit 0488ff3

Browse files
committed
Fix read of duplicate patchnames, update copyright year.
1 parent c5d90c9 commit 0488ff3

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Doom Struct
2-
Copyright (c) 2015 - 2024 Matt Tropiano
2+
Copyright (c) 2015 - 2025 Matt Tropiano
33

44
[Latest Release](https://github.com/MTrop/DoomStruct/releases/latest)
55

docs/CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
Doom Struct (C) 2015-2024
1+
Doom Struct (C) 2015-2025
22
=========================
33
by Matt Tropiano et al. (see AUTHORS.txt)
44

55

6+
Changed in 2.18.0
7+
-----------------
8+
9+
- `Fixed` PatchNames.readBytes(...) is now tolerant of PNAMES lumps that may contain duplicate patch names (since it can corrupt a TextureSet).
10+
- `Added` PatchNames.add(int, boolean) for allowing duplicate patch names.
11+
- `Changed` Slightly more efficient texture exporting in TextureSet.
12+
13+
614
Changed in 2.17.0
715
-----------------
816

src/main/java/net/mtrop/doom/texture/PatchNames.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2015-2023 Matt Tropiano
2+
* Copyright (c) 2015-2025 Matt Tropiano
33
* This program and the accompanying materials are made available under the
44
* terms of the GNU Lesser Public License v2.1 which accompanies this
55
* distribution, and is available at
@@ -60,9 +60,23 @@ public void clear()
6060
* @see NameUtils#isValidEntryName(String)
6161
*/
6262
public int add(String name)
63+
{
64+
return add(name, false);
65+
}
66+
67+
/**
68+
* Adds a patch entry.
69+
* @param name the entry name.
70+
* @param allowDuplicates if true, allow a duplicate entry.
71+
* @return the index of the added entry, or an existing index if it was already in the list and <code>allowDuplicates</code> is <code>false</code>.
72+
* @throws IllegalArgumentException if the provided name is not a valid entry name.
73+
* @see NameUtils#isValidEntryName(String)
74+
* @since 2.18.0
75+
*/
76+
public int add(String name, boolean allowDuplicates)
6377
{
6478
NameUtils.checkValidEntryName(name);
65-
if (nameList.contains(name))
79+
if (!allowDuplicates && nameList.contains(name))
6680
return nameList.getIndexOf(name);
6781

6882
int out = nameList.size();
@@ -120,7 +134,7 @@ public void readBytes(InputStream in) throws IOException
120134
SerialReader sr = new SerialReader(SerialReader.LITTLE_ENDIAN);
121135
int n = sr.readInt(in);
122136
while (n-- > 0)
123-
add(NameUtils.toValidEntryName(NameUtils.nullTrim(new String(sr.readBytes(in, 8), "ASCII"))));
137+
add(NameUtils.toValidEntryName(NameUtils.nullTrim(new String(sr.readBytes(in, 8), "ASCII"))), true);
124138
}
125139

126140
@Override

src/main/java/net/mtrop/doom/texture/TextureSet.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2015-2024 Matt Tropiano
2+
* Copyright (c) 2015-2025 Matt Tropiano
33
* This program and the accompanying materials are made available under the
44
* terms of the GNU Lesser Public License v2.1 which accompanies this
55
* distribution, and is available at
@@ -69,9 +69,10 @@ public TextureSet(PatchNames pnames, final CommonTextureList<?> ... textureLists
6969
for (int j = 0; j < t.getPatchCount(); j++)
7070
{
7171
CommonPatch p = t.getPatch(j);
72-
String patchName = pnames.get(p.getNameIndex());
72+
int patchIndex = p.getNameIndex();
73+
String patchName = pnames.get(patchIndex);
7374
if (patchName == null)
74-
throw new TextureException("Index "+j+" in PNAMES does not exist!");
75+
throw new TextureException("Index "+patchIndex+" in PNAMES does not exist!");
7576
Patch newpatch = newtex.createPatch(patchName);
7677
newpatch.setOriginX(p.getOriginX());
7778
newpatch.setOriginY(p.getOriginY());
@@ -294,10 +295,7 @@ public <P extends CommonPatch, T extends CommonTexture<P>> void export(PatchName
294295

295296
index = pnames.indexOf(pname);
296297
if (index == -1)
297-
{
298-
pnames.add(pname);
299-
index = pnames.indexOf(pname);
300-
}
298+
index = pnames.add(pname);
301299

302300
P ndtp = ndt.createPatch();
303301
ndtp.setOriginX(patch.getOriginX());

0 commit comments

Comments
 (0)