Skip to content
View in the app

A better way to browse. Learn more.

WRobot

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Why does this code crash WRobot?

Featured Replies

I'm at the end of my rope. For some reason this code crashes WRobot. I have it in a while loop. Log included...

private void FoodManager()
	{
		if (sRogueSettings.CurrentSetting.UseBuffFood && sRogueSettings.CurrentSetting.BuffFoodName != null && sRogueSettings.CurrentSetting.BuffFoodBuffName != null)
		{
			uint foodID = wManager.Wow.Helpers.ItemsManager.GetIdByName(sRogueSettings.CurrentSetting.BuffFoodName);
			if (!ObjectManager.Me.HaveBuff(sRogueSettings.CurrentSetting.BuffFoodBuffName) && ItemsManager.HasItemById(foodID) && wManagerSetting.CurrentSetting.FoodName != sRogueSettings.CurrentSetting.BuffFoodName)
			{
				wManagerSetting.CurrentSetting.FoodName = sRogueSettings.CurrentSetting.BuffFoodName;
			}
			else if (ObjectManager.Me.HaveBuff(sRogueSettings.CurrentSetting.BuffFoodBuffName) && wManagerSetting.CurrentSetting.FoodName != originalFoodSetting)
			{
				wManagerSetting.CurrentSetting.FoodName = originalFoodSetting;
			}
		}
	}

 

10 11 2017 21H30.log.html

Hello, if something crashes and it's not a stack overflow (recursive call) you may wrap your code in a try-catch statement:

    private void FoodManager()
    {
        try
        { 
            if (sRogueSettings.CurrentSetting.UseBuffFood && sRogueSettings.CurrentSetting.BuffFoodName != null && sRogueSettings.CurrentSetting.BuffFoodBuffName != null)
            {
                uint foodID = wManager.Wow.Helpers.ItemsManager.GetIdByName(sRogueSettings.CurrentSetting.BuffFoodName);
                if (!ObjectManager.Me.HaveBuff(sRogueSettings.CurrentSetting.BuffFoodBuffName) && ItemsManager.HasItemById(foodID) && wManagerSetting.CurrentSetting.FoodName != sRogueSettings.CurrentSetting.BuffFoodName)
                {
                    wManagerSetting.CurrentSetting.FoodName = sRogueSettings.CurrentSetting.BuffFoodName;
                }
                else if (ObjectManager.Me.HaveBuff(sRogueSettings.CurrentSetting.BuffFoodBuffName) && wManagerSetting.CurrentSetting.FoodName != originalFoodSetting)
                {
                    wManagerSetting.CurrentSetting.FoodName = originalFoodSetting;
                }
            }
        }
        catch (Exception e)
        {
            robotManager.Helpful.Logging.WriteError(e.ToString());
        }
    }

I think you have probably a null reference exception on your settings, so you would check for "sRogueSettings.CurrentSetting" whether it is null at first.

And "sRogueSettings.CurrentSetting.BuffFoodName != null" is not necessary on a string, since checking against null will result always in false.

  • Author
1 hour ago, reapler said:

Hello, if something crashes and it's not a stack overflow (recursive call) you may wrap your code in a try-catch statement:


    private void FoodManager()
    {
        try
        { 
            if (sRogueSettings.CurrentSetting.UseBuffFood && sRogueSettings.CurrentSetting.BuffFoodName != null && sRogueSettings.CurrentSetting.BuffFoodBuffName != null)
            {
                uint foodID = wManager.Wow.Helpers.ItemsManager.GetIdByName(sRogueSettings.CurrentSetting.BuffFoodName);
                if (!ObjectManager.Me.HaveBuff(sRogueSettings.CurrentSetting.BuffFoodBuffName) && ItemsManager.HasItemById(foodID) && wManagerSetting.CurrentSetting.FoodName != sRogueSettings.CurrentSetting.BuffFoodName)
                {
                    wManagerSetting.CurrentSetting.FoodName = sRogueSettings.CurrentSetting.BuffFoodName;
                }
                else if (ObjectManager.Me.HaveBuff(sRogueSettings.CurrentSetting.BuffFoodBuffName) && wManagerSetting.CurrentSetting.FoodName != originalFoodSetting)
                {
                    wManagerSetting.CurrentSetting.FoodName = originalFoodSetting;
                }
            }
        }
        catch (Exception e)
        {
            robotManager.Helpful.Logging.WriteError(e.ToString());
        }
    }

