Jump to content

When to fix a bug?


Recommended Posts

  So today I noticed I've got a mistake in the logic for assigning IDs to assets. So my question is how much time should I put into fixing it now? Would it make more sense to just move onto other work and simply make a note that I need to fix this? That's kind of a hard question for me to answer. I'm sure it'll just annoy me until I do solve it.

  Perhaps just in terms of mental health it might be best to handle it now. If not, perhaps I should start a section for this game that is known bugs. Then as we solve them we can update the bugs as fixed. That could be fun for tracking how many things are good (or bad). And it allows me to have the fun part of bug fixing without actually using Jira again.

  Forced to use it for work, would rather not do that at home.

Link to comment
Share on other sites

Well I'll be a monkey's cousin! I figured it out! Let me take you on a journey!

public static Dictionary<System.Guid, IUniqueID> _idCache = new ();

So we've got this dictionary that is used in an editor script correct?

What happens is when we create new assets, or load the project in editor, we check if this cache is currently empty. If it IS that means that you likely just opened Unity for the first time. Or maybe your power went out because the breakers are stupid...guess which one happens here sometimes.

Now this is fine, but how do we know when an asset is *deleted*? That's a good question, we can't check if the deleted item matches an ID in the dictionary because its already destroyed by the time we know. All we know is where it used to be and that it was destroyed.

However we DO know something was deleted.

            if (deletedAssets != null && deletedAssets.Length > 0)
            {
                //Clear out any null entries that snuck in.
                foreach (var IDKVP in _idCache)
                {
                    if (IDKVP.Value == null)
                    {
                        _idCache.Remove(IDKVP.Key);
                    }
                }
            }

So what we do is iterate through the cache, which is quite large, and remove all of the null assets from it. Could we do this more efficiently? Probably. Will we? Probably not. Because this is an editor only tool and at least for now it isn't even remotely close to taxing my PC. This logic won't be in the delivered game and is literally compiled out at build time.

So, then, what was I doing wrong?

I was checking and removing deleted assets *after* I did the "Is your ID already in here?" Check. Ok, well Oaf...I still don't get it. Each new asset gets a new ID, so how would these things end up with the same ID as an old asset. Simply, they couldn't unless...

You switch scenes.

When I would leave one scene and come back I've got a static dictionary sitting in my memory. This means that initial check that checks every, single, asset goes "Holy cow! This ID is already taken! Lemme assign a new one!"

So in the end it reimports all 178 or so assets that currently exists.

Now that I've flipped the deletion logic to before the iterating through looking for duplicates we solve the issue. No longer are there x null copies of every asset in the dictionary. Now the only things in the dictionary during any check is a valid object currently loaded in the scene or related to those scene loaded assets.

So huzzah! That's a bug down! Now I can get some rest.

Link to comment
Share on other sites

×
×
  • Create New...