Search code examples
anylogic

Java IllegalStateException when removing items on conveyor in AnyLogic


I am using the following codes to remove the items on conveyors at some moments in AnyLogic. But sometimes it throws an error when executed.

for (ConveyorPath conveyor : zweiterTeilConveyor) {
    List list = conveyor.getAgents();
    for (Object a : list) {
        Kerze k = (Kerze) a;
        conveyor.removeAgent(k);
        kToRemove.add(k);
    }
}

The error message:

Exception during discrete event execution:
Internal error: Entity 147645 at blocked Hold root.convey_FTM.conveyorEnter.?<MHLSettings>.conveyorSystems_xjal[4].asyncStationControllers_xjal[1].enterBlocker hasn't registered in it.
java.lang.IllegalStateException: Internal error: Entity 147645 at blocked Hold root.convey_FTM.conveyorEnter.?<MHLSettings>.conveyorSystems_xjal[4].asyncStationControllers_xjal[1].enterBlocker hasn't registered in it.

Sadly the message itself doesn't provide too much information for me and I have no clue how to fix it. I guess at the moment the agent is waiting at for the conveyor's enter port to be free. Do you have any ideas what the error is about and how to avoid it?


Solution

  • You are not supposed to remove elements from conveyors via code. Hence the error.

    Instead, use the outRedirect port at the bottom:

    enter image description here

    As per the help, this is how you can make agents leave conveyors prematurely