Calculating Power of a Non-Continuous Signal
An integral is a sum like a + b + c...
a, b,c are the values of the function in the part that you are integrating.

Where the value does not exist, it has the value 0.
Adding 0 to a sum will not change that sum.

You already take that into account.

You say that the integral in the formula is \$\int_{\frac{-T}{2}}^{\frac{T}{2}}\$ and that \$T=\pi\$, which would lead to \$\int_{\frac{-\pi}{2}}^{\frac{\pi}{2}}\$, but actually the image shows that T = \$\frac{\pi}{2}\$, hence and the substitution is as you have written: \$\int_{\frac{-\pi}{4}}^{\frac{\pi}{4}}\$. This adjusts the lower and upper bound so that the values that are summed up by the integral are those different from 0, because integrating those does not add anything to the integral.

That's why it is wrong to divide by two.
In general: if you have a formula for something, use that formula, don't add more calculation to it, because that changes the formula and the result is something else.