I am trying to understand the proof here:
How to prove that this function is primitive recursive?
In the answer below, $f,\pi,g$ are primitive recursive. $P,G,h$ are defined in the way below: $$ \begin{align} P(n,x,0)&=x\\ P(n,x,i+1)&=\pi(n-(i+1),P(n,x,i)) \\ G(n,x,0)&=f(P(n,x,n)) \\ G(n,x,i+1)&=g(i,P(n,x,n-(i+1)),G(n,x,i)) \\ h(n,x) &= G(n,x,n) \\ \end{align} $$
I need to prove that $h$ is indeed primitive recursive. Here is my definition of primitive recursive:
And we can obtain recursive function by composition, as this picture mentions that it can be obtained by substitution:

So to prove that $h$ is primitive recursive, it is sufficient to prove $G$ is primitive recursive. But $G$ seems not to be a total function, and thus seems cannot be primitive recursive. For instance, it is not defined at $n=0,i+1=1$.
I am confused. So may I please ask if $G$ and $P$ are primitive recursive? How can I see this? Thanks in advance!