NPE using the new detect methods

Posts regarding potential bugs, enhancement requests, and general feedback on use of dyn4j
zoom
Posts: 143
Joined: Sun Mar 17, 2013 3:57 pm
Location: Stockholm, Sweden
Contact:

NPE using the new detect methods

Postby zoom » Sun Apr 20, 2014 7:47 am

I'm getting a NPE in my code. I'll see if I can boil it down to a simple test case (http://www.sscce.org) but in short this is approx. what I do (using 3.1.9):

Code: Select all

final ArrayList<DetectResult> result = new ArrayList<>();
Circle convex = new Circle(20.0) ;
CategoryFilter filter = new CategoryFilter(2, 15);
world.detect(convex, filter, true, false, result);


java.lang.NullPointerException: null
at org.dyn4j.collision.narrowphase.Epa.getPenetration(Epa.java:142) ~[dyn4j-3.1.9.jar:3.1.9]
at org.dyn4j.collision.narrowphase.Gjk.detect(Gjk.java:178) ~[dyn4j-3.1.9.jar:3.1.9]
at org.dyn4j.dynamics.World.detect(World.java:2271) ~[dyn4j-3.1.9.jar:3.1.9]
at org.dyn4j.dynamics.World.detect(World.java:2070) ~[dyn4j-3.1.9.jar:3.1.9]

zoom
Posts: 143
Joined: Sun Mar 17, 2013 3:57 pm
Location: Stockholm, Sweden
Contact:

Re: NPE using the new detect methods

Postby zoom » Sun Apr 20, 2014 9:36 am

Here is a unit test:

Code: Select all

@Test
public void testCircleConvex() {
   World world = new World() ;
   Circle c = new Circle(20.0) ;
   ArrayList<DetectResult> result = new ArrayList<>() ;
   Body b = new Body();
   b.addFixture(c) ;
   world.addBody(b);
   world.detect(c, new CategoryFilter(2,15), true, false, result) ;
}


I don't think I'm adding circles to the world in my game but I guess it could be the same case that I'm hitting anyway.

zoom
Posts: 143
Joined: Sun Mar 17, 2013 3:57 pm
Location: Stockholm, Sweden
Contact:

Re: NPE using the new detect methods

Postby zoom » Sun Apr 20, 2014 10:01 am

A work around is to either use AABB instead of convex or stick to the deprecated detect method. Here is my full unit test case.

Code: Select all


public class Dyn4JDetectTest {
   @Test
   public void testCircleConvexWithFilter() {
      World world = new World() ;
      Circle c = new Circle(20.0) ;
      ArrayList<DetectResult> result = new ArrayList<>() ;
      Body b = new Body();
      b.addFixture(new Circle(1.0)) ;
      world.addBody(b);
      world.detect(c, new CategoryFilter(2,15), true, false, result) ;
      Assert.assertEquals(1, result.size());
   }
   
   @Test
   public void testCircleConvexDefaultFlags() {
      World world = new World() ;
      Circle c = new Circle(20.0) ;
      ArrayList<DetectResult> result = new ArrayList<>() ;
      Body b = new Body();
      b.addFixture(new Circle(1.0)) ;
      world.addBody(b);
      world.detect(c, result) ;
      Assert.assertEquals(1, result.size());
   }
   
   @Test
   public void testAABBWithFilter() {
      World world = new World() ;
      AABB c = new AABB(20.0) ;
      ArrayList<DetectResult> result = new ArrayList<>() ;
      Body b = new Body();
      b.addFixture(new Circle(1.0)) ;
      world.addBody(b);
      world.detect(c, new CategoryFilter(2,15), true, false, result) ;
      Assert.assertEquals(1, result.size());
   }
   
   @Test
   public void testDeprecatedConvex() {
      World world = new World() ;
      Circle c = new Circle(20.0) ;
      Body b = new Body();
      b.addFixture(new Circle(1.0)) ;
      world.addBody(b);
      List<Body> detect = world.detect(c);
      Assert.assertEquals(1, detect.size());
   }
}

William
Site Admin
Posts: 349
Joined: Sat Feb 06, 2010 10:23 pm

Re: NPE using the new detect methods

Postby William » Sun Apr 20, 2014 1:54 pm

Thanks for the test case.

This is definitely a bug. I've attached a fixed version for you to test out when you get a chance.

William
Attachments
dyn4j-v3.1.10-beta1.jar
dyn4j 3.1.10 beta1
(354.88 KiB) Downloaded 128 times

zoom
Posts: 143
Joined: Sun Mar 17, 2013 3:57 pm
Location: Stockholm, Sweden
Contact:

Re: NPE using the new detect methods

Postby zoom » Sun Apr 20, 2014 2:33 pm

Yeah, that fixed it :) Thanks for the quick bug fix.

William
Site Admin
Posts: 349
Joined: Sat Feb 06, 2010 10:23 pm

Re: NPE using the new detect methods

Postby William » Sun Jul 20, 2014 12:57 pm

I've published version 3.1.10 which includes this fix.

William

zoom
Posts: 143
Joined: Sun Mar 17, 2013 3:57 pm
Location: Stockholm, Sweden
Contact:

Re: NPE using the new detect methods

Postby zoom » Sun Jul 20, 2014 1:47 pm

Nice :) I've abandoned my 2D-hobby game for other projects but I'll dig it up and give the latest dyn4j a spin.


Return to “Bugs, Enhancements, Feedback”

Who is online

Users browsing this forum: No registered users and 2 guests