You have omitted a very important part of the change of variables. What happens to $dx$? In particular, you know that $dt = \cos x dx$, but you have no $\cos x$ term in your integrand. Trying to incorporate it is a bit challenging, and your problem lies within this.
Extremely important is that the relationship between $dt$ and $\cos x dx$ changes halfway through the integral, and the two halves do not cancel.
In particular, $\cos x=\pm\sqrt{1-\sin^2x}=\pm\sqrt{1-(t-1)^2}=\pm\sqrt{2t-t^2}$. You change which branch of the square root you use halfway through the integral. You cannot substitute both $\pm$ at the same time. For part of the integral, you do one, for the rest, you do the other, choosing the signs that make sense. This is why you must split on $x = \pi/2$. This sign change makes it so the two halves add instead of canceling. You are acting as if there is no sign change and they cancel.