WiiRd forum

Off-topic => Off-topic => Topic started by: toonlink444 on March 23, 2012, 03:30:45 PM

Title: Object reference not set to an instance of an object
Post by: toonlink444 on March 23, 2012, 03:30:45 PM
I've received this new error and I can't seem to fix it. I figured out that a value is returning null but I can't find a way to fix it.
Here's the code.
[spoiler]public void ChangeSize(ResourceNode parent ,Vector3 scale)
        {
            FileStream fs = new FileStream(Application.StartupPath + "\\Output\\Output.brres", FileMode.Open);
            CHR0EntryNode entry;

            foreach (ResourceNode r in parent.Children)
            {
                if (r is CHR0EntryNode)
                {
                    entry = r as CHR0EntryNode;                   
                    entry.SetKeyframeOnlyScale(0, scale);                   
                }
            }
            fs.Close();
        }[/spoiler]
The line in bold is the issue, but it's declared here.
[spoiler]public void ChangeSize(ResourceNode parent ,Vector3 scale)[/spoiler]
So what gives I've been editing for over a hour and it's really irritating.
Title: Re: Object reference not set to an instance of an object
Post by: James0x57 on March 23, 2012, 09:51:48 PM
However you set the array "parent.Children" probably has a mistake in it. To use that foreach loop, each of parent.Children[x] must be a "ResourceNode" object.

Mind posting the function that adds to the Children array?

Title: Re: Object reference not set to an instance of an object
Post by: toonlink444 on March 23, 2012, 11:58:41 PM
I'm using the BrawlLib.dll so I didn't make the array, but I checked out some of the source code of a BrawlLib.cs and ResourceNode Children and a different function then it does in my code so I'll add that code into mine.
Title: Re: Object reference not set to an instance of an object
Post by: toonlink444 on March 24, 2012, 05:44:54 PM
Hmmmm same error. I'm thinking that I may need to add BrawlLib.cs to the program to see what will fix it.
Here's the function for both mine and BrawlLib.
Mine:
[spoiler]public void ChangeSize(Reference parent,Vector3 scale)
        {
            FileStream fs = new FileStream(Application.StartupPath + "\\Output\\Output.brres", FileMode.Open);
            CHR0EntryNode entry;

            foreach (ResourceNode r in parent.Children2)
            {
                if (r is CHR0EntryNode)
                {
                    entry = r as CHR0EntryNode;                   
                    entry.SetKeyframeOnlyScale(0, scale);                   
                }
            }
            fs.Close();
        }
-------------------------------------------
public abstract class Reference
    {
        internal protected List<ResourceNode> _children = new List<ResourceNode>();

        public List<ResourceNode> Children2
        {
            get
            {
                if (_children == null)
                {
                    _children = new List<ResourceNode>();
                }
                return _children;
            }
        }
    }
}[/spoiler]
BrawlLib:
[spoiler]public List<ResourceNode> Children
        {
            get
            {
                if (_children == null)
                {
                    _children = new List<ResourceNode>();
                    if (WorkingSource != DataSource.Empty)
                        OnPopulate();
                }
                return _children;
            }
        }[/spoiler]
I eliminated some of BrawLib's code as to remove unnecessary code and not clutter the form. See any errors?