It's way to avoid a lot of rpg horro stories the classical one include
-
Clear description of the game (which is done in this comic) properly managing expectations is already great
-
Line and veil, in the sense writing done theme that you don't want at the table, and themes which can be present but not in plain sight for example most people do close the door when having sex, so let's do the same in tabletop no need to go further than the bard joined the elf in their room, and what happened behind closed door stay behind closed door
-
X card, which is a kind of last ressort measure and allows anyone to stop a scene going to far
Then, some people push further and added way to modulate the intensity of a scene, like asking for more or less depending on how you feel. Being at the verge of tears after a consented intense scene can be one of your best RPG memory ever but being at the verge of tear after feeling like another player assaulted you, can be a horror story, and the difference is just about Accepting it
The whole We play a game so you have to cooperate together even if role-play wise it makes no sense is a bad practice, May-be not at the point you'll leave the table but definitely a serious sign that the table doesn't function properly.
Luckily, there is a very easy fix Do a session zero, and build a coherent party ab initio, it include in game reason for the party to work together, coherent goals (because when player A wants to abolish the reign of the emperor, and player B wants to defend the emperor you'll have a PvP fight within 3 session) and a meta discussion to have a pallet of skills matching the party's goal (At least in more epic game where you don't want to feel powerless). Almost every RPG published in the last 10-15 years contains an extensive session zero guide and tons of tips to build a relevant party.
If someone wants to play a law priest in a pirate campaign or any other character not fitting the campaign theme or opposing other PCs, it's perfectly OK to tell the no. Obviously if everybody is aligned on some PvP and betrayal the answer may be different, but it's again something to address in session zero.