GitHub-TC / EmpyrionScripting

Displays various informations directly and live on LCD screens and will support conveyor and construction control
GNU General Public License v3.0
34 stars 5 forks source link

NRE When accessing Structure.DockedE in SP when changing playfields. #10

Closed AmandaCameron closed 2 years ago

AmandaCameron commented 2 years ago

Describe the bug When accessing a the E.S.DockedE array either in C# or in Handlebars, you get "Exception was thrown by the target invocation" -- I managed to reproduce the error using a C# script, and it produces the stack trace shown below.

To Reproduce Steps to reproduce the behavior:

  1. Create a script (hbs or C#) that access E.S.DockedE
  2. Leave the playfield
  3. Return
  4. Dock back to that BA (not sure if it also happens for CV)
  5. The relevent LCDs now only display "Exception was thrown by the target invocation" and in the case of a C# script, the following stack trace is in the logs:

18-14:50:11.297 10_50 -ERR- {EmpyrionScripting} C# Run [3213/C#:AutoRefill]:System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
  at EmpyrionScripting.DataWrapper.StructureData+<>c__DisplayClass1_0.<.ctor>b__15 (System.Collections.Generic.KeyValuePair`2[TKey,TValue] E) [0x00026] in <4c38c010eeef4b64ab2ca8ed0bd099d5>:0 
  at System.Linq.Enumerable.TryGetFirst[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate, System.Boolean& found) [0x0003f] in <351e49e2a5bf4fd6beabb458ce2255f3>:0 
  at System.Linq.Enumerable.FirstOrDefault[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x00000] in <351e49e2a5bf4fd6beabb458ce2255f3>:0 
  at EmpyrionScripting.DataWrapper.StructureData.<.ctor>b__1_12 (Eleon.Modding.IStructure S) [0x0001d] in <4c38c010eeef4b64ab2ca8ed0bd099d5>:0 
  at (wrapper delegate-invoke) System.Func`2[Eleon.Modding.IStructure,System.Collections.Generic.KeyValuePair`2[System.Int32,Eleon.Modding.IEntity]].invoke_TResult_T(Eleon.Modding.IStructure)
  at System.Linq.Enumerable+SelectListIterator`2[TSource,TResult].MoveNext () [0x00048] in <351e49e2a5bf4fd6beabb458ce2255f3>:0 
  at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[TSource,TResult].ToArray () [0x0003e] in <351e49e2a5bf4fd6beabb458ce2255f3>:0 
  at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0001f] in <351e49e2a5bf4fd6beabb458ce2255f3>:0 
  at EmpyrionScripting.DataWrapper.StructureData.<.ctor>b__1_2 () [0x00051] in <4c38c010eeef4b64ab2ca8ed0bd099d5>:0 
  at System.Lazy`1[T].CreateValue () [0x00081] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Lazy`1[T].LazyInitValue () [0x00080] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Lazy`1[T].get_Value () [0x0003a] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at EmpyrionScripting.DataWrapper.StructureData.get_DockedE () [0x00000] in <4c38c010eeef4b64ab2ca8ed0bd099d5>:0 
  at Submission#0+ModMain.Main (EmpyrionScripting.Interface.IScriptModData r) [0x00097] in <8e7e2fe907224f95a53251ecab0c12a9>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <695d1cc93cca45069c528c15c9fdd749>:0 

Expected behavior That DockedE would work regardless if the player leaves and comes back to the playfield.

Additional context Add any other context about the problem here.

AmandaCameron commented 2 years ago

Going to hijack my own issue with some additional observations I've made while playing with the C# script support:

  1. EntityData.EntityType isn't accessible in non-save scripts for some reason I don't understand (Rather, checking the entity is, comparing with constants from the Enum isn't)
  2. Neither is ForEach (Is it selecting the wrong overload?)
  3. There's no pretty way to check if an item id is inside a Id list, (Is PlainIds meant to be this? Right now it's just containing the raw strings (CobaltOre etc))
  4. It'd be helpful if there was some output somewhere for what caused the privledge level to change, both in debugging 1 and 2 and in general. (Is there already a tool for this that I just don't know about?)

I'll comment with any more I think of, if that's agreeable

GitHub-TC commented 2 years ago

In SP there is amajor bug in Empyrion with the vessel with you yous to leave the playfield. These vessel is no longer correct in the emities list. The bug is reported to Eleon but i don't know when they will fix it.