Recursive backtracking maze algorithm: Infinite loop/recursion limit?

Did you develop this yourself or follow a tutorial? I am making a mining game and need something to make caves.