From cdc708dcda0b648f646e3fffa1658acf33a10721 Mon Sep 17 00:00:00 2001 From: NemesisMate Date: Thu, 23 Jun 2016 16:57:06 +0100 Subject: [PATCH 1/2] userdata to null again once all data is removed. --- jme3-core/src/main/java/com/jme3/scene/Spatial.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jme3-core/src/main/java/com/jme3/scene/Spatial.java b/jme3-core/src/main/java/com/jme3/scene/Spatial.java index d0369ca3c..d912b34b3 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Spatial.java +++ b/jme3-core/src/main/java/com/jme3/scene/Spatial.java @@ -1530,6 +1530,9 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab if(data == null){ userData.remove(key); + if(userData.isEmpty()) { + userData = null; + } }else if (data instanceof Savable) { userData.put(key, (Savable) data); } else { From ce82a8a7b90179cf19881550e400db9b04533053 Mon Sep 17 00:00:00 2001 From: NemesisMate Date: Sat, 25 Jun 2016 11:16:46 +0100 Subject: [PATCH 2/2] improved the setUserData method. --- .../src/main/java/com/jme3/scene/Spatial.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/scene/Spatial.java b/jme3-core/src/main/java/com/jme3/scene/Spatial.java index d912b34b3..8561648b0 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Spatial.java +++ b/jme3-core/src/main/java/com/jme3/scene/Spatial.java @@ -1524,19 +1524,22 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab } public void setUserData(String key, Object data) { - if (userData == null) { - userData = new HashMap(); - } - - if(data == null){ - userData.remove(key); - if(userData.isEmpty()) { - userData = null; + if (data == null) { + if (userData != null) { + userData.remove(key); + if(userData.isEmpty()) { + userData = null; + } } - }else if (data instanceof Savable) { - userData.put(key, (Savable) data); } else { - userData.put(key, new UserData(UserData.getObjectType(data), data)); + if (userData == null) { + userData = new HashMap(); + } + if (data instanceof Savable) { + userData.put(key, (Savable) data); + } else { + userData.put(key, new UserData(UserData.getObjectType(data), data)); + } } }