ArgumentNullException?

Topics: Developer Forum
Jul 25, 2007 at 12:01 AM
This is probably going to turn out to be an incredibly stupid question, but sometimes it takes two pairs of eyes. ;)

When a new object is spawned in-game it causes the program to crash. "_texture2D" in the Sprite class is equal to null, even though the correct asset was passed to the SpriteObjectView constructor.

When the same object is created with identical parameters at the very start of the game, there is no crash.

I made a function in my Game1 class (I know, creative) to spawn said object. When the function is used in a KeyDownAction thingy, the program crashes. When the same function is within the Initialize() function, everything behaves normally.

What gives?

Also, while I'm here, I think you should give the FarseerGame some new public int variables or something so I know what the width and height of the viewport is (which may not always be 1024x768). Unless they're already there, then in that case I'm so embarrassed...
Coordinator
Jul 25, 2007 at 5:26 PM
I don't have a good answer for you on this. The 'FarseerGame' project is(was) not part of the physics engine. It was just a playground application I used for testing out the engine.

In fact, there is no "FarseerGame" project in the next release. I'm not sure what is causing your error, and I'm at work so I can't dig thru my old code. Sorry I can't be of more help on this.





ccxvi wrote:
This is probably going to turn out to be an incredibly stupid question, but sometimes it takes two pairs of eyes. ;)

When a new object is spawned in-game it causes the program to crash. "_texture2D" in the Sprite class is equal to null, even though the correct asset was passed to the SpriteObjectView constructor.

When the same object is created with identical parameters at the very start of the game, there is no crash.

I made a function in my Game1 class (I know, creative) to spawn said object. When the function is used in a KeyDownAction thingy, the program crashes. When the same function is within the Initialize() function, everything behaves normally.

What gives?

Also, while I'm here, I think you should give the FarseerGame some new public int variables or something so I know what the width and height of the viewport is (which may not always be 1024x768). Unless they're already there, then in that case I'm so embarrassed...

Jul 30, 2007 at 1:52 AM
I found a solution in case anyone else has this problem: Just use LoadGraphicsContent(true); if a new object is created. Obviously, the ArgumentNullException occurred when it did because it is called in the very beginning automatically. How stupid of me for not seeing this before. I'm certain this is the most inefficient solution available, loading everything again just to create one object, but it works.

LoadGraphicsContent(false); behaves pretty much like LoadGraphicsContent(true);. Maybe the former could just go through Texture2Ds that are equal to null...