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!

StackOverflowException

siran

Sorceror
After about 5-6 hours of modifying a LOT of code involving most types of weapons, runuo crashes on startup with no crash log. The message given is "StackOverflowException".

Using WinMerge I compared my code with yesterday's backup and could not find any examples of infinite loops or self-calling code. I found a post where someone reported a similar problem involving the GetProperties method, so I removed a modification I had made to GetProperties in the BaseWeapon.cs script. That solved the problem and half the reason for this post is maybe that will help someone else who encounters this problem. The other half of the reason for this post is to see if anyone can shed some light on WHY this modification caused the problem.

Here is the change I made:
Code:
MinDamage += (int)(MinDamage * CraftResources.GetDamageModifier (Resource));
MaxDamage += (int)MaxDamage * CraftResources.GetDamageModifier (Resource));
list.Add (1061168, "{0}/t{1}", MinDamage.ToString (), MaxDamage.ToString ());
I added the two lines above the list.Add line, where I am calling a method I made in ResourceInfo.cs which is as follows:
Code:
public static double GetDamageModifier (CraftResource resource)
        {
            double modifier = 0.0;
            CraftResourceInfo info = GetInfo (resource);
            CraftAttributeInfo attr = info.AttributeInfo;
            if (attr != null)
                modifier = attr.DamageModifier;
            return modifier;
        }
This method simply accesses a new variable I added to CraftAttributeInfo to allow damage to be modified depending on the resource of which the weapon is made.

What I don't understand is what about this would cause a stack overflow exception.
 

pooka01

Sorceror
-----

MinDamage += (int)(MinDamage * CraftResources.GetDamageModifier (Resource));
MaxDamage += (int)->(<-MaxDamage * CraftResources.GetDamageModifier (Resource)); //missing parenthesis.

-----

"where I am calling a method I made in ResourceInfo.cs"

CraftResources.GetDamageModifier (Resource)); //wrong place? supposed to be in ressourceinfo?

-----

list.Add (1061168, "{0}/t{1}", MinDamage.ToString (), MaxDamage.ToString ());

list.Add (1061168, "{0}/t{1}", MinDamage, MaxDamage); //ToString() is called by default.

-----

All i can see that goes out of place.
 

siran

Sorceror
Pooka01, thanks for your reply. I didn't copy/paste that code and left off the parenthesis when I typed it into the thread, but it is there in the code. In any event, the code all compiles just fine. the CraftResources.GetDamageModifier is correct and works fine from some other calls to it. So it's not syntax not able to find the method. Simply remarking the two lines before the list.Add line in BaseWeapon allows RunUO to run just fine. I'm just wondering why modifying those two variables in the GetProperties method of BaseWeapon results in a stack overflow exception.
 
Top