【发布时间】:2024-04-26 11:10:01
【问题描述】:
我有一个非常奇怪的错误。我有一个 int 类型的对象属性,称为 currentState
这是声明
class WorkerAgent : public BaseAgent {
private:
int currentState;
下面的代码在游戏循环中运行了很多次,但有时(在随机时间)代码会在第 (270) 行对程序进行追逐
*OBS: currentState 在运行这行代码时已经初始化(270)!
if (currentState == REPAIRING) {
if (!unit->isRepairing()) {
setState(GATHER_MINERALS);
BaseAgent* base = AgentManager::getInstance()->getClosestBase(unit->getTilePosition());
if (base != NULL) {
unit->rightClick(base->getUnit());
return;
}
} else {
return;
}
}
int cur = currentState; // (line 270)
bool b = cur == FIND_BUILDSPOT;
我有一个 EXCEPTION_ACCESS_VIOLATION 并且程序 chashes.. 我不知道会发生什么,因为 currentState 既不是指针也不是 cur
错误
VERSION: 1.16.1.1
BWAPI:
REVISION: 4160
BUILD: RELEASE
ERROR: None
LOCATION: Single Player
MAP: Stepping Stones
(3)Stepping Stones.scm
EXCEPTION: 0xC0000005 EXCEPTION_ACCESS_VIOLATION
FAULT: 0x10044217 BWAPI.dll
REGISTERS:
EDI: 00000140
ESI: 00000003
EBX: 00000000
EDX: C208C483
ECX: 5B46A60C
EAX: 035F0001
EBP: 0018EEE8
EIP: 10044217
ESP: 0018E4C4
STACK:
BWAPI.dll 0x10044217 ----
BWAPI.dll 0x10046C38 ----
BWAPI.dll 0x10047A43 ----
BWAPI.dll 0x100408C6 ----
DUMB.DLL 0x5B4254A0 WorkerAgent::computeActions
d:\programming\mestrado\bots\dumb\bthaimodule\source\workeragent.cpp:270
有关此案的任何其他信息,请询问我!这个问题我快疯了!
【问题讨论】:
-
currentState是否已初始化或以其他方式赋值? -
是的! currentState 已经初始化了!
-
第 270 行到底在哪里?
-
int cur = currentState; //(第 270 行)
-
未初始化是我拥有的最相关的东西。现在,如果它在那条线上崩溃,我怀疑还有其他一些未定义的行为。
标签: c++ exception access-violation