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] NullReferenceException encountered during downloads #2986

Closed
Blu3wolf opened this issue Feb 5, 2020 · 12 comments · Fixed by #2987
Closed

[Bug] NullReferenceException encountered during downloads #2986

Blu3wolf opened this issue Feb 5, 2020 · 12 comments · Fixed by #2987
Labels
Bug Something is not working as intended ConsoleUI Issues affecting the interactive console UI

Comments

@Blu3wolf
Copy link

Blu3wolf commented Feb 5, 2020

Background

  • Operating System: Manjaro
  • CKAN Version: 1.26.10
  • KSP Version: 1.7.3

Have you made any manual changes to your GameData folder (i.e., not via CKAN)?
Yup, the ones described in the RO/RP-1 install guide: https://github.com/KSP-RO/RP-0/wiki/RO-&-RP-1-Installation-for-1.7.3

Problem

Describe the bug
Using the console UI for CKAN, while downloading some mods the console spat an unhandled exception at me. I suspect I also had a few others earlier as the graphic UI was showing me a white screen with red cross on the first run after building it.

Steps to reproduce
I ran 'ckan consoleui' and selected a series of mods to download. Ctrl + F followed by a string, arrow keys to select the mod in question, + key to select for install, Esc key to cancel search and Ctrl + F to return to search, repeated a few times - I think 5 or 6 mods selected.

Expected behavior
I expected the download to complete, but instead encountered an NRE.

Screenshots (if applicable)

CKAN error code (if applicable):

Downloading "https://github.com/shadowmage45/TexturesUnlimited/releases/download/1.5.8.23/TexturesUnlimited-1.5.8.23.zip"                                                            ^ │
 │ Downloading "https://github.com/raidernick/BDAnimationModules/releases/download/v0.6.5.7/BDanim_v0.6.5.7.zip"                                                                        ▒ │
 │ Downloading "https://github.com/blowfishpro/B9PartSwitch/releases/download/v2.11.1/B9PartSwitch_v2.11.1.zip"                                                                         ▒ │
 │ Downloading "https://github.com/linuxgurugamer/PatchManager/releases/download/0.0.16.4/PatchManager-0.0.16.4.zip"                                                                    ▒ │
 │ Failed to download "https://github.com/KSP-RO/ROCapsules/releases/download/v1.0.0.0/ROCapsules-v1.0.0.0.zip", trying fallback                                                        ▒ │
