From 0ad6eb1b8d31a2e3af00305226704511ee75b0c3 Mon Sep 17 00:00:00 2001 From: badlogic Date: Thu, 26 Sep 2019 14:29:01 +0200 Subject: [PATCH] [libgdx] SkinEntry equals and hashCode do not take the attachment field into account. When setting a new SkinEntry for an existing slot + name combination, the old key with the old attachment stays in the keys table of the OrderedMap. Upon a call to getAttachments() that keys table is returned, which means the old attachment is returned instead of the newly set attachment. This commit fixes this buggy behaviour by storing SkinEntries as values, giving us access to the re-used key on which we can then update the attachment field. I'm sorry. Closes #1485. --- .../src/com/esotericsoftware/spine/Skin.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java index f3bd7df4e..70a0e5704 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java @@ -31,7 +31,6 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.OrderedMap; - import com.esotericsoftware.spine.attachments.Attachment; import com.esotericsoftware.spine.attachments.MeshAttachment; @@ -41,7 +40,7 @@ import com.esotericsoftware.spine.attachments.MeshAttachment; * Runtime skins in the Spine Runtimes Guide. */ public class Skin { final String name; - final OrderedMap attachments = new OrderedMap(); + final OrderedMap attachments = new OrderedMap(); final Array bones = new Array(); final Array constraints = new Array(); private final SkinEntry lookup = new SkinEntry(); @@ -56,7 +55,11 @@ public class Skin { public void setAttachment (int slotIndex, String name, Attachment attachment) { if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0."); if (attachment == null) throw new IllegalArgumentException("attachment cannot be null."); - attachments.put(new SkinEntry(slotIndex, name, attachment), attachment); + SkinEntry newEntry = new SkinEntry(slotIndex, name, attachment); + SkinEntry oldEntry = attachments.put(newEntry, newEntry); + if (oldEntry != null) { + oldEntry.attachment = attachment; + } } /** Adds all attachments, bones, and constraints from the specified skin to this skin. */ @@ -96,7 +99,8 @@ public class Skin { public Attachment getAttachment (int slotIndex, String name) { if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0."); lookup.set(slotIndex, name); - return attachments.get(lookup); + SkinEntry entry = attachments.get(lookup); + return entry != null ? entry.attachment : null; } /** Removes the attachment in the skin for the specified slot index and name, if any. */