Jump to content

[1.10.2] Getting NBT data causing a StackOverflow error


Koenn

Recommended Posts

So I have the following code to add a tooltip to an item:

@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent event) {
    ItemStack stack = event.getItemStack();
    NBTTagCompound tag = stack.getTagCompound();
    if (tag == null) {
        return;
    }

    if (!tag.getString("infused_element").equals("")) {
        Element element = Element.valueOf(tag.getString("infused_element"));
        int level = tag.getInteger("infusion_level");

        event.getToolTip().add(String.format(TOOLTIP_FORMAT, element.toString(), RomanNumber.toRoman(level)));
    }
}

 

When in game I look at an item with this NBT tag the game crashes with the following error:

[12:03:21] [server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking player
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:789) ~[MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687) ~[MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) ~[integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536) [MinecraftServer.class:?]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
Caused by: java.lang.StackOverflowError
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:523) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:17) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:525) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:17) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:525) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:17) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:525) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:17) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:525) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:17) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:525) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:17) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:525) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:17) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:525) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:17) ~[NBTTagCompound.class:?]
at net.minecraft.nbt.NBTTagCompound.copy(NBTTagCompound.java:525) ~[NBTTagCompound.class:?]

 

Any idea what I'm doing wrong?

I'm a plugin developer, and I just started modding. Don't blame me for doing things wrong, Forge is not the same as Bukkit.

Link to comment
Share on other sites

Hi

 

It looks to me like you've somehow managed to create an NBTTagCompound "A" which contains an element that has been set to itself (i.e. "A").

So when vanilla tries to copy your "A", it keeps trying to copy all the elements including the one that points to "A", i.e. a recursive loop.

 

I'm not sure how you managed to do that.  Personally I would follow hugo's advice and use your debugger to set a breakpoint at onItemTooltip and then check what is happening when you modify the tag.

 

-TGG

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.