RockyTV

PopupDialog is still throwing NRE on KSP_win32

4 posts in this topic

Posted (edited)

When you have an addon that uses the PopupDialog.SpawnDialog method and this addon is set to startup instantly, it will throw a NRE on the first call to PopupDialog.SpawnDialog.
An example:

The following code

PopupDialog.SpawnPopupDialog(
                Vector2.zero, Vector2.zero, "A simple dialog", "this is a title", "this should be the message", 
                "this should be a button", true, HighLogic.UISkin, true);

has this output:

mOIu.png

 

As you can see, there are no buttons present there, nor the message text.

This is the log file and this is the code for my sample addon:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using UnityEngine;
using KSP;

namespace NRETesterKSP
{
    [KSPAddon(KSPAddon.Startup.Instantly, true)]
    public class NRETesterKSP : MonoBehaviour
    {
        public void Awake()
        {
            PopupDialog.SpawnPopupDialog(
                Vector2.zero, Vector2.zero, "A simple dialog", "this is a title", "this should be the message", 
                "this should be a button", true, HighLogic.UISkin, true);
        }
    }
}

 

This only happens in x86 versions; if I switch to x64 it works just fine.

EDIT: just used the same code in KSP_x64 and this is the expected result:

9Jtp.png

EDIT2: if the addon is set to start on MainMenu, the dialog pops up correctly, without errors.

Edited by RockyTV

Share this post


Link to post
Share on other sites

Have you raised this on the bugtracker?

 

Share this post


Link to post
Share on other sites

Hmm, I think that method now takes one more parameter (in all its variants), so make sure you are using the correct one. I've been using PopupDialog a lot in my mod and saw no issues (after adding that parameter and recompiling).

Share this post


Link to post
Share on other sites

A bit of a late reply but @garwel is right, the pop-up dialog needs some additional parameters:

  • isModal
  • titleExtra

Another thing is that the pop-up dialog will require a new parameter under KSP 1.3.0. @RockyTV has included it in the test code as "A simple dialog" text string:

  • dialogName

Something to note: since this dialog window is used widely by the Compatibility Checker, it will fail to operate (so no warning messsages about incompatibilities).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now