From e86354818224106fd0ad3ce87d5e9f8ddf0c1bb9 Mon Sep 17 00:00:00 2001 From: CharonInferar Date: Sun, 5 Oct 2014 18:48:34 +0200 Subject: [PATCH] Fixed getBytes() exception Only objects that are in objectList are added to the Quadtree. Prevents later errors where the quadtree objects would not be found in objectList. After all such objects should not even be around, but well ... --- .../objects/creature/CreatureObject.java | 45 +++++++++++++++++++ src/services/SimulationService.java | 12 +++++ 2 files changed, 57 insertions(+) diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index 0eaaa13d..09a74693 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -21,6 +21,9 @@ ******************************************************************************/ package resources.objects.creature; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -1431,6 +1434,9 @@ public class CreatureObject extends TangibleObject implements IPersistent { public void sendBaselines(Client destination) { if (destination != null && destination.getSession() != null) { + + //objectFieldDiagnosis(); + destination.getSession().write(getBaseline(3).getBaseline()); destination.getSession().write(getBaseline(6).getBaseline()); if (destination == getClient()) { @@ -1451,6 +1457,45 @@ public class CreatureObject extends TangibleObject implements IPersistent { } } + // Utility method to check which fields are null + public void objectFieldDiagnosis(){ + System.out.println("Object being diagnosed: " + this.getTemplate() + " Id: " + this.getObjectID()); + + ArrayList list = new ArrayList(); + Method[] methods = this.getClass().getDeclaredMethods(); + for (Method method : methods) + if (isGetter(method)){ + try { + Object valueObject = method.invoke(this, (Object[]) null); + if (valueObject==null){ + System.err.println("method " + method.getName() + " delivers null object"); + } + } catch (IllegalAccessException e) { + System.err.println("IllegalAccessException during reflection"); + e.printStackTrace(); + } catch (IllegalArgumentException e) { + System.err.println("IllegalArgumentException during reflection"); + e.printStackTrace(); + } catch (InvocationTargetException e) { + System.err.println("InvocationTargetException during reflection"); + e.printStackTrace(); + } + } + } + + public static boolean isGetter(Method method) { + if (Modifier.isPublic(method.getModifiers()) && + method.getParameterTypes().length == 0) { + if (method.getName().matches("^get[A-Z].*") && + !method.getReturnType().equals(void.class)) + return true; + if (method.getName().matches("^is[A-Z].*") && + method.getReturnType().equals(boolean.class)) + return true; + } + return false; + } + public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) { switch (viewType) { case 1: diff --git a/src/services/SimulationService.java b/src/services/SimulationService.java index e8dc0bc0..e2bdfeb4 100644 --- a/src/services/SimulationService.java +++ b/src/services/SimulationService.java @@ -192,6 +192,7 @@ public class SimulationService implements INetworkDispatch { if(notifyObservers) { Point3D pos = new Point3D(x, 0, z); Collection newAwareObjects = get(object.getPlanet(), x, z, 512); + cleanAwareObjects(newAwareObjects); // Only objects that are in objectList are considered!!! for(Iterator it = newAwareObjects.iterator(); it.hasNext();) { SWGObject obj = it.next(); if((obj.getAttachment("bigSpawnRange") == null && obj.getWorldPosition().getDistance2D(pos) > 200) || obj == object) @@ -211,6 +212,17 @@ public class SimulationService implements INetworkDispatch { return success; } + public void cleanAwareObjects(Collection newAwareObjects){ + Collection cleanUpObjects = new ArrayList(); + for(Iterator it = newAwareObjects.iterator(); it.hasNext();) { + SWGObject obj = it.next(); + SWGObject objInList = NGECore.getInstance().objectService.getObject(obj.getObjectID()); + if (objInList==null) + cleanUpObjects.add(obj); + } + newAwareObjects.removeAll(cleanUpObjects); + } + public void addChildObjects(SWGObject object, Vector childObjects) { for(SWGObject childObject : childObjects) {