Fix master server thread segfaulting on startup #100

Merged
GenericHeroGuy merged 1 commits from ms-startup-crash into Saturn-Next 2024-02-09 10:06:55 +01:00
GenericHeroGuy commented 2024-02-08 20:01:14 +01:00 (Migrated from github.com)

I've finally figured out why the master server thread segfaults if you start the game without an internet connection on OpenGL!

In D_RegisterServerCommands, the main thread registers cv_masterserver, which starts the change-masterserver thread. Then, the main thread calls D_RegisterClientCommands, which registers a series of 20 cvars (starting with cv_globalgamma), all of which call V_SetPalette when initialized. At the same time, the MS thread might fail and print an error to the console. If there's no connection, it fails immediately.

At this point, a conflict occurs as the MS thread tries drawing patches while the main thread is flushing the cache; the patch in use by the MS thread is suddenly freed, triggering the segfault.

My solution? Move those 20 cvars to SCR_Startup, which runs before D_RegisterServerCommands.

Also, while researching, I found and fixed a bug in HMS_set_rules which made it accidentally return its (uninitialized) buffer if HMS_do fails.

I've finally figured out why the master server thread segfaults if you start the game without an internet connection on OpenGL! In ``D_RegisterServerCommands``, the main thread registers ``cv_masterserver``, which starts the ``change-masterserver`` thread. Then, the main thread calls ``D_RegisterClientCommands``, which registers a series of 20 cvars (starting with ``cv_globalgamma``), all of which call ``V_SetPalette`` when initialized. At the same time, the MS thread might fail and print an error to the console. If there's no connection, it fails immediately. At this point, a conflict occurs as the MS thread tries drawing patches while the main thread is flushing the cache; the patch in use by the MS thread is suddenly freed, triggering the segfault. My solution? Move those 20 cvars to ``SCR_Startup``, which runs before ``D_RegisterServerCommands``. Also, while researching, I found and fixed a bug in ``HMS_set_rules`` which made it accidentally return its (uninitialized) buffer if ``HMS_do`` fails.
alufolie91 commented 2024-02-09 09:49:04 +01:00 (Migrated from github.com)

Thats why ppl should stop throwing stuff into d_netcmd lmao jk
But ye seems good and logical to me

Thats why ppl should stop throwing stuff into d_netcmd lmao jk But ye seems good and logical to me
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: saturn/SRB2Kart-Saturn#100