Recursive exception?

Discussion in 'Plugin Development' started by dark navi, Dec 24, 2012.

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

    dark navi

    Hey guys, I recently set it up on our server so users could look into containers in spectating mode. The way I did this is through copying the inventory and just opening it for them.

    Here is the code I use:
    Code:
     BlockState blockState = event.getClickedBlock().getState();
                    if (blockState instanceof InventoryHolder) {
                        // Right-clicking an inventory holder opens a copy
                        InventoryHolder invHolder = (InventoryHolder) event.getClickedBlock().getState();
                        Player player = ((Player) event.getPlayer());
                        Inventory initInventory = invHolder.getInventory();
                        Inventory dupeInventory = Bukkit.createInventory(player, initInventory.getType());
                   
                        dupeInventory.setContents(initInventory.getContents());
                   
                        player.openInventory(dupeInventory);
                        event.setCancelled(true);
                    }
                  
    I should note that this seems to work fine most of the time. I recently looked at our server and was meet this this crash:
    Code:
    Description: Exception in server tick loop
     
    java.lang.StackOverflowError
        at net.minecraft.server.v1_4_6.ItemStack.setData(ItemStack.java:142)
        at net.minecraft.server.v1_4_6.ItemStack.<init>(ItemStack.java:41)
        at net.minecraft.server.v1_4_6.ItemStack.cloneItemStack(ItemStack.java:222)
        at net.minecraft.server.v1_4_6.Container.clickItem(Container.java:141)
        at net.minecraft.server.v1_4_6.Container.a(Container.java:271)
        at net.minecraft.server.v1_4_6.Container.clickItem(Container.java:143)
     
            Repeating 1000+ times
        at net.minecraft.server.v1_4_6.Container.a(Container.java:271)
        at net.minecraft.server.v1_4_6.Container.clickItem(Container.java:143)
    The crash report just says Exception in server tick loop. It looks to me like it's calling a() and then clickItem() over and over again. This is using the latest DEV build as of this morning, so I suppose this could be a bug in CB still.

    Any ideas about this one? Do I need to do some garbage collection on these inventories that I am making?
     
  2. Offline

    fireblast709

    Maybe because you are creating an Inventory each time. Try creating one reference to it and change that each time you create one. (So something like a HashMap, and setting the inventory there each time. Thus you only have one reference at a time)
     
    dark navi likes this.
Thread Status:
Not open for further replies.

Share This Page