Your algorithm has a problem. You rely on the fact that
there is atmost one possible direction from any cell
and that that path can never be circular.
In case of a binary matrix that conditions are bound to fail.
You move from (0,0) to (1,0) to (0,0) to (1,0) to (0,0) to (1,0) to (0,0) to (1,0) to (0,0) to (1,0) to (0,0) to (1,0) to (0,0) to (1,0) to (0,0) to (1,0) to (0,0) to (1,0) to (0,0) to (1,0) to (0,0) to (1,0) to (0,0) to (1,0) an so on 🙂
So your algorithm terminates when the stack is full since with the preconditions you chose the longest path length is infinite and only Chuck Norris can do infinite loops in finite time.
Edit: I strongly support the comment by Xeverous. You really should refactor your code to be more c++. That makes the code easier to read and you would have easily seen the problem.
solved My c++ program has stopped working