편집 : 이것은 중복이 아니므로 NullReferenceException의 의미를 알고 있습니다. C# 서버 : 널 검사 후 바로 NullReferenceException
private Entity target;
private float newPathTimer;
private float attackTimer;
public override void Update(float deltaTime) {
attackTimer += deltaTime;
// Check for target
if (target != null) {
float distance = MathExtra.PointDistance(Entity.X, Entity.Y, target.X, target.Y);
"목표"로 설정되어있는 유일한 장소
:public override void Receive(ICommand message) {
if (message is Attack) {
target = SystemMessager.SendQuery<Entity>(new GetEntity(((Attack)message).entityID));
newPathTimer = NEW_PATH_RATE;
}
if (message is FollowPath) {
if (!((FollowPath)message).pursuit) {
target = null;
}
}
}
모든 참조를 "
은 다음 코드는 나에게 바로 NULL 체크 후"대상 "에 대한 NullReferenceException이를주고있다 "대상 :
그것이 만드는 경우 차이점은이 애플리케이션은 클라이언트에게 패킷을주고받는 서버입니다.
또한이 오류를 재현하는 방법을 모릅니다. 항상 발생하지는 않습니다.
편집 : 수신 방법은 특정 패킷이 수신 될 때마다 호출됩니다. 나는 패킷이이 문제를 일으키는 별도의 스레드에서 수신 될 수 있다고 생각합니다.
'target '이 다른 스레드에 의해 변형 될 수 있습니까? 그것이 항상 일어나는 것은 아니라는 것을 감안할 때, 이것은 경쟁 조건처럼 들립니다. – Stuart
null 및 void 메시지 란 무엇입니까? – ArthNRick
잠금 장치를 사용해보십시오 – Nkosi