RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Imbuing Target Crash

espcevan

Sorceror
I found a bug that crashes my server.

When
  • Someone first imbues something
  • Reopens the main Imbue page
  • Clicks "Imbue Last Property"
  • and then click themselves
The Server Crashes.

Server Crash Report
===================

RunUO Version 2.2, Build 4782.3756
Operating System: Microsoft Windows NT 6.1.7601 Service Pack 1
.NET Framework: 2.0.50727.5477
Time: 5/26/2014 9:24:18 PM
Mobiles: 38867
Items: 204363
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Server.SkillHandlers.ImbuingGump.InternalTargetD.OnTarget(Mobile from, Object o)
at Server.Targeting.Target.Invoke(Mobile from, Object targeted)
at Server.Network.PacketHandlers.TargetResponse(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)


Here is the unedited code from Imbuing.cs where the Imbue Last Prop target gets called on

Code:
        // ===== Imbue Target with Last Prop ====================
        public static void ImbueLastProp(Mobile from, int Mod, int Mint)
        {
            from.Target = new InternalTargetD();
            return;
        }
 
        // ===== Targetting ===== Imbue Last Mod =====
        private class InternalTargetD : Target
        {
            public InternalTargetD() : base(2, false, TargetFlags.None)
            {
                AllowNonlocal = true;
            }
            protected override void OnTarget(Mobile from, object o)
            {
                PlayerMobile pm = from as PlayerMobile;
                int Imod = pm.Imbue_Mod;
                int ImodInt = pm.Imbue_ModInt;
 
                Item it = o as Item;
 
                // = Item has been Imbued 20 or more times
                if (o is BaseWeapon) { BaseWeapon Ti = o as BaseWeapon; if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
                if (o is BaseArmor)  { BaseArmor Ti = o as BaseArmor;   if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
                if (o is BaseJewel)  { BaseJewel Ti = o as BaseJewel;   if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
                if (o is BaseHat)    { BaseHat Ti = o as BaseHat;       if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
                
                if (it.LootType == LootType.Blessed)
                {
                    from.SendLocalizedMessage(1080438); // You cannot imbue a blessed item.
                    return;
                }
 
                // = Check Last Mod can be applied to Targeted Item Type
                if (o is BaseMeleeWeapon)
                {
                    if (Imod == 1 || Imod == 2 || Imod == 12 || Imod == 13 || Imod == 16 || Imod == 21 || Imod == 22 || (Imod >= 25 && Imod <= 41) || Imod >= 101)
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseRanged)
                {
                    if (Imod == 1 || Imod == 2 || Imod == 12 || Imod == 13 || Imod == 16 || Imod == 21 || Imod == 22 || Imod == 60 || Imod == 61 || (Imod >= 25 && Imod <= 41) || Imod >= 101)
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseShield)
                {
                    if (Imod == 1 || Imod == 2 || Imod == 19 || Imod == 16 || Imod == 22 || Imod == 24 || Imod == 42)
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseArmor)
                {
                    if (Imod == 3 || Imod == 4 || Imod == 5 || Imod == 9 || Imod == 10 || Imod == 11 || Imod == 21 || Imod == 23 || (Imod >= 17 && Imod <= 19))
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseHat)
                {
                    if (Imod == 3 || Imod == 4 || Imod == 5 || Imod == 9 || Imod == 10 || Imod == 11 || Imod == 21 || Imod == 23 || (Imod >= 17 && Imod <= 19))
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseJewel)
                {
                    if (Imod == 1 || Imod == 2 || Imod == 6 || Imod == 7 || Imod == 8 || Imod == 12 || Imod == 10 || Imod == 11 || Imod == 20 || Imod == 21 || Imod == 23 || Imod == 21 || (Imod >= 14 && Imod <= 18) || (Imod >= 51 && Imod <= 55) || Imod >= 151)
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else
                    from.SendMessage("The selected item cannot be Imbued with the last Property..");
 
                return;
            }
        }
 

daat99

Moderator
Staff member
Can you run your server in "debug mode" (see FAQ forum for more information) and post the debug crash log please?

Based on the scenario you described I would guess that "it" is null ("o" is not an Item so trying to cast it as an Item will result in "null" assignment into the "it" variable).
 

espcevan

Sorceror
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Server.SkillHandlers.ImbuingGump.InternalTargetD.OnTarget(Mobile from, Object o) in e:\UO Stuff\2.3\Scripts\New folder\Imbuing\Imbuing.cs:line 662
at Server.Targeting.Target.Invoke(Mobile from, Object targeted)
at Server.Network.PacketHandlers.TargetResponse(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)

Code:
                if (it.LootType == LootType.Blessed)///Line662
                {
                    from.SendLocalizedMessage(1080438); // You cannot imbue a blessed item.
                    return;
                }

Code:
        // ===== Targetting ===== Imbue Last Mod =====
        private class InternalTargetD : Target
        {
            public InternalTargetD() : base(2, false, TargetFlags.None)
            {
                AllowNonlocal = true;
            }
            protected override void OnTarget(Mobile from, object o)
            {
                PlayerMobile pm = from as PlayerMobile;
                int Imod = pm.Imbue_Mod;
                int ImodInt = pm.Imbue_ModInt;
 
                Item it = o as Item;
 
                // = Item has been Imbued 20 or more times
                if (o is BaseWeapon) { BaseWeapon Ti = o as BaseWeapon; if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
                if (o is BaseArmor)  { BaseArmor Ti = o as BaseArmor;  if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
                if (o is BaseJewel)  { BaseJewel Ti = o as BaseJewel;  if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
                if (o is BaseHat)    { BaseHat Ti = o as BaseHat;      if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
               
                if (it.LootType == LootType.Blessed)///Line662
                {
                    from.SendLocalizedMessage(1080438); // You cannot imbue a blessed item.
                    return;
                }
 
                // = Check Last Mod can be applied to Targeted Item Type
                if (o is BaseMeleeWeapon)
                {
                    if (Imod == 1 || Imod == 2 || Imod == 12 || Imod == 13 || Imod == 16 || Imod == 21 || Imod == 22 || (Imod >= 25 && Imod <= 41) || Imod >= 101)
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseRanged)
                {
                    if (Imod == 1 || Imod == 2 || Imod == 12 || Imod == 13 || Imod == 16 || Imod == 21 || Imod == 22 || Imod == 60 || Imod == 61 || (Imod >= 25 && Imod <= 41) || Imod >= 101)
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseShield)
                {
                    if (Imod == 1 || Imod == 2 || Imod == 19 || Imod == 16 || Imod == 22 || Imod == 24 || Imod == 42)
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseArmor)
                {
                    if (Imod == 3 || Imod == 4 || Imod == 5 || Imod == 9 || Imod == 10 || Imod == 11 || Imod == 21 || Imod == 23 || (Imod >= 17 && Imod <= 19))
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseHat)
                {
                    if (Imod == 3 || Imod == 4 || Imod == 5 || Imod == 9 || Imod == 10 || Imod == 11 || Imod == 21 || Imod == 23 || (Imod >= 17 && Imod <= 19))
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseJewel)
                {
                    if (Imod == 1 || Imod == 2 || Imod == 6 || Imod == 7 || Imod == 8 || Imod == 12 || Imod == 10 || Imod == 11 || Imod == 20 || Imod == 21 || Imod == 23 || Imod == 21 || (Imod >= 14 && Imod <= 18) || (Imod >= 51 && Imod <= 55) || Imod >= 151)
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else
                    from.SendMessage("The selected item cannot be Imbued with the last Property..");
 
                return;
            }
        }
 
I think I would enclose Item it = o as Item; in an if statement to check to see if it is an item before assigning it to a Item variable:

Code:
if (o is Item)
  Item it = o as Item;
else
  return;

That might be a good start. Sadly I do not have a lot of time to look over it further.
 

daat99

Moderator
Staff member
Instead on what Keldon - JoinUO suggested you can check if "it" is null after you are trying to cast o as an item.
This will be preferable because the null check is "cheaper" (CPU/Memory wise) in comparison to the "if o is item" check.

Please keep in mind that his suggestion will solve your issue as well and the CPU/Memory usage won't be noticeable.
 

espcevan

Sorceror
*sighs* I cant seem to get this... I is Rusted. For a temp fix i just disabled that particular target for the time being until i can get this right.
 

espcevan

Sorceror
Yeah i tried that and it gave me some odd error, ill get that in a min. There is also another problem with Imbuing... When more than one person is imbuing stuff they are getting each others imbues for some reason. It takes the resources but puts the imbue on someone else's item.
 

espcevan

Sorceror
Have you tried what Keldon suggested?

Code:
Errors:
+ New folder/Imbuing/Imbuing.cs:
    CS1023: Line 671: Embedded statement cannot be a declaration or labeled statement

Code:
        // ===== Imbue Target with Last Prop ====================
        public static void ImbueLastProp(Mobile from, int Mod, int Mint)
        {
            from.Target = new InternalTargetD();
            return;
        }
 
        // ===== Targetting ===== Imbue Last Mod =====
        private class InternalTargetD : Target
        {
        private Mobile m_Mobile;
            public InternalTargetD() : base(8, false, TargetFlags.None)
            {
                AllowNonlocal = true;
            }
            protected override void OnTarget(Mobile from, object o)
            {
                PlayerMobile pm = from as PlayerMobile;
                int Imod = pm.Imbue_Mod;
                int ImodInt = pm.Imbue_ModInt;
             
                Item it = o as Item;
             
                if (o is Item)
                    Item it = o as Item;
                else
                    return;
 
                // = Item has been Imbued 20 or more times
                if (o is BaseWeapon) { BaseWeapon Ti = o as BaseWeapon; if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
                if (o is BaseArmor)  { BaseArmor Ti = o as BaseArmor;  if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
                if (o is BaseJewel)  { BaseJewel Ti = o as BaseJewel;  if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
                if (o is BaseHat)    { BaseHat Ti = o as BaseHat;      if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
             
                if (it.LootType == LootType.Blessed)
                {
                    from.SendLocalizedMessage(1080438); // You cannot imbue a blessed item.
                    return;
                }
             
                if (o is BaseMeleeWeapon)
                {
                    if (Imod == 1 || Imod == 2 || Imod == 12 || Imod == 13 || Imod == 16 || Imod == 21 || Imod == 22 || (Imod >= 25 && Imod <= 41) || Imod >= 101)
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseRanged)
                {
                    if (Imod == 1 || Imod == 2 || Imod == 12 || Imod == 13 || Imod == 16 || Imod == 21 || Imod == 22 || Imod == 60 || Imod == 61 || (Imod >= 25 && Imod <= 41) || Imod >= 101)
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseShield)
                {
                    if (Imod == 1 || Imod == 2 || Imod == 19 || Imod == 16 || Imod == 22 || Imod == 24 || Imod == 42)
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseArmor)
                {
                    if (Imod == 3 || Imod == 4 || Imod == 5 || Imod == 9 || Imod == 10 || Imod == 11 || Imod == 21 || Imod == 23 || (Imod >= 17 && Imod <= 19))
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseHat)
                {
                    if (Imod == 3 || Imod == 4 || Imod == 5 || Imod == 9 || Imod == 10 || Imod == 11 || Imod == 21 || Imod == 23 || (Imod >= 17 && Imod <= 19))
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else if (o is BaseJewel)
                {
                    if (Imod == 1 || Imod == 2 || Imod == 6 || Imod == 7 || Imod == 8 || Imod == 12 || Imod == 10 || Imod == 11 || Imod == 20 || Imod == 21 || Imod == 23 || Imod == 21 || (Imod >= 14 && Imod <= 18) || (Imod >= 51 && Imod <= 55) || Imod >= 151)
                    {
                        ImbuingGumpC.ImbueItem(from, o, Imod, ImodInt);
                        from.SendGump(new ImbuingGump(from));
                        return;
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
                }
                else
                    from.SendMessage("The selected item cannot be Imbued with the last Property..");
 
                return;
            }
        }

Like i said, I'm pretty rusty at scripting

Also, What does this line do?
Code:
AllowNonlocal = true;
 

espcevan

Sorceror
Fixxed The Crash.

Code:
        // === Imbue Target with Last Prop ===
        public static void ImbueLastProp(Mobile from, int Mod, int Mint)
        {
            from.Target = new InternalTargetD();
 
            return;
        }
 
        private class InternalTargetD : Target
        {
            public InternalTargetD()
                : base(8, false, TargetFlags.None)
            {
                AllowNonlocal = false;
            }
            protected override void OnTarget(Mobile from, object o)
            {
                PlayerMobile pm = from as PlayerMobile;
                int Imod = pm.ImbLast_Mod;
                Item it = o as Item;
               
               
                if ( from.Target is Item )
                {
                    if (o is BaseWeapon) { BaseWeapon Ti = o as BaseWeapon; if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
                    if (o is BaseArmor) { BaseArmor Ti = o as BaseArmor; if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
                    if (o is BaseJewel) { BaseJewel Ti = o as BaseJewel; if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
                    if (o is BaseClothing) { BaseClothing Ti = o as BaseClothing; if (Ti.TimesImbued >= 20) { from.SendMessage("This item has been modified too many times and cannot be imbued any further."); return; } }
 
                    if (it.LootType == LootType.Blessed)
                    {
                        from.SendLocalizedMessage(1080444);
                        return;
                    }
 
                    if (o is BaseMeleeWeapon)
                    {
                        if (Imod == 1 || Imod == 2 || Imod == 12 || Imod == 13 || Imod == 16 || Imod == 21 || Imod == 22 || (Imod >= 25 && Imod <= 41) || Imod >= 101)
                        {
                            ImbuingGumpC.ImbueItem(from, o, Imod, pm.ImbLast_ModInt);
                            return;
                        }
                    }
                    else if (o is BaseRanged)
                    {
                        if (Imod == 1 || Imod == 2 || Imod == 12 || Imod == 13 || Imod == 16 || Imod == 21 || Imod == 22 || Imod == 60 || Imod == 61 || (Imod >= 25 && Imod <= 41) || Imod >= 101)
                        {
                            ImbuingGumpC.ImbueItem(from, o, Imod, pm.ImbLast_ModInt);
                            return;
                        }
                    }
                    else if (o is BaseShield)
                    {
                        if (Imod == 1 || Imod == 2 || Imod == 19 || Imod == 16 || Imod == 22 || Imod == 24 || Imod == 42)
                        {
                            ImbuingGumpC.ImbueItem(from, o, Imod, pm.ImbLast_ModInt);
                            return;
                        }
                    }
                    else if (o is BaseArmor)
                    {
                        if (Imod == 3 || Imod == 4 || Imod == 5 || Imod == 9 || Imod == 10 || Imod == 11 || Imod == 21 || Imod == 23 || (Imod >= 17 && Imod <= 19))
                        {
                            ImbuingGumpC.ImbueItem(from, o, Imod, pm.ImbLast_ModInt);
                            return;
                        }
                    }
                    else if (o is BaseClothing)
                    {
                        if (Imod == 3 || Imod == 4 || Imod == 5 || Imod == 9 || Imod == 10 || Imod == 11 || Imod == 21 || Imod == 23 || (Imod >= 17 && Imod <= 19))
                        {
                            ImbuingGumpC.ImbueItem(from, o, Imod, pm.ImbLast_ModInt);
                            return;
                        }
                    }
                    else if (o is BaseJewel)
                    {
                        if (Imod == 1 || Imod == 2 || Imod == 6 || Imod == 7 || Imod == 8 || Imod == 12 || Imod == 10 || Imod == 11 || Imod == 20 || Imod == 21 || Imod == 23 || Imod == 21 || (Imod >= 14 && Imod <= 18) || (Imod >= 51 && Imod <= 55) || Imod >= 151)
                        {
                            ImbuingGumpC.ImbueItem(from, o, Imod, pm.ImbLast_ModInt);
                            return;
                        }
                    }
                    else
                        from.SendMessage("The selected item cannot be Imbued with the last Property..");
 
                    return;
                }
                else
                    from.SendMessage("You cannot imbue that.");
 
                return;
            }
        }

added a new 'if'
Code:
if ( from.Target is Item )
{
  ***
  ***
}
else
  from.SendMessage("You cannot imbue that.");
return;
 

espcevan

Sorceror
I was close. Glad you got it fixed and it is now working.

Thanks for the help tho.

I'm still having another issue with Imbuing
  • More than one person clicks imbue and click an item
  • one of the people pick a property to imbue and click "Imbue"
  • the other person that has the window waiting to pick the property gets the imbue on there targeted item without doing anything
  • the person that already picked there property and chose to imbue the item looses the ingredients and gets no imbued items
Its like everyone doing imbue at the same time is connected some how
 
the variables are shared in the system. You do not have separate instances of the variable for each person unless it is in a getter/setter variable. If the imbue target is passed along if anyone else has an imbue target that will become the new item in the variable.

I have not really looked at the imbuing system too much. I have heard it is very buggy. I am trying to think of how it was done on OSI.

I wrote an augment system where I put the meat of my code in the target routine to prevent this.

How I think I would solve the imbuing issue: I would add a new getter/setter to the PlayerMobile for imbuing target. Store the item targeted to that variable. When the imbue happens you can put that players imbue target and you wont have players imbuing each others items.

This would not have to be serialized because if the server crashes they will need to re-open the gump and pick a new target anyways.

Of course this will most likely require heavy rewriting of the imbuing script sadly. Maybe once my current server start up slows down I will look into rewriting the imbuing system that is here on runuo.
 

espcevan

Sorceror
That would be cool. We decided to disable the imbuing stuff for now until there is a set fix for Imbue. Runecrafting is in its place for the time being.
 
Top