We-the-People-civ4col-mod / Mod

This is the repository where the mod resides.
90 stars 37 forks source link

Make asserts reveal caller or call stack #961

Open Nightinggale opened 11 months ago

Nightinggale commented 11 months ago

Assert Failed

File: DLLSources.\CvGame.cpp Line: 7061 Func: CvGame::setFatherTeam Expression: eTeam >= 0 Message:

I just got feedback that this triggered. Sadly it doesn't say what called CvGame::setFatherTeam with an invalid eTeam. This makes me wonder if we can get assert messages to reveal the call stack, or at least the top part of it. Searching online located StackWalker, which might be able to get the job done, but it mentions having dropped some backward compatibility, so maybe not with our setup.

I started looking at FAssert.h/cpp and I wonder if we can mod that one to do what we want.

void test(const char* file = __FILE__, unsigned int line = __LINE__, const char* func = NULL)

This reveals where this function is declared, so not really useful.

test(__FILE__, __LINE__, __FUNCTION__);

This one provides the information to the test function where it is called from. This got me thinking. Can we make an easy to use and maintain setup where we exploit this?

If we make a struct called AssertInfo, which we set up with those 3 variables using a define, say ASSERT_INFO. We can then add AssertInfo as an argument. Easy way to add the information from the caller and we will get a compile error if the struct is missing in arguments, hence it should be fairly easy to set up.

Next step would be to add two more assert defines, which should do the task of FAssert and FAssertMsg, but with the struct added as an argument. This way when FAssertDlg is called, rather than using __FILE__, __LINE__, __FUNCTION__, it should use the struct data.

Naturally we can take this one step further and add another dialogue, which reports both current location (current code) and caller, but would require studying FAssert.cpp internals.