Unhandled Exception:org/download/ROCapsules-v1.0.0.0/E962516B-ROCapsules-v1.0.0.0.zip"                                                                                                  ▒ │
System.NullReferenceException: Object reference not set to an instance of an objectownload/1.5.8.23/TexturesUnlimited-1.5.8.23.zip", trying fallback                                    ▒ │
  at CKAN.ConsoleUI.Toolkit.ConsoleTextBox.Draw (System.Boolean focused) [0x000eb] in <b28b520a445343588cb592db267d120a>:0                                                              ▒ │
  at CKAN.ConsoleUI.Toolkit.ScreenContainer.Draw () [0x0002d] in <b28b520a445343588cb592db267d120a>:0 Manager-0.0.16.4.zip", trying fallback                                            ▒ │
  at CKAN.ConsoleUI.Toolkit.ConsoleScreen.RaiseMessage (System.String message, System.Object[] args) [0x00008] in <b28b520a445343588cb592db267d120a>:0                                  ▒ │
  at CKAN.NetAsyncDownloader.FileDownloadComplete (System.Int32 index, System.Exception error) [0x000d9] in <b28b520a445343588cb592db267d120a>:0                                        ▒ │
  at CKAN.NetAsyncDownloader+<>c__DisplayClass14_0.<DownloadModule>b__1 (System.Object sender, System.ComponentModel.AsyncCompletedEventArgs args) [0x00012] in <b28b520a445343588cb592db267d120a>:0  to download "https://github.com/KSP-RO/ROCapsules/releases/download/v1.0.0.0/ROCapsules-v1.0.0.0.zip", trying fallback                                                        * │
  at CKAN.NetAsyncDownloader+NetAsyncDownloaderDownloadPart.<ResetAgent>b__21_1 (System.Object sender, System.ComponentModel.AsyncCompletedEventArgs args) [0x00008] in <b28b520a445343588cb592"https://archive.org/download/ROCapsules-v1.0.0.0/E962516B-ROCapsules-v1.0.0.0.zip"                                                                                                    │
  aFailed to download "https://github.com/shadowmage45/TexturesUnlimited/releases/download/1.5.8.23/TexturesUnlimited-1.5.8.23.zip", trying fallback                                    ──┘
  a"https://archive.org/download/TexturesUnlimited-1.5.8.23/B6A71E99-TexturesUnlimited-1.5.8.23.zip"                                                                                       
  aFailed to download "https://github.com/linuxgurugamer/PatchManager/releases/download/0.0.16.4/PatchManager-0.0.16.4.zip", trying fallback                                                
  a"https://archive.org/download/PatchManager-0.0.16.4/CC4C384F-PatchManager-0.0.16.4.zip"                                                                                              reserve[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object                                                                   
  at CKAN.ConsoleUI.Toolkit.ConsoleTextBox.Draw (System.Boolean focused) [0x000eb] in <b28b520a445343588cb592db267d120a>:0 lback callback, System.Object state, System.Boolean preserveSyncC  at CKAN.ConsoleUI.Toolkit.ScreenContainer.Draw () [0x0002d] in <b28b520a445343588cb592db267d120a>:0                                                                                       
  at CKAN.ConsoleUI.Toolkit.ConsoleScreen.RaiseMessage (System.String message, System.Object[] args) [0x00008] in <b28b520a445343588cb592db267d120a>:0 :0                                   
  at CKAN.NetAsyncDownloader.FileDownloadComplete (System.Int32 index, System.Exception error) [0x000d9] in <b28b520a445343588cb592db267d120a>:0                                            
  at CKAN.NetAsyncDownloader+<>c__DisplayClass14_0.<DownloadModule>b__1 (System.Object sender, System.ComponentModel.AsyncCompletedEventArgs args) [0x00012] in <b28b520a445343588cb592db267d120a>:0                                                                                                                                                                                    
  at CKAN.NetAsyncDownloader+NetAsyncDownloaderDownloadPart.<ResetAgent>b__21_1 (System.Object sender, System.ComponentModel.AsyncCompletedEventArgs args) [0x00008] in <b28b520a445343588cb592db267d120a>:0                                                                                                                                                                            
  at System.Net.WebClient.OnDownloadFileCompleted (System.ComponentModel.AsyncCompletedEventArgs e) [0x0000a] in <9bd67acb7e9448b0ae17ea9ad68db84f>:0                                       
  at System.Net.WebClient.<StartAsyncOperation>b__78_4 (System.Object arg) [0x00000] in <9bd67acb7e9448b0ae17ea9ad68db84f>:0                                                                
  at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x00007] in <c4bddbfe864a4b8191bb818d6b204e9d>:0                                                
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <c4bddbfe864a4b8191bb818d6b204e9d>:0                                                                                                                               
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <c4bddbfe864a4b8191bb818d6b204e9d>:0                                                                                                                                       
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00021] in <c4bddbfe864a4b8191bb818d6b204e9d>:0                                   
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in <c4bddbfe864a4b8191bb818d6b204e9d>:0                                                                                     
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <c4bddbfe864a4b8191bb818d6b204e9d>:0    
@HebaruSan HebaruSan added Bug Something is not working as intended ConsoleUI Issues affecting the interactive console UI labels Feb 5, 2020
@HebaruSan
Copy link
Member

Looks like a ConsoleUI version of #2890, I see multiple download failures being reported in that screenshot.

@HebaruSan
Copy link
Member

Only found one object reference in ConsoleTextBox.Draw that isn't guaranteed to be non-null, lines[index] here:

Console.Write(lines[index].PadRight(w));

If you put a null into the lines list, then that PadRight call would throw. lines is only updated here:

lines.AddRange(Formatting.WordWrap(line, GetRight() - GetLeft() + 1));

... so maybe Formatting.WordWrap can return null?

@HebaruSan
Copy link
Member

... nope, Formatting.WordWrap only adds string objects to its return list, never null:

