Crash report after teleporting all players to another map

Discussion in 'Plugin Development' started by zajacmp3, Aug 18, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    zajacmp3

    Hello,

    I sometimes have a crash report on function that removes players from map to another one.
    Function is working perfectly well sometimes and sometimes not. I can't find why it does crash server sometimes.

    Here is the crash report:
    Code:
    2012-08-18 07:38:16 [INFO] Removing players from 1 map
    2012-08-18 07:38:16 [SEVERE] java.util.ConcurrentModificationException
    2012-08-18 07:38:16 [SEVERE]     at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:782)
    2012-08-18 07:38:16 [SEVERE]     at java.util.ArrayList$Itr.next(ArrayList.java:754)
    2012-08-18 07:38:16 [SEVERE]     at net.minecraft.server.World.tickEntities(World.java:1143)
    2012-08-18 07:38:16 [SEVERE]     at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:567)
    2012-08-18 07:38:16 [SEVERE]     at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
    2012-08-18 07:38:16 [SEVERE]     at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
    2012-08-18 07:38:16 [SEVERE]     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
    2012-08-18 07:38:16 [SEVERE]     at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    2012-08-18 07:38:16 [SEVERE] Encountered an unexpected exception ConcurrentModificationException
    java.util.ConcurrentModificationException
        at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:782)
        at java.util.ArrayList$Itr.next(ArrayList.java:754)
        at net.minecraft.server.World.tickEntities(World.java:1143)
        at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:567)
        at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
        at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    2012-08-18 07:38:16 [SEVERE] This crash report has been saved to: /minecraft/./crash-reports/crash-2012-08-18_07.38.16-server.txt
    
    Any ideas?

    My function that is running here:
    Code:
        public static void removePlayersFromMap(String map) {
            System.out.println("Removing players from "+map+" map");
            removeAllPlayerInDeathState();
            World world = Bukkit.getServer().getWorld("Lobby");
            List<Player> players = Bukkit.getServer().getWorld(map).getPlayers();
            for(int temp = 0; temp<players.size() ; temp++){
                Location location = players.get(temp).getLocation();
                location.setWorld(world);
                location.setX(-73);
                location.setY(65);
                location.setZ(255);
                players.get(temp).teleport(location);
                if(players.get(temp).isDead()){
                    players.get(temp).kickPlayer("Kicked! Cause of being dead and inactive on reloading map!");
                    File datfile = new File("Lobby/players/"+players.get(temp).getName()+".dat");
                    datfile.delete();
                }
            }
        }

    I need any ideas how to avoid crashes like that. Any ideas that I can work and try to work with.
     
  2. Looking at the position where the CME is occuring (when the server ticks its entities), it appears to me that you are running that code from another thread.
    Never every possibly do teleporting or any change to the world from a separate thread! I can't stress that enough. Almost nothing of the Bukkit API or Minecraft server in general is thread-safe, and eventually it will cause world corruption and server crashes.

    http://wiki.bukkit.org/Scheduler_Programming
    If you use the scheduler already, make sure everything is "sync" instead of "async".
     
  3. Offline

    zajacmp3

    Okay, I am getting somewhere. Just need a bit more of your guidance.
    This function is in main class and from some point it is really in scheduler. So I will change it to "sync" cause it is now "async".

    And another question. I have now 2x 1GHZ in my hosting. So that may be not enough computing power you say for this thread that I am running yes?
    If I change the hosting to some better like I think to e24cloud.com will it minimize the risk of future crashes with it?
     
  4. No, it depends on the fact that two things that work at the same time use the same data, no matter how fast these run, they still run next to each other. Also, there is no benefit whatsoever of having your thing threaded, because it doesn't do any long-taking operations.
    The time and CPU effort it takes to launch the new Thread is way more than what your code "slows" the main thread.
     
Thread Status:
Not open for further replies.

Share This Page