News:

Do you need help?
Simutrans Wiki Manual can help you to play and extend Simutrans. In 9 languages.

Ignore undefined menubar tools by "if", instead of "assert"

Started by z9999, February 24, 2009, 06:23:15 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

z9999

In simumenu.cc, there are 3 assert to check tool_count.
But this don't allow to share menuconf file with different patched versions like underfround patches.
This is very annoying for testers and players.


assert(toolnr<GENERAL_TOOL_COUNT);

assert(toolnr<SIMPLE_TOOL_COUNT);

assert(toolnr<DIALOGE_TOOL_COUNT);


I think ignoring undefined tools using "if" syntax instead of assert is happy for testers and players. So, we can share the same menuconf with them.

Is this possible to change this ?


if (toolnr<GENERAL_TOOL_COUNT) {
}

if (toolnr<SIMPLE_TOOL_COUNT) {
}

if (toolnr<DIALOGE_TOOL_COUNT) {
}


prissi

But then, a normal player using a wrong version may run into troubles, especially if those tools are then used for other functions. (Such patched versions might also have other entries in simuconf.tab, which are interpreted differently.)

I added them actually to help me to find errors when *I* accidently used too high number ... I am not against, but unsure, if in the long run for unexperienced user this would mean more trouble.

EDIT: put the if in, but print error message.

z9999

Thank you for considering this.
But unfortunately it causes to crash.

A patch attached.


Index: simmenu.cc
===================================================================
--- simmenu.cc (r2344)
+++ simmenu.cc (copy)
@@ -553,7 +553,7 @@
}
}
else {
- dbg->error( "werkzeug_t::init_menu()", "When parsing menuconf.tab: No simple tool %i defined (max %i)!", toolnr, GENERAL_TOOL_COUNT );
+ dbg->error( "werkzeug_t::init_menu()", "When parsing menuconf.tab: No simple tool %i defined (max %i)!", toolnr, SIMPLE_TOOL_COUNT );
}
}
else if(strstr(toolname,"dialog_tool[")) {
@@ -578,7 +578,7 @@
}
}
else {
- dbg->error( "werkzeug_t::init_menu()", "When parsing menuconf.tab: No dialog tool %i defined (max %i)!", toolnr, GENERAL_TOOL_COUNT );
+ dbg->error( "werkzeug_t::init_menu()", "When parsing menuconf.tab: No dialog tool %i defined (max %i)!", toolnr, DIALOGE_TOOL_COUNT );
}
}
else if(strstr(toolname,"toolbar[")) {
@@ -612,7 +612,9 @@
addtool->default_param = strdup(toolname);
addtool->command_key = 1;
}
- toolbar_tool[i]->append(addtool);
+ if(addtool) {
+ toolbar_tool[i]->append(addtool);
+ }
}
}
// sort characters