UnderminersTeam / UndertaleModTool

The most complete tool for modding, decompiling and unpacking Undertale (and other GameMaker games!)
GNU General Public License v3.0
1.11k stars 213 forks source link

Serializing functions crashes in YYC games #478

Open Archie-osu opened 3 years ago

Archie-osu commented 3 years ago

Crashes on the newest build of the "master" branch. The game is empty, made with GMS 2.3 + YYC.

The actual exception occurs in WriteUndertaleObject, where the code checks for the type, not expecting that obj might be null.

Screenshot: https://imgur.com/a/rfYD1l9

BenjaminUrquhart commented 3 years ago

Can you provide a stack trace? I believe this is intended behavior as there’s no real way to write a null object.

Archie-osu commented 3 years ago
System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=UndertaleModLib
  StackTrace:
   at UndertaleModLib.UndertaleWriter.WriteUndertaleObject[T](T obj) in C:\Users\Archie\Documents\GitHub\UndertaleModTool\UndertaleModLib\UndertaleIO.cs:line 491
UndertaleModLib.dll!UndertaleModLib.UndertaleWriter.WriteUndertaleObject<UndertaleModLib.Models.UndertaleInstruction.Reference<UndertaleModLib.Models.UndertaleFunction>>(UndertaleModLib.Models.UndertaleInstruction.Reference<UndertaleModLib.Models.UndertaleFunction> obj = null) | UndertaleIO.cs Line 491

UndertaleModLib.dll!UndertaleModLib.Models.UndertaleInstruction.Serialize(UndertaleModLib.UndertaleWriter writer = {UndertaleModLib.UndertaleWriter}) | UndertaleCode.cs Line 498

UndertaleModTool.dll!UndertaleModTool.MainWindow.CreateGMLBytecode(string sCode = "room_goto(20)", bool UseAUMI = true) | ScriptingFunctions.cs Line 78

UndertaleModTool.dll!UndertaleModTool.MainWindow.RunScriptNow(string path = "C:\\Users\\Archie\\Desktop\\gmlexec.csx") | MainWindow.xaml.cs Line 1074
BenjaminUrquhart commented 3 years ago

Are there line numbers?

Archie-osu commented 3 years ago

Updated with line numbers.

BenjaminUrquhart commented 3 years ago

Looking at the relevant code, it seems that Function is null. Did you forget to set it perhaps? https://github.com/krzys-h/UndertaleModTool/blob/master/UndertaleModLib/Models/UndertaleCode.cs#L498

Archie-osu commented 3 years ago

I am looping over CompileContext.ResultAssembly after compiling GML. For each entry in that list, I call entry.Serialize - the same instructions and code are valid in non-YYC environments.