当我在调试模式下运行我的程序时,它会在一个非 null 的对象上弹出 NullReferenceException - 它显示为在 Locals 视图中定义的那样。有问题的对象是 SFML.Graphics.Sprite,其中只有一个字段为空(myInverseTransform),但是当我检查其他 Sprite 时,它们在那里也为空。
有谁知道什么会导致这种情况,或者我怎样才能找到异常所指的空对象是什么?
相关代码:
这是代码:
(在雪碧中:)
public void Draw(RenderTarget target, RenderStates states)
{
states.Transform *= Transform;
RenderStates.MarshalData marshaledStates = states.Marshal();
if (target is RenderWindow)
{
sfRenderWindow_drawSprite(((RenderWindow)target).CPointer, CPointer, ref marshaledStates);
}
else if (target is RenderTexture)
{
sfRenderTexture_drawSprite(((RenderTexture)target).CPointer, CPointer, ref marshaledStates);
}
}
(在变换中:)
public static Transform operator *(Transform left, Transform right)
{
return new Transform(left).Combine(right);
}
public Transform Combine(Transform transform)
{
sfTransform_combine(CPointer, transform.CPointer);
return this;
}
else if (target is RenderTexture)
{
sfRenderTexture_drawSprite(((RenderTexture)target).CPointer, CPointer, ref marshaledStates);
}
}
调用 Sprite.Draw this.Transform 时定义的问题(根据 Locals 视图),但在 Transform 的 * 运算符中,正确的变量为 null;