I think you have probably a null reference exception on your settings, so you would check for "sRogueSettings.CurrentSetting" whether it is null at first.

And "sRogueSettings.CurrentSetting.BuffFoodName != null" is not necessary on a string, since checking against null will result always in false.

Oh right, didn't think of that, still new and learning :)

Yup, it was "Object reference not set to an instance of an object. in Main.FoodManager()"

However still don't understand the exception. What is out of place? Everything seems to be set up correctly. How do I pinpoint where the error is?

31 minutes ago, Seminko said:

How do I pinpoint where the error is?

You may check first whether "sRogueSettings.CurrentSetting" is null:

    private void FoodManager()
    {
        try
        { 
            if (sRogueSettings.CurrentSetting == null)
                robotManager.Helpful.Logging.Write("CurrentSetting is null");
            else
                robotManager.Helpful.Logging.Write("CurrentSetting is not null");
        }
        catch (Exception e)
        {
            robotManager.Helpful.Logging.WriteError(e.ToString());
        }
    }

You get probably "CurrentSetting is null" ;)

So in this case this means you haven't initialized "CurrentSetting" = no instance to your object is given = "CurrentSetting" is null, hence you cannot accessing its properties.

In the end you need to call "sRogueSettings.Load();" to create an instance.

However If it's not the case, you may check for other variables against null.

Edited by reapler

  • Author
10 hours ago, reapler said:

You may check first whether "sRogueSettings.CurrentSetting" is null:


    private void FoodManager()
    {
        try
        { 
            if (sRogueSettings.CurrentSetting == null)
                robotManager.Helpful.Logging.Write("CurrentSetting is null");
            else
                robotManager.Helpful.Logging.Write("CurrentSetting is not null");
        }
        catch (Exception e)
        {
            robotManager.Helpful.Logging.WriteError(e.ToString());
        }
    }

You get probably "CurrentSetting is null" ;)

So in this case this means you haven't initialized "CurrentSetting" = no instance to your object is given = "CurrentSetting" is null, hence you cannot accessing its properties.

In the end you need to call "sRogueSettings.Load();" to create an instance.

However If it's not the case, you may check for other variables against null.

I'm stupid... did not have sRogueSettings.Load(); :wub:

A small template, also creates an instance on null. Saving manually with "sRogueSettings.CurrentSetting.Save();"


    public class SRogueSettings : robotManager.Helpful.Settings
    {
        public bool UseBuffFood { get; set; }

        public string BuffFoodName { get; set; }

        //...

        public static SRogueSettings CurrentSetting
        {
            get
            {
                if (_currentSetting == null && !_cannotLoad)
                    Load();
                return _currentSetting;
            }
            set
            {
                _currentSetting = value;
            }
        }

        private static bool _cannotLoad;
        private static SRogueSettings _currentSetting;

        public bool Save()
        {
            try
            {
                _cannotLoad = !Save(AdviserFilePathAndName("SRogue", ObjectManager.Me.Name + "." + Usefuls.RealmName));
                return !_cannotLoad;
            }
            catch (Exception e)
            {
                Logging.WriteError(e.ToString());
                _cannotLoad = true;
                return false;
            }
        }
        
        public static bool Load()
        {
            try
            {
                if (File.Exists(AdviserFilePathAndName("SRogue", ObjectManager.Me.Name + "." + Usefuls.RealmName)))
                {
                    CurrentSetting = Load<SRogueSettings>(AdviserFilePathAndName("SRogue", ObjectManager.Me.Name + "." + Usefuls.RealmName));
                    return true;
                }
                _cannotLoad = true;
                CurrentSetting = new SRogueSettings
                {
                    UseBuffFood = true,
                    BuffFoodName = "",
                };
            }
            catch (Exception e)
            {
                Logging.WriteError(e.ToString());
            }
            return false;
        }
    }

 

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.