public static List<string> WordWrap(string msg, int w)
{
List<string> messageLines = new List<string>();
if (!string.IsNullOrEmpty(msg)) {
// The string is allowed to contain line breaks.
string[] hardLines = msg.Split(new string[] {"\r\n", "\n"}, StringSplitOptions.None);
foreach (string line in hardLines) {
if (string.IsNullOrEmpty(line)) {
messageLines.Add("");
} else if (line.Length <= w) {
messageLines.Add(line);
} else {
int used = 0;
while (used < line.Length) {
while (used < line.Length && line[used] == ' ') {
// Skip spaces so lines start with non-spaces
++used;
}
if (used >= line.Length) {
// Ran off the end of the string with spaces, we're done
messageLines.Add("");
break;
}
int lineLen;
if (used + w >= line.Length) {
// We're at the end of the line, use the whole thing
lineLen = line.Length - used;
} else {
// Middle of the line, find a word wrappable chunk
for (lineLen = w; lineLen >= 0 && line[used + lineLen] != ' '; --lineLen) { }
}
if (lineLen < 1) {
// Word too long, truncate it
lineLen = w;
}
messageLines.Add(line.Substring(used, lineLen));
used += lineLen;
}
}
}
}
return messageLines;
}

@HebaruSan
Copy link
Member

Maybe AddRange is doing what it did in #2984, temporarily padding the list with nulls. That shouldn't affect us here since we wait for AddRange to finish before we call Draw, except that there is also some threading involved with each error being reported on its own thread.

@HebaruSan
Copy link
Member

@Blu3wolf if I provide you a test build, would you be confident in whether it was working, or was this more of a rare glitch type of thing?

@Blu3wolf
Copy link
Author

Blu3wolf commented Feb 6, 2020

I could give it a shot? As it's closed with a merged PR, do you still want me to try a test build?

@HebaruSan
Copy link
Member

HebaruSan commented Feb 6, 2020

Sure, if you're up for it, more testing is always good:

  • (link removed, see below)

Thanks much!

@Blu3wolf
Copy link
Author

Blu3wolf commented Feb 6, 2020

so, silly question - what do I do with that? The CKAN Ive got at the moment was installed through the AUR, and its a binary with no file extension. Was built with MSBUILD.

Can I run that exe with mono?

@HebaruSan
Copy link
Member

HebaruSan commented Feb 6, 2020

Yup, mono ckan.exe should run the GUI, or mono ckan.exe consoleui for ConsoleUI.

@Blu3wolf
Copy link
Author

Blu3wolf commented Feb 6, 2020

Well, I got another cool exception but I think this may be a separate bug. When I tried to Audit Recommendations from the F10 menu, I got this one:

Unhandled Exception:rce Pack                       1.3.0.0     1.8.9        │ Scan KSP dir                 │ 
System.ArgumentException: An item with the same key has already been added. Key: NearFutureConstruction 1.1.4
  at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x0015a] in <c4bddbfe864a4b8191bb818d6b204e9d>:0 ──────────────────┤ 
  at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <c4bddbfe864a4b8191bb818d6b204e9d>:0                        4.0.3       1.8.90       │ Authentication tokens...     │ 
  at CKAN.ConsoleUI.DependencyScreen.generateList (System.Collections.Generic.HashSet`1[T] inst) [0x001f4] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0              v13.1.0     1.8.99       │ Help               F1, Alt+H │ 
  at CKAN.ConsoleUI.DependencyScreen..ctor (CKAN.KSPManager mgr, CKAN.ConsoleUI.ChangePlan cp, System.Collections.Generic.HashSet`1[T] rej, System.Boolean dbg) [0x000ee] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 trl+Q │ 
  at CKAN.ConsoleUI.ModListScreen.ViewSuggestions () [0x0008d] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 ────┘ 
  at CKAN.ConsoleUI.Toolkit.ConsolePopupMenu.Run (System.Int32 right, System.Int32 top) [0x00162] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0                       1.5.8.23    1.7.9                                       ▒
  at CKAN.ConsoleUI.Toolkit.ConsoleScreen.<.ctor>b__0_1 (System.Object sender) [0x00023] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 ocedural Wings - Fork          0.91                                                    ▒
  at CKAN.ConsoleUI.Toolkit.ScreenContainer.Interact () [0x0003e] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0  ▒
  at CKAN.ConsoleUI.Toolkit.ScreenContainer.Run (System.Action process) [0x0002b] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0  Configurator                         1.27.1      1.99.99                                     ▒
  at CKAN.ConsoleUI.ConsoleCKAN..ctor (CKAN.KSPManager mgr, System.Boolean debug) [0x0005b] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 tinued                      v7.7.3.1    1.8.99                                      ▒
  at CKAN.ConsoleUI.ConsoleUI.Main_ (System.String[] args, CKAN.KSPManager manager, System.Boolean debug) [0x00007] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0     v0.21                                                   ▒
  at CKAN.CmdLine.MainClass.ConsoleUi (CKAN.KSPManager manager, CKAN.CmdLine.CommonOptions opts, System.String[] args) [0x00019] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0    1.8.9                                       ▒
  at CKAN.CmdLine.MainClass.RunSimpleAction (CKAN.CmdLine.Options cmdline, CKAN.CmdLine.CommonOptions options, System.String[] args, CKAN.IUser user, CKAN.KSPManager manager) [0x002ff] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 rbalism - RealismOverhaul Config            v0.2        1.8.9                                       v
  at CKAN.CmdLine.MainClass.Execute (CKAN.KSPManager manager, CKAN.CmdLine.CommonOptions opts, System.String[] args) [0x0028b] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0                                                   
  at CKAN.CmdLine.MainClass.Main (System.String[] args) [0x000a1] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: An item with the same key has already been added. Key: NearFutureConstruction 1.1.4
  at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x0015a] in <c4bddbfe864a4b8191bb818d6b204e9d>:0 
  at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <c4bddbfe864a4b8191bb818d6b204e9d>:0 
  at CKAN.ConsoleUI.DependencyScreen.generateList (System.Collections.Generic.HashSet`1[T] inst) [0x001f4] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 
  at CKAN.ConsoleUI.DependencyScreen..ctor (CKAN.KSPManager mgr, CKAN.ConsoleUI.ChangePlan cp, System.Collections.Generic.HashSet`1[T] rej, System.Boolean dbg) [0x000ee] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 
  at CKAN.ConsoleUI.ModListScreen.ViewSuggestions () [0x0008d] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 
  at CKAN.ConsoleUI.Toolkit.ConsolePopupMenu.Run (System.Int32 right, System.Int32 top) [0x00162] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 
  at CKAN.ConsoleUI.Toolkit.ConsoleScreen.<.ctor>b__0_1 (System.Object sender) [0x00023] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 
  at CKAN.ConsoleUI.Toolkit.ScreenContainer.Interact () [0x0003e] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 
  at CKAN.ConsoleUI.Toolkit.ScreenContainer.Run (System.Action process) [0x0002b] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 
  at CKAN.ConsoleUI.ConsoleCKAN..ctor (CKAN.KSPManager mgr, System.Boolean debug) [0x0005b] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 
  at CKAN.ConsoleUI.ConsoleUI.Main_ (System.String[] args, CKAN.KSPManager manager, System.Boolean debug) [0x00007] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 
  at CKAN.CmdLine.MainClass.ConsoleUi (CKAN.KSPManager manager, CKAN.CmdLine.CommonOptions opts, System.String[] args) [0x00019] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 
  at CKAN.CmdLine.MainClass.RunSimpleAction (CKAN.CmdLine.Options cmdline, CKAN.CmdLine.CommonOptions options, System.String[] args, CKAN.IUser user, CKAN.KSPManager manager) [0x002ff] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 
  at CKAN.CmdLine.MainClass.Execute (CKAN.KSPManager manager, CKAN.CmdLine.CommonOptions opts, System.String[] args) [0x0028b] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 
  at CKAN.CmdLine.MainClass.Main (System.String[] args) [0x000a1] in <ce28b1fd8caa4b339aed683ae3b21ffc>:0 

@HebaruSan
Copy link
Member

Yup, that's different, but also worth fixing. Submitted #2990. Thanks!

@HebaruSan
Copy link
Member

@Blu3wolf thanks, here's a new test build that should have that fixed:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended ConsoleUI Issues affecting the interactive console UI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants