matigramirez / Parsec

Serialization library for Shaiya file formats
MIT License
31 stars 23 forks source link

svmap: System.NullReferenceException #31

Closed ghost closed 2 years ago

ghost commented 2 years ago

Describe the bug System.NullReferenceException thrown when trying to build an svmap file from JSON.

To Reproduce

  1. Set a debug breakpoint at line 50 in Reader.cs and step into the code
  2. Keep stepping until it passes through the empty FileBase constructor
  3. Once it reaches the Monster constructor it will throw the exception
System.NullReferenceException: 'Object reference not set to an instance of an object.'

binaryReader was null.
System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Parsec
  StackTrace:
   at Parsec.Shaiya.Svmap.Monster..ctor(SBinaryReader binaryReader) in C:\Users\kurtekat\source\repos\Parsec\src\Parsec\Shaiya\Svmap\Monster.cs:line 15

Desktop

Additional context

using Parsec.Readers;
using Parsec.Shaiya.Svmap;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var svmap = Reader.ReadFromJson<Svmap>("0.json");
            svmap.Write("0.svmap");
        }
    }
}
matigramirez commented 2 years ago

Good catch. This issue was caused by all of the svmap subclasses not having parameterless constructors for json to use. They instead were being created with the ctor that attempts to use SBinaryReader which was null. Issue was fixed on eeb838072171efedb8f9deb3fab4955eaa37d3d3.

ghost commented 2 years ago

glad i was able to help. thanks for fixing it.