Jump to content

Recommended Posts

Posted (edited)

Hi guys,

I started getting this hang when adding this code in this class:

	@Nonnull
    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
        NBTTagList wands = new NBTTagList();
        NBTTagList compounds = new NBTTagList();
        for (Map.Entry<ItemWand,NBTTagCompound> entry:
             mWandNBTTagMap.entrySet()) {
            wands.appendTag(NBTHelper.serializeResourceLocation(entry.getKey().getRegistryName()));
            compounds.appendTag(entry.getValue());
        }
        compound.setTag(KEY_WANDS,wands);
        compound.setTag(KEY_COMPOUNDS,compound);
        return super.writeToNBT(compound);
    }

    @Override
    public void readFromNBT(NBTTagCompound compound) {
        if (compound.hasKey(KEY_WANDS) && compound.hasKey(KEY_COMPOUNDS)) {
            Iterator<NBTBase> wands = ((NBTTagList) compound.getTag(KEY_WANDS)).iterator();
            Iterator<NBTBase> compounds = ((NBTTagList) compound.getTag(KEY_COMPOUNDS)).iterator();
            while (wands.hasNext() && compounds.hasNext()) {
                ResourceLocation registryName = NBTHelper.deserializeResourceLocation((NBTTagString) wands.next());
                NBTTagCompound compoundTag = (NBTTagCompound) compounds.next();
                if (registryName!=null && compoundTag!=null &&CommonProxy.ITEM_REGISTRY.containsKey(registryName)) {
                    Item wand = CommonProxy.ITEM_REGISTRY.getValue(registryName);
                    if (wand instanceof ItemWand) {
                        ItemWand itemWand = (ItemWand) wand;
                        mWandNBTTagMap.put(itemWand,compoundTag);
                    } else {
                        Log.warn("Could not deserialize TileEntityWandCraftingTable wand-compound map entry. Retrieved Item but item for "+registryName+" was not an ItemWand! Some Mod overrode this with an incompatible Item!");
                    }
                } else {
                    Log.debug("Could not deserialize TileEntityWandCraftingTable wand-compound map entry. This is probably due to updating Mods.");
                }
            }
            if (wands.hasNext()) {
                Log.warn("TileEntityWandCraftingTable:Noticed corrupted NBT-Data! There are too many Wand-Entries for the given Compounds! This may lead to errors further down the line!");
            } else if (compounds.hasNext()) {
                Log.warn("TileEntityWandCraftingTable:Noticed corrupted NBT-Data! There are too many Compound-Entries for the given Compounds! This may lead to errors further down the line!");
            }
        }else {
            Log.debug("Could not deserialize TileEntityWandCraftingTable wand-compound map. This is probably due to updating Spellcraft.");
        }
        super.readFromNBT(compound);
    }

 

I can see nothing obviously wrong with this code and especially nothing justifying getting an StackOverflowError on the FileIO Thread sometime after the world was opened:

[10:59:04] [File IO Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: java.lang.StackOverflowError
[10:59:04] [File IO Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at java.io.DataOutputStream.write(DataOutputStream.java:107)
[10:59:04] [File IO Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at java.io.DataOutputStream.writeUTF(DataOutputStream.java:401)
[10:59:04] [File IO Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at java.io.DataOutputStream.writeUTF(DataOutputStream.java:323)
[10:59:04] [File IO Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at net.minecraft.nbt.NBTTagString.write(NBTTagString.java:29)
[10:59:04] [File IO Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at net.minecraft.nbt.NBTTagList.write(NBTTagList.java:39)
[10:59:04] [File IO Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at net.minecraft.nbt.NBTTagCompound.writeEntry(NBTTagCompound.java:581)
[10:59:04] [File IO Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at net.minecraft.nbt.NBTTagCompound.write(NBTTagCompound.java:39)
[10:59:04] [File IO Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at net.minecraft.nbt.NBTTagCompound.writeEntry(NBTTagCompound.java:581)
[10:59:04] [File IO Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at net.minecraft.nbt.NBTTagCompound.write(NBTTagCompound.java:39)
[10:59:04] [File IO Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at net.minecraft.nbt.NBTTagCompound.writeEntry(NBTTagCompound.java:581)
[10:59:04] [File IO Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at net.minecraft.nbt.NBTTagCompound.write(NBTTagCompound.java:39)
  ... omitted rest of the stacktrace, because it was an StackOverflowError

The fact, that it comes through an NBTTagString propably suggests, that it has something to do with saving the Wand Registry Names, because these are the only ones generating NBTTagStrings in my NBTHelper utility class.

Does anyone have an idea what could have caused this?

The reason why I'm doing this saving is, because I want the user not to be able to recraft a specific Item with new properties everytime he removes a single component...

(Before someone asks, I know, that the calls to getSubStack are currently unsafe (mutability))

Edited by Major Tuvok
Posted
1 hour ago, Major Tuvok said:

compound.setTag(KEY_COMPOUNDS,compound);

 

You're storing compound inside of itself, leading to infinite recursion when Minecraft tries to write the NBT to disk.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.