为什么这个搜索死循环了
```c++
#include "iostream"
#include "queue"
using namespace std;
char map[32][32][32];
int bookmap1[32][32][32];
int g;
int next1[6][3] = { {0,1,0},{0,-1,0},{0,0,1},{0,0,-1},{1,0,0},{-1,0,0} };
int l, r, c;
int temp = 0;
struct point {
int z;
int x;
int y;
int step;
};
int main() {
queue<point> q;
cin >> l >> r >> c;
while (1) {
g = 0;
if (l == 0 && r == 0 && c == 0)break;
for (int i = 0; i < l; i++, temp++) {
{
for (int j = 0; j < r; j++)
for (int z = 0; z < c; z++)
{
cin >> map[temp][j][z];
if (map[temp][j][z] == 'S')
{
q.push({ temp,j,z,0 });
map[temp][j][z] = '#';
}
}
}
}
while (!q.empty()) {
point t = q.front();
q.pop();
for (int i = 0; i < 6; i++) {
int tz = t.z + next1[i][0];
int tx = t.x + next1[i][1];
int ty = t.y + next1[i][2];
if (tz < 0 || tz >= l || tx < 0 || tx >= r || ty < 0 || ty >= c || map[tz][tx][ty] == '#' || bookmap1[tx][ty][tz] == 1)continue;
if (map[tz][tx][ty] == '.') {
q.push(point{ tz,tx,ty,t.step + 1 });
bookmap1[tz][tx][ty] = 1;
break;
}
if (map[tz][tx][ty] == 'E')
{
g = 1;
printf("Escaped in %d minute(s).\n", t.step + 1);
while (!q.empty()) q.pop(); // 4. 退出循环
break;
}
}
}
if (g == 0)
cout << "Trapped!" << endl;
for (int i = 0; i < l; i++) {
for (int j = 0; j < r; j++) {
for (int z = 0; z < c; z++) {
bookmap1[i][j][z] = 0;
}
}
}
temp = 0;
cin >> l >> r >> c;
}
return 0;
}
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/b449a0f2c54748e4810e5f2e78784b91.png "#left")