bug在发布中,不在调试中
Bugs in Release not in Debug
我正在为路径规划/避免碰撞方法构建一个自上而下的视图演示。c++ in Visual Studio 2010.
当我运行在调试模式一切都很好。但当我在释放中运行时,疯狂的行为发生了。以前我的角色在遇到其他角色时会加速并改变方向,而现在他们只是消失了(可能移动到屏幕外的某个地方)。
搜索表明,这通常是由于浮点操作。我删除了所有的浮点数,并且浮点模型已经在调试和发布时都是精确的。我不知道从这里该去哪里…
我很确定这段代码是错误的来源。每个字符都可以在一个单元格中找到。在单元边缘,字符的平均速度被存储(cell->vLeft等),并且这个字符想要平均它自己的速度与存储在单元边缘上的速度。
void CharacterQueryStructure_Grid::computeActualVelocity(Character& character, double dt){
// find the cell for this character
const CellCoord& cellID = _posToCell2D(character.getPosition());
int x = cellID.first, y = cellID.second;
int layerID = character.getLayer();
if(x == -1 && y == -1){ // if the position is invalid, return no neighbours
//TODO: ERRORRRR
//return Point(NULL, NULL);
character.setNewVelocity_EulerIntegration(character.getPreferredVelocity(), dt);
}
else{
//Interpolate between the four points to find the average velocity at that location
UIC_cell* cell = uicGrids[layerID][_getCellID(x,y)];
double distLeft = (character.getPosition().x - xMin) - cellSize * x;
double distBot = (character.getPosition().y - yMin) - cellSize * y;
//First find the interpolated velocity at the location of your projection on the horizontal and vertical axes.
Point vHor = cell->vLeft * ((cellSize - distLeft)/cellSize) + cell->vRight * (distLeft/cellSize);
Point vVer = cell->vBot * ((cellSize - distBot)/cellSize) + cell->vTop * (distBot/cellSize);
//Now interpolate these to your location
double distHor = abs(distLeft - .5 * cellSize);
double distVer = abs(distBot - .5 * cellSize);
//Point vAverage = vHor * (distHor / (.5 * cellSize)) + vVer * (distVer / (.5 * cellSize));
Point vAverage = (vHor + vVer) / 2;
//Calculate the new velocity based on your own preferred velocity, the average velocity and the density in your cell.
Point newVelo = character.getPreferredVelocity() + (cell->density / maxDensity) * (vAverage - character.getPreferredVelocity());
// set it, while adhering smoothness constraints
character.setPreferredVelocity(newVelo);
}
}
任何帮助都将非常感激!
编辑:这里是_posToCell2D…
CellCoord CharacterQueryStructure_Grid::_posToCell2D(const Point& pos) const
{
int x = (int)floor((pos.x - xMin) / cellSize);
int y = (int)floor((pos.y - yMin) / cellSize);
// if this coordinate lies outside the grid: return nothing
if(x < 0 || y < 0 || x >= xNrCells || y >= yNrCells)
return CellCoord(-1,-1);
// otherwise, return the correct cell ID
return CellCoord(x,y);
}
切换时的一个常见故障是未初始化变量的行为。您是否曾经将所有的uicGrids[][]设置为一些初始值?
通常,Debug会自动将这些初始化为0。
如果以上猜测都没有帮助,那么调试的有效方法是临时添加大量日志语句并写入日志文件,以便您可以跟踪代码执行并查看变量的值。
相关文章:
- 正在VS调试器中监视映射条目
- 调试符号中缺少 QObject 类信息(编辑但存在其他 Qt 类)
- 发布版本中的 Qt 隐形组合框(但不在调试版本中)
- VSCode C++调试文件名中包含中文字符的文件时插件损坏
- 在调试配置中编译工作正常,但发布会给出链接错误
- 标识gdb调试器中符号的源文件名
- 有没有一种预处理器的方法可以从调试符号中删除代码段
- GCC:在调试构建中优化的静态数据成员
- 在 Visual Studio 调试器中,如何从内存中打印字节范围?
- 应用程序仅在qt调试器中加载dll,而不是独立加载
- 在调试配置中仅优化单个方法
- 为什么迭代器调试在调试版本中会减慢 std::unordered_map 200 倍?
- 获取stacktrace for Crash,而无需在调试器中运行该应用程序
- Qt curl.exe在调试/发布中工作,但不在部署中工作
- 按值传递的参数在 Visual Studio 2010, C++ 的调试器中显示为通过引用传递
- import_array在嵌入式Python C API的调试版本中不起作用
- 从VSCODE C 调试步骤中排除文件
- 类内定义的友元函数的调试标志中的命名空间
- 调试宏中的字符串变量扩展
- 在Qt调试器中reinterpret_cast错误的值