3D Maze FAQ


Q: Why does find_maze_path() not take in any parameters? Shouldn't I pass in 3 indexes?

The find_maze_path() function that is in the interface is what we call a starter function. Oftentimes recursive functions can get really complicated and so to make things simple we have a starter function that takes in no parameters. Inside of there is where we call the actual recursive function
Lets take a 2D maze as an example. The actual recursive function we are going to use will be called: rec_find_maze_path(int x, int y) (you can name yours whatever you want). This is where all the code for recursing is going to happen. Then if we want to call that function we would do it in find_maze_path() which should look something like this:

bool find_maze_path() {
    return rec_find_maze_path(0,0);
}
So to start, we will call myMazeObject.find_maze_path(); which will in turn call rec_find_maze_path(0,0) and start the recursion at cell [0,0].

Q: How do I deal with Valgind errors?

It's important to remember that while Valgrind does tell you if you have memory leaks, it doesn't only tell you that; sometimes valgrind errors are not related to leaks and are instead telling you about bad memory you are accessing (ex: uninitialized variables, accessing out of bounds memory, using delete on a null pointer, etc). For this lab the most common issues are:

  • Mixing up the dimensions of your 3D array and accessing out of bounds
  • Freeing your memory in the wrong order, and thus using delete on a spot in memory that is not allocated with new
  • Forgetting to free up the memory used for your 3D array in the destructor.
If you run into Valgrind errors while doing this lab, check these things out first, and make sure you are setting breakpoints and single stepping through your code to try and find what case is causing your issue. As always, use this link as a guide for understanding valgrind output.