Unpopular opinion, but I would say do not be afraid to buy a house. As long as you're buying the house to live in it (and not purely for investment and price speculation), you can go ahead and buy a house in Thailand. However, you do need to understand the Thai laws and seek a lawyer to advice you on how to protect your rights legally.
In the event of divorce, you're legally entitled to 50% of the property, i.e, your ex-wife can't just evict you of your property (as long as you have the right visa to stay in Thailand, your marriage visa expires as soon as you get a divorce). You both have the option to either sell the property and divide the proceedings
*****
. But the issue arises when one of the partner (usually the Thai wife and her relatives) doesn't want to sell the house. Hence, you need a Usufruct Contract and a pre-nup agreement. Talk to your lawyer and have an agreement drafted where you both agree to sell the house upon divorce and also what happens to the property (and to the personal assets) in the event where one of the partner dies, i.e, what'll happen if your wife dies and what'll happen if you die.
Don't leave anything unto luck. Every scenario needs to be considered and taken into account and an agreement needs to be drafted and legalised. Believe it or not, more often than not it'll be your wife's family and relative that'll try screwing you up.