SilenceXX

Member
I have a bit problem with implemnting PvM PvP system.
It compiles normaly, but after shard restart it gives out deserialize exception in playermobile.
Deserialize part:
Code:
                case 32:

                    {
                        m_NONPK = (NONPK)reader.ReadInt();
                        goto case 31;
                    }
Serialize part:
Code:
writer.Write((int)m_NONPK);
Other stuff in playermobile related:
Code:
    public enum NONPK
        {
            Null,
            NONPK,
            NONPKinEvent,
            PK
        }
and
Code:
        private NONPK m_NONPK;
+ Exception it did throw:
Code:
Error:
System.Exception: Load failed (items=False, mobiles=True, guilds=False, data=False, type=Server.Mobiles.PlayerMobile, serial=0x00000001) ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Server.Mobiles.PlayerMobile.Deserialize(GenericReader reader)
   at Server.World.Load() in c:\ServUO2\Server\World.cs:line 595
   --- End of inner exception stack trace ---
   at Server.World.Load() in c:\ServUO2\Server\World.cs:line 328
   at Server.Core.Main(String[] args) in c:\ServUO2\Server\Main.cs:line 539
This exception is fatal, press return to exit
 
[file]PlayerMobile.cs|none[/file]Visual studio debug:
Code:
System.NullReferenceException was unhandled by user code
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=Scripts.CS
  StackTrace:
       at Server.Mobiles.PlayerMobile.Deserialize(GenericReader reader) in c:\ServUO\Scripts\Mobiles\PlayerMobile.cs:line 3863
       at Server.World.Load() in C:\ServUO\Server\World.cs:line 595
  InnerException:
Witch did point to:
Code:
            var list = Stabled;

            for (int i = 0; i < list.Count; ++i)
            {
                BaseCreature bc = list[i] as BaseCreature;

                if (bc != null)
                {
                    bc.IsStabled = true;
                    bc.StabledBy = this;
                }
            }

Also adding full playermobile.cs maybe im missing out something:
 
Last edited:
You serialize wrong :

Code:
  writer.Write(32); // version
   
  writer.Write(NextFletcherBulkOrder);
  writer.Write(NextCarpenterBulkOrder);
  writer.Write((int)m_NONPK);


should be

Code:
  writer.Write(32); // version
   
  writer.Write((int)m_NONPK);
  writer.Write(NextFletcherBulkOrder);
  writer.Write(NextCarpenterBulkOrder);

because you deserialize this way :

Code:
case 32:
{
	m_NONPK = (NONPK)reader.ReadInt();
        goto case 31;
}
  case 31:
  {
  NextFletcherBulkOrder = reader.ReadTimeSpan();
  goto case 30;
  }
  case 30:
  {
  NextCarpenterBulkOrder = reader.ReadTimeSpan();
  goto case 29;
  }


and not

Code:
case 32:
{
        goto case 31;
}
  case 31:
  {
  NextFletcherBulkOrder = reader.ReadTimeSpan();
  goto case 30;
  }
  case 30:
  {
  NextCarpenterBulkOrder = reader.ReadTimeSpan();
  m_NONPK = (NONPK)reader.ReadInt();
  goto case 29;
  }

on serialisation\deserialisation always keep in mind : What goes first in has to be first taken out.

If you already have this live there is a way to fix :

Serialize :

Code:
  writer.Write(33); // version to override the issue on 32
   
  writer.Write((int)m_NONPK); //Version 33
  writer.Write(NextFletcherBulkOrder);
  writer.Write(NextCarpenterBulkOrder);

Deserialize

Code:
case 33:
{
	m_NONPK = (NONPK)reader.ReadInt(); ///Take out on new stream
        goto case 31;
}
  case 32:
  case 31:
  {
  NextFletcherBulkOrder = reader.ReadTimeSpan();
  goto case 30;
  }
  case 30:
  {
  NextCarpenterBulkOrder = reader.ReadTimeSpan();
  if(version.Equals(32))
        m_NONPK = (NONPK)reader.ReadInt(); //Take out from old stream
  goto case 29;
  }
 
That is not a case here... Because geting same results with serialize and deserialize. In same spot. Moved that part myself after errror. was thinking about rechecking that part.
You serialize wrong :

Code:
  writer.Write(32); // version
   
  writer.Write(NextFletcherBulkOrder);
  writer.Write(NextCarpenterBulkOrder);
  writer.Write((int)m_NONPK);


should be

Code:
  writer.Write(32); // version
   
  writer.Write((int)m_NONPK);
  writer.Write(NextFletcherBulkOrder);
  writer.Write(NextCarpenterBulkOrder);

because you deserialize this way :

Code:
case 32:
{
	m_NONPK = (NONPK)reader.ReadInt();
        goto case 31;
}
  case 31:
  {
  NextFletcherBulkOrder = reader.ReadTimeSpan();
  goto case 30;
  }
  case 30:
  {
  NextCarpenterBulkOrder = reader.ReadTimeSpan();
  goto case 29;
  }


and not

Code:
case 32:
{
        goto case 31;
}
  case 31:
  {
  NextFletcherBulkOrder = reader.ReadTimeSpan();
  goto case 30;
  }
  case 30:
  {
  NextCarpenterBulkOrder = reader.ReadTimeSpan();
  m_NONPK = (NONPK)reader.ReadInt();
  goto case 29;
  }
 
I only checked that part for the new property not the whole file.
You serialize there int + double (date) + double(date) and deserialize double + double + int.
Other changes i not checked.
 
Did anyways recheck. Still same error at same line...
I mean after restoring back order...

Reuploading file with edits, so old one doesnt mess with mind.
 

Attachments

  • PlayerMobile.cs
    139.5 KB · Views: 7
Last edited:
You are casting the reader for some reason:

m_NONPK = (NONPK)reader.ReadInt();

You should just do:

m_NONPK = reader.ReadInt();
 
In servuo compile:
Code:
Errors:
+ Mobiles/PlayerMobile.cs:
    CS0266: Line 3488: Cannot implicitly convert type 'int' to 'Server.Mobiles.NONPK'. An explicit conversion exists (are you missing a cast?)
Same on Visual studio.

You are casting the reader for some reason:

m_NONPK = (NONPK)reader.ReadInt();

You should just do:

m_NONPK = reader.ReadInt();
 
try it as:

m_NONPK = reader.ReadInt(int(NONPK));

What are you doing?

enum = (enum)reader.readint(); may correct if its assignable.


Code:
public enum mycustomenum : byte
{
    FirstEntry = 0,
    SecondEntry = 1,
    Thirdentry = 2
}

Serialize :

Code:
......
writer.Write((byte)myenum);
......

Deserialize :

Code:
......
myenum = (mycustomenum )reader.readbyte();
......

Thats the correct way....


PS : his issue has to bee somewhere else.. I also not know if null is correct on an enum..
 
Will try to roll out if thats my nonpk with is causing errors.

Edited that out, and still for some reson that stabled list...
 
Last edited:
Case closed... For some reason all that error was being thrown out because of HS Ships i did add... Wird that it did work previously with no errors. But removing it did solve all serialize cases.
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back