Now that the primaries are over what happens if a candidate drops out of the race for one reason or another?

Would they be replaced on the ticket? or would the other side automatically win? Could someone launch a last-minute write-in campaign?

Let's just say it's something we might want to figure out sooner than later...