저는 C++을 시험해 보는 C++ 프로그래머입니다. 나는 box2d를 C++로 많이 해왔지만 이것은 C#으로 처음 만든 첫 번째 시간입니다. 그래서 저는 먼 곳의 물리 엔진으로 간단한 게임을 만들려고합니다. 내 코드 (Visual Studio C# 2010 Express 및 xna 게임 스튜디오 4.0 사용)를 컴파일하려고 시도하면 body.cs에서 IBroadPhase broadPhase = World.ContactManager.BroadPhase;
으로 중단됩니다.이 오류는 nullreferenceexception was unhandled
입니다.farseer 물리 엔진의 body.cs에서 "nullreferenceexception이 처리되지 않았습니다"
public class Player : Entity
{
Vector2 position;
SpriteBatch spriteBatch;
Texture2D texture;
Rectangle rectangle;
Body body;
CircleShape shape;
Fixture fixture;
public Player()
{
// TODO: Construct any child components here
}
///
/// Allows the game component to perform any initialization it needs to before starting
/// to run. This is where it can query for any required services and load content.
///
public override void Initialize(World world, SpriteBatch spriteBatch, Texture2D texture)
{
// TODO: Add your initialization code here
this.spriteBatch = spriteBatch;
this.texture = texture;
rectangle = new Rectangle(0, 0, 11, 14);
body = BodyFactory.CreateBody(world);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(0, 0);
shape = new CircleShape(1.0f, 1.0f);
fixture = body.CreateFixture(shape);
base.Initialize(world, spriteBatch, texture);
}
///
/// Allows the game component to update itself.
///
/// <param name="gameTime" />Provides a snapshot of timing values.
public override void Update(GameTime gameTime)
{
// TODO: Add your update code here
base.Update(gameTime);
}
public override void Draw(GameTime gameTime)
{
spriteBatch.Begin();
spriteBatch.Draw(texture, new Vector2(body.WorldCenter.X * 10, body.WorldCenter.Y * 10), rectangle, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
파 시어의 테스트 베드가 잘 실행, 그래서 난 내 코드가 문제이며, 시어되지 확신 해요 : 그래서 여기에 대한 코드의 문제는 내 플레이어 클래스에 믿습니다. 내 코드를 더보고 싶다면 알려줘. 나는 farseer 공개 토론에서 이것을 또한 배치했다, 그래서 나는 거기 대답을 얻는 경우에, 나는 너희들에게 알릴 것이다. 미리 감사드립니다.
전체 스택 추적을 사용할 수 있습니까? – user7116
참조 : http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net –
오류 코드를 게시하지 않았습니다. 그럼에도 불구하고 해당 줄에 중단 점을 넣고 코드를 디버깅하십시오. 중단 점에 도달하면 객체 위로 마우스를 가져 가서 어느 것이 null인지 확인합니다. null 인 객체의 멤버에 액세스하려고하면이 예외가 발생합니다. null을 찾아 수정하십시오. –