RockyTV

PopupDialog is still throwing NRE on KSP_win32

11 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

Modders notes will cover these changes.. and they should be coming soon TM

2 people like this

Share this post


Link to post
Share on other sites
On 15/04/2017 at 6:51 AM, JPLRepo said:

Have you raised this on the bugtracker?

 

http://bugs.kerbalspaceprogram.com/issues/14819

On 26/04/2017 at 6:57 AM, Phineas Freak said:

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).

I know, but both versions still throw (1.2.2 and 1.2.9).

Share this post


Link to post
Share on other sites

@RockyTV I tested this a bit and if I use Start() instead of Awake() it will display the dialog correctly.

It is being called later than Awake() but it works.
 

1 person likes this

Share this post


Link to post
Share on other sites

If the problem only shows up when run immediately then it's probably just that some required assets haven't been loaded yet.

Share this post


Link to post
Share on other sites
6 hours ago, Olympic1 said:

@RockyTV I tested this a bit and if I use Start() instead of Awake() it will display the dialog correctly.

It is being called later than Awake() but it works.
 

 

1 hour ago, DMagic said:

If the problem only shows up when run immediately then it's probably just that some required assets haven't been loaded yet.

The problem is that it will only throw a NRE when using KSP x86. It doesn't happen in x64.

Share this post


Link to post
Share on other sites

But does it only happen when run immediately on x86? If you wait until Start, or the Main Menu does it work? If so then there is probably just some slight difference in the time it takes to load in some necessary asset (maybe the TMP Font Asset, I think that's one of the first things that gets loaded).

Share this post


Link to post
Share on other sites
6 minutes ago, DMagic said:

But does it only happen when run immediately on x86? If you wait until Start, or the Main Menu does it work? If so then there is probably just some slight difference in the time it takes to load in some necessary asset (maybe the TMP Font Asset, I think that's one of the first things that gets loaded).

Yeah, it only happens when I use Awake instead of Start. If I move my addon to start in the main menu, it works.

Share this post


Link to post
Share on other sites