Skip to content

Fix crash when calling TF2_IsHolidayActive while no map is running#1694

Closed
Mikusch wants to merge 1 commit intoalliedmodders:masterfrom
Mikusch:tf-holiday-crash
Closed

Fix crash when calling TF2_IsHolidayActive while no map is running#1694
Mikusch wants to merge 1 commit intoalliedmodders:masterfrom
Mikusch:tf-holiday-crash

Conversation

@Mikusch
Copy link
Contributor

@Mikusch Mikusch commented Jan 18, 2022

Currently, the server crashes when attempting to call TF2_IsHolidayActive while no map is running. Throw a native error instead.

Can be tested with this snippet:

#include <tf2>

public void OnEntityCreated(int entity, const char[] classname)
{
	PrintToServer("Is it Halloween? %d", TF2_IsHolidayActive(TFHoliday_HalloweenOrFullMoon));
}

@asherkin
Copy link
Member

Is there a more concrete thing we can check here that is actually related to the crash? E.g. is it actually that the gamerules ptr is invalid between maps and sdktools should be clearing it out?

@sirdigbot
Copy link
Contributor

Is there a more concrete thing we can check here that is actually related to the crash? E.g. is it actually that the gamerules ptr is invalid between maps and sdktools should be clearing it out?

Looking in IDA I think that the gamerules pointer doesnt get set until CWorld::Precache is called (CWorld::Precache -> InstallGameRules -> CreateGameRulesObject), which I think only happens if a map is loaded, unless I'm misunderstanding what CWorld is.

@sirdigbot
Copy link
Contributor

You should also add the errors to the docstring in tf2.inc

@KyleSanderson
Copy link
Member

Is there a stack from a Linux box or similar for this one? Asher is right if the ptr is invalid at a global level we should correct that instead.

@sapphonie
Copy link
Contributor

Is there a stack from a Linux box or similar for this one? Asher is right if the ptr is invalid at a global level we should correct that instead.

https://crash.limetech.org/ib3armhzana5

I let the server start up (on itemtest),

then did

killserver
map itemtest

and it crashed.

@peace-maker
Copy link
Member

TF2 uses the GameRulesProxy way to grab the g_pGameRules pointer instead of using the other way of a pointer to that pointer which probably gets cleared by the game on mapchange.

https://github.com/alliedmodders/sourcemod/blob/master/extensions/sdktools/vglobals.cpp#L131-L152

That s_pGameRules isn't set to nullptr on LevelShutdown, so ISDKTools::GetGamerules() returns the old value in between.
I guess the correct fix here is to set s_pGameRules to nullptr in LevelShutdown.

@Mikusch
Copy link
Contributor Author

Mikusch commented Apr 21, 2022

Thanks for the input. I'll create a new PR that fixes this issue in a more concrete way.

@Mikusch Mikusch closed this Apr 21, 2022
@Mikusch Mikusch deleted the tf-holiday-crash branch April 21, 2022 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants