我有一个函数 shortestPath(),它是 Dijkstra 算法的修改实现,用于我正在为我的 comp2 类工作的棋盘游戏 AI。我浏览了网站并使用 gdb 和 valgrind 我确切地知道段错误发生的位置(实际上几个小时前就知道了),但无法弄清楚是什么未定义的行为或逻辑错误导致了问题。
出现问题的函数被调用大约 10 倍并按预期工作,直到它与 GDB 出现段错误:“错误读取变量:无法访问内存”和 valgrind:“大小为 8 的无效读取”
通常这已经足够了,但我无法解决这个问题。也感谢任何一般性建议和提示...谢谢!
GDB:https:
//gist.github.com/mckayryan/b8d1e9cdcc58dd1627ea Valgrind:https : //gist.github.com/mckayryan/8495963f6e62a51a734f
这是发生段错误的函数:
static void processBuffer (GameView currentView, Link pQ, int *pQLen,
LocationID *buffer, int bufferLen, Link prev,
LocationID cur)
{
//printLinkIndex("prev", prev, NUM_MAP_LOCATIONS);
// adds newly retrieved buffer Locations to queue adding link types
appendLocationsToQueue(currentView, pQ, pQLen, buffer, bufferLen, cur);
// calculates distance of new locations and updates prev when needed
updatePrev(currentView, pQ, pQLen, …Run Code Online (Sandbox Code Playgroud)