0

I'm trying to add diferent Parcel objects at the same position. My code looks like this, where Rock extends Parcel:

    Point origin = null;
    Rock rock = null;
    for (int i = 0; i < ROCKS; i++) {
        if (i % 10 == 0) {
            origin = model.getRandomUnoccupiedPosition(sim.getRandomGenerator());
            rock = new Rock(origin, destination);
            sim.register(rock);
        } else {
            Rock r = new Rock(origin, destination);
            model.addObjectAtSamePosition(r, rock);
        }
    }

but after a few iterations, I get this error when trying to pick up the Rock with a Vehicle:

Exception in thread "Thread-1" java.lang.IllegalArgumentException: Parcel must be registered and must be either ANNOUNCED or AVAILABE, it is: null. Parcel: [Parcel-103f852].
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:146)
    at com.github.rinde.rinsim.core.model.pdp.DefaultPDPModel.pickup(DefaultPDPModel.java:175)
    at me.alexrs.mas.roveragent.RoverAgent.tickImpl(RoverAgent.java:105)
    at com.github.rinde.rinsim.core.model.pdp.Vehicle.tick(Vehicle.java:55)
    at com.github.rinde.rinsim.core.model.time.TimeModel.tickImpl(TimeModel.java:139)
    at com.github.rinde.rinsim.core.model.time.SimulatedTimeModel.doStart(SimulatedTimeModel.java:32)
    at com.github.rinde.rinsim.core.model.time.TimeModel.start(TimeModel.java:94)
    at com.github.rinde.rinsim.ui.SimulationViewer$5.run(SimulationViewer.java:399)

The only Rock that is registered is the one that has been registered in the Simulator, but if I try to register more than one Rock, I get an exception saying that two objects can't be at the same position.

Alexrs95
  • 392
  • 1
  • 3
  • 13
  • It should be possible to add two RoadUsers (not MovingRoadUser) at the same location in the CollisionPlaneRoadModel, I believe this is a bug, I'll fix this ASAP. The exception that you are getting seems odd, can you add more code such that it becomes a [runnable example](https://stackoverflow.com/help/mcve)? – rinde May 08 '17 at 16:53
  • This bug is now fixed in the latest snapshot (4.5.0-SNAPSHOT). – rinde May 08 '17 at 18:56
  • Now it seems to work. Thanks! – Alexrs95 May 09 '17 at 13:03
  • Are you able to reproduce the issue that triggered the exception you posted? – rinde May 09 '17 at 15:07
  • Yes, if I use `model.addObjectAtTheSamePosition(obj1, obj2)` without calling `sim.register(obj1)`, the exception appears, but now I can just call `sim.register(obj)` for every object I want to add, being `obj` a `Parcel`, and I can initialise several `Parcel`s at the same position. – Alexrs95 May 13 '17 at 14:38

0 Answers0