There are two main cases to distinguish.
1) There is a successor state. This is an easy case. The successor state takes on all treaty obligations unless specifically decided otherwise. Russia is the successor state of the USSR.
2) There is no successor state, either because the original state is conquered or too fragmented. South Vietnam would be an example of conquest, Yugoslavia of fragmentation. This is also fairly easy - there is no successor state, so the treaty stops applying to the defunct state. For a bilateral treaty, that means the end of the treaty, a multilateral treaty in general survives.
However, international politics is generally more descriptive than prescriptive. There are always edge cases. E.g. the dissolution of Czecho-Slovakia did not lead to a designated successor state. However, as part of the planned and peaceful divorce, both the Czech Republic and Slovakia accepted obligations from prior treaties, and were (as far as I can tell) both accepted as new signatories to existing treaties.