SMAPI - Stardew Modding API

SMAPI - Stardew Modding API

971k Downloads

Some content loads broken in SMAPI 2.1 beta

Pathoschild opened this issue ยท 1 comments

commented

In some cases SMAPI 2.1 beta uses the absolute file path as an asset key, which causes errors. This didn't happen in earlier versions.

For example, Custom Furniture has this code:

texture = helper.Content.Load<Texture2D>(Path.Combine("Furniture", data.folderName, data.texture));

That causes this error on Windows (see full log):

Custom Furniture failed on entry and might not work correctly. Technical details:
StardewModdingAPI.Framework.Exceptions.SContentLoadException: Custom Furniture failed loading content asset 'C:\Users\Rebecka\Desktop\Steam\steamapps\common\Stardew Valley\Mods\CustomFurniture\Furniture\Coffee table\Coffee table b.png' from ModFolder.
---> Microsoft.Xna.Framework.Content.ContentLoadException: Error loading "C:\Users\Rebecka\Desktop\Steam\steamapps\common\Stardew Valley\Mods\CustomFurniture\Furniture\Coffee table\Coffee table b.png". Cannot open file.
---> System.ArgumentException: Invalid filename. TitleContainer.OpenStream requires a relative URI.
  at Microsoft.Xna.Framework.TitleContainer.OpenStream(String name)
  at Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName)
  --- End of inner exception stack trace ---
  at Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName)
  at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject)
  at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName)
  at StardewValley.LocalizedContentManager.Load[T](String assetName)
  at StardewModdingAPI.Framework.SContentManager.<>n__2[T](String assetName)
  at StardewModdingAPI.Framework.SContentManager.<>c__DisplayClass40_0`1.<LoadImpl>b__1() in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\SContentManager.cs:line 512
  at StardewModdingAPI.Framework.Utilities.ContextHash`1.Track[TResult](T key, Func`1 action) in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\Utilities\ContextHash.cs:line 53
  at StardewModdingAPI.Framework.SContentManager.<>c__DisplayClass40_0`1.<LoadImpl>b__0() in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\SContentManager.cs:line 509
  at StardewModdingAPI.Framework.SContentManager.WithWriteLock[T](Func`1 action) in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\SContentManager.cs:line 794
  at StardewModdingAPI.Framework.SContentManager.LoadImpl[T](String assetName, ContentManager instance) in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\SContentManager.cs:line 490
  at StardewModdingAPI.Framework.SContentManager.LoadFor[T](String assetName, ContentManager instance) in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\SContentManager.cs:line 207
  at StardewModdingAPI.Framework.SContentManager.Load[T](String assetName) in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\SContentManager.cs:line 190
  at StardewModdingAPI.Framework.ModHelpers.ContentHelper.Load[T](String key, ContentSource source) in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\ModHelpers\ContentHelper.cs:line 128
  --- End of inner exception stack trace ---
  at StardewModdingAPI.Framework.ModHelpers.ContentHelper.Load[T](String key, ContentSource source) in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\ModHelpers\ContentHelper.cs:line 136
  at CustomFurniture.CustomFurniture.build(CustomFurnitureData data, String objectID, Vector2 tile) in C:\Users\David\Documents\GitHub\Stardew-Valley-Mods\CustomFurniture\CustomFurniture.cs:line 40
  at CustomFurniture.CustomFurniture..ctor(CustomFurnitureData data, String objectID, Vector2 tile) in C:\Users\David\Documents\GitHub\Stardew-Valley-Mods\CustomFurniture\CustomFurniture.cs:line 34
  at CustomFurniture.CustomFurnitureMod.loadPacks() in C:\Users\David\Documents\GitHub\Stardew-Valley-Mods\CustomFurniture\CustomFurnitureMod.cs:line 58
  at CustomFurniture.CustomFurnitureMod.Entry(IModHelper helper) in C:\Users\David\Documents\GitHub\Stardew-Valley-Mods\CustomFurniture\CustomFurnitureMod.cs:line 24
  at StardewModdingAPI.Program.LoadMods(IModMetadata[] mods, JsonHelper jsonHelper, SContentManager contentManager) in C:\source\_Stardew\SMAPI\src\SMAPI\Program.cs:line 800
``
commented

Turns out it's a bug in Custom Furniture (see Platonymous/Stardew-Valley-Mods#10). I added logic in SMAPI 2.1 to explicitly block absolute asset paths, to make this more clear.