Ludeon Forums

Ludeon Forums

  • April 03, 2020, 07:30:50 PM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [1.0] Duplicate operations under "Add bill" (AllRecipes bug)  (Read 639 times)

SineSwiper

  • Muffalo
  • *
  • Posts: 6
  • Refugee
    • View Profile
[1.0] Duplicate operations under "Add bill" (AllRecipes bug)
« on: November 04, 2019, 12:53:57 PM »

NOTE: This is a vanilla bug because it's within the core Verse's library.

When a mod dynamically adds recipe defs (or add recipes to pawns) to the game, RimWorld proper has a tendency to display duplicate recipes within Add Bills.  Here is an example.  Yes, that's a lot of mods, but here me out:

The Verse.ThingDef.AllRecipes method creates a cached version of recipes by looking through this.recipes, populating its cache object, and then looking through DefDatabase<RecipeDef> to find recipeUsers.  In other words, it's looking in both directions for what would likely be the same set of recipes, if the dynamic recipeDef mods are adding them in correctly.  For example, Humanoid Alien Races 2.0 adds its recipes in both spots.

The important bit is that AllRecipes does NOT call RemoveDuplicates against the cached object.  So, it ends up adding all of the recipes from this.recipes and adding a duplicate set of recipes from recipeUsers.  The RimWorld.HealthCardUtility.DrawMedOperationsTab method calls AllRecipes and doesn't account for duplicates, either.  In fact, this sort of bug might slow down certain operations because it's unnecessarily searching double the recipes.  Checking both sides is probably a good idea, but it should expect duplicates, too.

I could fix this with a Harmony patch, but given that this has farther-reaching effects than just my mod, I figured it best to report it here.
Logged

SineSwiper

  • Muffalo
  • *
  • Posts: 6
  • Refugee
    • View Profile
Re: [1.0] Duplicate operations under "Add bill" (AllRecipes bug)
« Reply #1 on: November 04, 2019, 06:04:27 PM »

I've confirmed that a Harmony postfix patch against the AllRecipes getter, which is just running RemoveDuplicates, does indeed fix the duplicates I was seeing.  However, since it's running that patch on each AllRecipes get, it's a bit slower than running it against the (private) cache once.  So, it's still worth fixing on the Verse library.
Logged

ison

  • Developer
  • Planetologist
  • *****
  • Posts: 2238
    • View Profile
Re: [1.0] Duplicate operations under "Add bill" (AllRecipes bug)
« Reply #2 on: January 01, 2020, 11:06:43 AM »

Thanks for reporting. However, why would a mod add a RecipeDef to both "recipes" and "recipeUsers"? I think they are exclusive recipe sources. So it looks like a bug with this mod.
Logged

LWM

  • Colonist
  • ***
  • Posts: 759
  • Little White Mouse
    • View Profile
Re: [1.0] Duplicate operations under "Add bill" (AllRecipes bug)
« Reply #3 on: January 03, 2020, 12:35:15 PM »

One obvious answer presents itself to me:  Mod creators don't know they should only have one source?
Logged