MelonSponge:Yes, i think i made a bit of a mistake of thinking that i could learn as i went, like i did with VB.
The problem is really simple when you look at the code. Take a look
| public GameObject() |
| { |
| gameobject = new GameObject(); |
| boneTransforms = new Matrix[gameobject.model.Bones.Count]; |
| |
| |
| } |
Here you have gameobject = new a new GameObject. So when you run this method if a Gameobject is created it will make a new GameObject,
then that GameObject will run the same method and create another GameObiject, this will happen forever. This is why you get the stack overflow. Does that make sense?
Think of it this way.
I create a new game object called Paul when Paul is created it runs the method inside and creates a gameobject = to a new GameObject();
when gameobject is created it then creates a new gameobject inside that gameobject.
This will never end.
If you wish to pass data inside methods you should do something like the following :
| using System; |
| using System.Collections.Generic; |
| using System.Linq; |
| using System.Text; |
| |
| namespace ConsoleApplication1 |
| { |
| class Program |
| { |
| |
| static void Main(string[] args) |
| { |
| |
| //This calls the method and passes the vars 1 and 2. The result will be 3. |
| |
| //Write to console |
| Console.WriteLine( |
| //Call the Add2Number Method, Pass in the int of 1 and 2 |
| //the .ToString will convert our int to a string |
| Add2Numbers(1, 2).ToString()); |
| //Pause so user can see output |
| Console.ReadLine(); |
| } |
| //Set method to acept 2 numbers to add |
| static int Add2Numbers(int a, int b) |
| { |
| //add numbers passed in |
| int answer = a + b; |
| //return result |
| return answer; |
| } |
| } |
| } |
| |
Or in your case you would want something like this:
| public GameObject(Model model) |
| { |
| boneTransforms = new Matrix[model.Bones.Count]; |
| } |
then when you call the method do something like
| GameObject(gameobject.model); |