Object reference not set to an instance of an object

Started by toonlink444, March 23, 2012, 03:30:45 PM

Previous topic - Next topic

toonlink444

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.
In the begining there was nothing. Then it exploded
New blog!! Check it out for hacking Smash Bros Brawl!! http://letshackblank.blogspot.com/

James0x57

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?



toonlink444

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.
In the begining there was nothing. Then it exploded
New blog!! Check it out for hacking Smash Bros Brawl!! http://letshackblank.blogspot.com/

toonlink444

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?
In the begining there was nothing. Then it exploded
New blog!! Check it out for hacking Smash Bros Brawl!! http://letshackblank.blogspot.com/