Mod Texture Load failures

Discuss coding questions, pull requests, and implementation details.
jimfcarroll
Posts: 71
Joined: Tue Feb 12, 2019 12:55 am

Mod Texture Load failures

Post by jimfcarroll » Tue Sep 17, 2019 1:01 pm

I decided to try to debug some of the texture load failures that happen when you load textures from a Mod that haven't been prepared correctly with the editor. I get (eventually) thousands of errors that read Texture atlas needs textures to have Readable flag set! There's a 1/2 dozen posts on this online but there doesn't seem to be a way to programatically edit the texture.

Anyway, before I spend more time on this I wanted to see if it was worth it since it seems, based on what I'm reading, it will take rewriting the texture with an editor which might not be a small feat.

User avatar
King of Worms
Posts: 3209
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Re: Mod Texture Load failures

Post by King of Worms » Tue Sep 17, 2019 8:56 pm

jimfcarroll wrote:
Tue Sep 17, 2019 1:01 pm
I decided to try to debug some of the texture load failures that happen when you load textures from a Mod that haven't been prepared correctly with the editor. I get (eventually) thousands of errors that read Texture atlas needs textures to have Readable flag set! There's a 1/2 dozen posts on this online but there doesn't seem to be a way to programatically edit the texture.

Anyway, before I spend more time on this I wanted to see if it was worth it since it seems, based on what I'm reading, it will take rewriting the texture with an editor which might not be a small feat.
I set read/write flags in unity inspector. You can batch-select as many files as u want and than change this flag on all of them.

Which mods have this problem?

jimfcarroll
Posts: 71
Joined: Tue Feb 12, 2019 12:55 am

Re: Mod Texture Load failures

Post by jimfcarroll » Tue Sep 17, 2019 11:34 pm

King of Worms wrote:
Tue Sep 17, 2019 8:56 pm
Which mods have this problem?
Good question. With only the DREAM mod installed (though I know there's a bunch of dfmod files as part of this) I get 40 of these as the startup screen is loading (Note: I added my own log statement so the line numbers for TextureReader.cs are slightly off):

Code: Select all

Texture atlas needs textures to have Readable flag set!
UnityEngine.Texture2D:PackTextures(Texture2D[], Int32, Int32, Boolean)
DaggerfallWorkshop.Utility.TextureReader:GetTexture2DAtlas(GetTextureSettings, SupportedAlphaTextureFormats) (at Assets/Scripts/Utility/TextureReader.cs:434)
DaggerfallWorkshop.MaterialReader:GetMaterialAtlas(Int32, Int32, Int32, Int32, Rect[]&, RecordIndex[]&, Int32, Boolean, Int32, Boolean, Boolean) (at Assets/Scripts/MaterialReader.cs:531)
DaggerfallWorkshop.DaggerfallBillboardBatch:SetMaterial(Int32, Boolean) (at Assets/Scripts/Internal/DaggerfallBillboardBatch.cs:187)
DaggerfallWorkshop.Utility.GameObjectHelper:CreateBillboardBatchGameObject(Int32, Transform) (at Assets/Scripts/Utility/GameObjectHelper.cs:1242)
DaggerfallWorkshop.Utility.GameObjectHelper:CreateRMBBlockGameObject(DFBlock, Int32, Int32, Boolean, DaggerfallRMBBlock, DaggerfallBillboardBatch, DaggerfallBillboardBatch, DaggerfallBillboardBatch, TextureAtlasBuilder, DaggerfallBillboardBatch, ClimateNatureSets, ClimateSeason) (at Assets/Scripts/Utility/GameObjectHelper.cs:481)
DaggerfallWorkshop.Utility.GameObjectHelper:CreateRMBBlockGameObject(String, Int32, Int32, Boolean, DaggerfallRMBBlock, DaggerfallBillboardBatch, DaggerfallBillboardBatch, DaggerfallBillboardBatch, TextureAtlasBuilder, DaggerfallBillboardBatch, ClimateNatureSets, ClimateSeason) (at Assets/Scripts/Utility/GameObjectHelper.cs:410)
DaggerfallWorkshop.Game.UserInterfaceWindows.DaggerfallUnitySetupGameWizard:CreateBackdrop() (at Assets/Scripts/Game/UserInterfaceWindows/DaggerfallUnitySetupGameWizard.cs:247)
DaggerfallWorkshop.Game.UserInterfaceWindows.DaggerfallUnitySetupGameWizard:ShowOptionsPanel() (at Assets/Scripts/Game/UserInterfaceWindows/DaggerfallUnitySetupGameWizard.cs:419)
DaggerfallWorkshop.Game.UserInterfaceWindows.DaggerfallUnitySetupGameWizard:ShowNextStage() (at Assets/Scripts/Game/UserInterfaceWindows/DaggerfallUnitySetupGameWizard.cs:608)
DaggerfallWorkshop.Game.UserInterfaceWindows.DaggerfallUnitySetupGameWizard:Update() (at Assets/Scripts/Game/UserInterfaceWindows/DaggerfallUnitySetupGameWizard.cs:184)
DaggerfallWorkshop.Game.DaggerfallUI:Update() (at Assets/Scripts/Game/DaggerfallUI.cs:362)
There's no mod loading in the stack trace so I don't know where the original textures came from. This doesn't happen at all with the vanilla DFU.

I couldn't find a method on `Texture2D` that would tell me if the texture was going to have this problem when it was given to `PackTextures` but it also seems to cause `Apply` to throw an exception so I added this right before the call:

Code: Select all

            Debug.LogFormat("Total number of textures: {0}", albedoTextures.Count);
            foreach (var cur in albedoTextures)
            {
                try
                {
                    cur.Apply();
                }catch
                {
                    Debug.LogFormat("    ----> {0}, {1}", cur.name, cur);
                }
            }
The 40 names of the Textures are:

Code: Select all

201_0-0
201_0-1
201_0-2
201_0-3
201_1-0
201_1-1
201_1-2
201_1-3
201_2-0
201_3-0
201_3-1
201_3-2
201_3-3
201_4-0
201_4-1
201_4-2
201_4-3
201_5-0
201_5-1
201_5-2
201_5-3
201_6-0
201_6-1
201_6-2
201_7-0
201_7-1
201_7-2
201_7-3
201_8-0
201_8-1
201_8-2
201_8-3
201_9-0
201_9-1
201_9-2
201_9-3
201_10-0
201_10-1
201_10-2
201_11-0
There's probably a better way to figure this out. I'm open to suggestions.

User avatar
King of Worms
Posts: 3209
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Re: Mod Texture Load failures

Post by King of Worms » Wed Sep 18, 2019 6:30 am

Will check those textures thank u.

I never seen any deffinitive guide on read/write :(
All is just few msgs during the years.. so its a miracle it works and has only 40 reports mostly from one single archive from grand total of 10 000s

jimfcarroll
Posts: 71
Joined: Tue Feb 12, 2019 12:55 am

Re: Mod Texture Load failures

Post by jimfcarroll » Wed Sep 18, 2019 12:28 pm

Maybe the tool that packs the mod components into the .dfmod file can check the textures before putting them in? If you point me to the code where that's done I can take a look.

User avatar
King of Worms
Posts: 3209
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Re: Mod Texture Load failures

Post by King of Worms » Wed Sep 18, 2019 10:30 pm

jimfcarroll wrote:
Wed Sep 18, 2019 12:28 pm
Maybe the tool that packs the mod components into the .dfmod file can check the textures before putting them in? If you point me to the code where that's done I can take a look.
Please let The Lacus know about it. He knows a lot about modding framework. Im just a peasant using his work :) either he will know or he will provide a direction. Sry I cant help more.

I can only confirm that having all the flags right is not trivial, esp for newcommers to modding.

Thank you for investigating this stuff!

User avatar
TheLacus
Posts: 1161
Joined: Wed Sep 14, 2016 6:22 pm
Contact:

Re: Mod Texture Load failures

Post by TheLacus » Thu Sep 19, 2019 10:44 am

Read/write flag is required when a texture needs to be edited at run time. For example many UI images are cut to individual pieces (buttons, panels) ; another example is the optional x16 grid which is created from original texture.

The modding documentation explain when this flag is needed, or at least it aim to; currently there is not a complete list of textures but is possible to make one, provided someone want to invest what could be a considerable amount of time in this.
Mod System documentation - Learn how to create mods for Daggerfall Unity.
Modder Discussion - General help and discussion for the mod system.
Github Issues - Submit a bug report for the game, including the mod system.

jimfcarroll
Posts: 71
Joined: Tue Feb 12, 2019 12:55 am

Re: Mod Texture Load failures

Post by jimfcarroll » Thu Sep 19, 2019 12:29 pm

My suggestion was to change the tool that builds the .dfmod file to validate any textures by checking the flag. If you think this makes sense and want to point me to the right area of the codebase, I'll give it a shot.

As it is, with a large swath of mods installed, I get this error I mentioned 1000's of times (the count of errors stops at 999+).

User avatar
TheLacus
Posts: 1161
Joined: Wed Sep 14, 2016 6:22 pm
Contact:

Re: Mod Texture Load failures

Post by TheLacus » Thu Sep 19, 2019 1:37 pm

jimfcarroll wrote:
Thu Sep 19, 2019 12:29 pm
My suggestion was to change the tool that builds the .dfmod file to validate any textures by checking the flag. If you think this makes sense and want to point me to the right area of the codebase, I'll give it a shot.

As it is, with a large swath of mods installed, I get this error I mentioned 1000's of times (the count of errors stops at 999+).
I think i should explain what Read/Write flag does. By default a texture is stored inside video-ram, which means that cpu code can't access it directly. Sometimes is necessary to perform modifications to a texture, so the workaround is to keep a copy of texture data in ram, make changes to this copy and then upload it to v-ram. This means that additional memory is used, so is not acceptable to force this flag on all textures bundled with a mod. It's up mod authors to set required inspector options for each texture.

Some automatization might be possible if we had a list of textures that need it; but, as i said, it would be a laborious work to write it and it would also be susceptible of changes.
Mod System documentation - Learn how to create mods for Daggerfall Unity.
Modder Discussion - General help and discussion for the mod system.
Github Issues - Submit a bug report for the game, including the mod system.

jimfcarroll
Posts: 71
Joined: Tue Feb 12, 2019 12:55 am

Re: Mod Texture Load failures

Post by jimfcarroll » Thu Sep 19, 2019 2:17 pm

Thanks for the explanation. That makes sense.

Perhaps I could automate determining which ones require it. Any texture passed to PackTextures here:

https://github.com/Interkarma/daggerfal ... er.cs#L423

... fails if the read/write flag isn't set. The problem is, the context of which textures are passed there (that is, their origin) is lost by the time that call is made, so I can't track where the textures originally came from without some changes. Would it be worth doing that?

Also, would it be worth programatically setting the read/write flag in places like that call. I know this isn't trivial and if it's possible, probably requires something along the lines of rewriting the texture to disk then using editor functionality to change the flag, then reloading them.

Post Reply