mirror of https://github.com/OpenTTD/OpenTTD
Fix #9940: Print debuglevel parse errors to console when changed from console
parent
dcdc8d187c
commit
c6953f13e4
|
@ -1587,7 +1587,7 @@ DEF_CONSOLE_CMD(ConDebugLevel)
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
IConsolePrint(CC_DEFAULT, "Current debug-level: '{}'", GetDebugString());
|
IConsolePrint(CC_DEFAULT, "Current debug-level: '{}'", GetDebugString());
|
||||||
} else {
|
} else {
|
||||||
SetDebugString(argv[1]);
|
SetDebugString(argv[1], [](const char *err) { IConsolePrint(CC_ERROR, std::string(err)); });
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -159,8 +159,9 @@ void DebugPrint(const char *level, const std::string &message)
|
||||||
* For setting individual levels a string like \c "net=3,grf=6" should be used.
|
* For setting individual levels a string like \c "net=3,grf=6" should be used.
|
||||||
* If the string starts with a number, the number is used as global debugging level.
|
* If the string starts with a number, the number is used as global debugging level.
|
||||||
* @param s Text describing the wanted debugging levels.
|
* @param s Text describing the wanted debugging levels.
|
||||||
|
* @param error_func The function to call if a parse error occurs.
|
||||||
*/
|
*/
|
||||||
void SetDebugString(const char *s)
|
void SetDebugString(const char *s, void (*error_func)(const char *))
|
||||||
{
|
{
|
||||||
int v;
|
int v;
|
||||||
char *end;
|
char *end;
|
||||||
|
@ -203,7 +204,8 @@ void SetDebugString(const char *s)
|
||||||
if (p != nullptr) {
|
if (p != nullptr) {
|
||||||
*p = v;
|
*p = v;
|
||||||
} else {
|
} else {
|
||||||
ShowInfoF("Unknown debug level '%.*s'", (int)(s - t), t);
|
std::string error_string = fmt::format("Unknown debug level '{}'", std::string(t, s - t));
|
||||||
|
error_func(error_string.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ extern int _debug_random_level;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *DumpDebugFacilityNames(char *buf, char *last);
|
char *DumpDebugFacilityNames(char *buf, char *last);
|
||||||
void SetDebugString(const char *s);
|
void SetDebugString(const char *s, void (*error_func)(const char *));
|
||||||
const char *GetDebugString();
|
const char *GetDebugString();
|
||||||
|
|
||||||
/* Shorter form for passing filename and linenumber */
|
/* Shorter form for passing filename and linenumber */
|
||||||
|
|
|
@ -564,7 +564,7 @@ int openttd_main(int argc, char *argv[])
|
||||||
videodriver = "dedicated";
|
videodriver = "dedicated";
|
||||||
blitter = "null";
|
blitter = "null";
|
||||||
dedicated = true;
|
dedicated = true;
|
||||||
SetDebugString("net=4");
|
SetDebugString("net=4", ShowInfo);
|
||||||
if (mgo.opt != nullptr) {
|
if (mgo.opt != nullptr) {
|
||||||
scanner->dedicated_host = ParseFullConnectionString(mgo.opt, scanner->dedicated_port);
|
scanner->dedicated_host = ParseFullConnectionString(mgo.opt, scanner->dedicated_port);
|
||||||
}
|
}
|
||||||
|
@ -588,7 +588,7 @@ int openttd_main(int argc, char *argv[])
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
CreateConsole();
|
CreateConsole();
|
||||||
#endif
|
#endif
|
||||||
if (mgo.opt != nullptr) SetDebugString(mgo.opt);
|
if (mgo.opt != nullptr) SetDebugString(mgo.opt, ShowInfo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'e': _switch_mode = (_switch_mode == SM_LOAD_GAME || _switch_mode == SM_LOAD_SCENARIO ? SM_LOAD_SCENARIO : SM_EDITOR); break;
|
case 'e': _switch_mode = (_switch_mode == SM_LOAD_GAME || _switch_mode == SM_LOAD_SCENARIO ? SM_LOAD_SCENARIO : SM_EDITOR); break;
|
||||||
|
|
Loading…
Reference in New Issue