Jump to content

Add Component Crash to Desktop


Sigma88

Recommended Posts

I am trying to fix an issue with one of my mods.

The game seems to crash to desktop for seemingly no reason if I have a bit of code that adds a new component to an object at  "MainMenu" Start

To make it easier to reproduce, I dumbed down the whole mod to a very short plugin that has this code:

Spoiler

using UnityEngine;
using KSP.UI;


namespace SigmaRandomPlugin
{
    [KSPAddon(KSPAddon.Startup.SpaceCentre, false)]
    internal class Trigger : MonoBehaviour
    {
        void Start()
        {
            CrewListItem[] items = Resources.FindObjectsOfTypeAll<CrewListItem>();

            if (items != null)
            {
                int n = items.Length;

                for (int i = 0; i < n; i++)
                {
                    CrewListItem item = items[i];
                    if (item != null)
                    {
                        GameObject go = item.gameObject;
                        if (go != null)
                        {
                            CustomDescription2 component = go.GetComponent<CustomDescription2>();
                            if (component == null)
                            {
                                component = go.AddComponent<CustomDescription2>();
                            }
                        }
                    }
                }
            }
        }
    }

    internal class CustomDescription2 : MonoBehaviour
    {
    }
}

 

the issue here is the use of ".AddComponent<>()"

for some reason, if I go back and forth between the MainMenu and a game save, after 2-5 iterations the game crashes spamming the following error:

 

Quote

ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.'

 

if someone has any idea please let me know

 

full logs and example plugins are available if anyone cares to give this a look, just let me know

Link to comment
Share on other sites

  • 2 weeks later...
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...