Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] icons visual issues (hammer piece table) #389

Open
galathil opened this issue Feb 11, 2023 · 3 comments
Open

[BUG] icons visual issues (hammer piece table) #389

galathil opened this issue Feb 11, 2023 · 3 comments

Comments

@galathil
Copy link

Details: icons in hammer table has sometimes visual issues
Jotunn Version: 2.10.1.0
Jotunn Submodule(if applicable): none
Repeatability(Consistent(100%), Inconsistent(50%), Rare(1%), Unknown(==1)): Inconsistent or rare

Problem Description:
I've develop a mod that add vanilla prefabs as building pieces in the game. The code wich generate the icon is :

private static Sprite CreatePrefabIcon(GameObject prefab)
{
    Sprite result = RenderManager.Instance.Render(prefab, RenderManager.IsometricRotation);
    return result;
}

The mod is available here : https://github.com/galathil/MoreVanillaBuilds
Note that my mods icons are affected by this random issue, not vanilla icons. You need to restart the game to clear this issue.
Other mods in plugin folder :

Maybe i make a mistake with RenderManager but i look other mods that include custom content in the game and syntax is the same.

Expected Behaviour:
No visual glitches

Actual Behaviour:
Visual glitches sometimes :

Link to your server's and client's LogOutput.log
No error in logs

@sirskunkalot
Copy link
Member

Hey, thanks for the report. I am not sure why this happens yet, has to be investigated more. Which will be hard when its not reproducible. But as some sort of "workaround" you could use the Render Manager cache for caching the generated icons to disk. This will also improve mod loading time a lot since you generate quite a lot of icons. Check out the tutorial section for more information: https://valheim-modding.github.io/Jotunn/tutorials/renderqueue.html#caching-icons

@galathil
Copy link
Author

Thanks for you reply. i'll implement caching in my mod and if i find any additionnal infos (or evidence) about the bug, i will post here.

@MSchmoecker
Copy link
Member

The underling issue seems to be a race condition. When rendering an icon the same frame as the game is switching scenes, the bug can occur. Many important Valheim singletons are created during a scene change, like ZNetscene.Awake or ObjectDB.Awake.

A reliable workaround is to wait one frame before rendering icons.

For example a coroutine can be used:

private List<GameObject> prefabsToRender = new List<GameObject>();

private void Awake() {
    prefabsToRender.Add(prefab);
}

private void OnObjectDBAwake() {
    StartCoroutine(RenderSprites());
}

private static IEnumerator RenderSprites() {
    yield return null; // wait one frame

    foreach (var prefab in prefabsToRender) {
        Sprite result = RenderManager.Instance.Render(prefab, RenderManager.IsometricRotation);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants