(a) A proceeding under this title shall be commenced in
(1) the county in which the alleged delinquent conduct or conduct indicating a need for supervision occurred; or
(2) the county in which the child resides at the time the petition is filed, but only if:
(A) the child was under probation supervision in that county at the time of the commission of the delinquent conduct or conduct indicating a need for supervision;
(B) it cannot be determined in which county the delinquent conduct or conduct indicating a need for supervision occurred; or
(C) the county in which the child resides agrees to accept the case for prosecution, in writing, prior to the case being sent to the county of residence for prosecution.
(b) An application for a writ of habeas corpus brought by or on behalf of a person who has been committed to an institution under the jurisdiction of the Texas Juvenile Justice Department and which attacks the validity of the judgment of commitment shall be brought in the county in which the court that entered the judgment of commitment is located.