Merge lp:~widelands-dev/widelands/bug1504366 into lp:widelands

Proposed by Jens Beyer
Status: Merged
Merged at revision: 7545
Proposed branch: lp:~widelands-dev/widelands/bug1504366
Merge into: lp:widelands
Diff against target: 28 lines (+5/-4)
1 file modified
src/editor/ui_menus/editor_player_menu.cc (+5/-4)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug1504366
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+273995@code.launchpad.net

Description of the change

Fix the crash, and by the way, replace the 99 as loop boundary by the MAX_PLAYERS define used everywhere else.

For me it works... but as usual, I'm not a C++ programmer yet ^^ so please check well.

To post a comment you must log in.
Revision history for this message
Jens Beyer (qcumber-some) wrote :

On a second look, maybe I was a bit too eager on the MAX_PLAYERS thing, and I could take that part back, but on the other hand, it still looks like it would never happen to be something over MAX_PLAYERS... well, you decide :-)

I tested again and don't see any issues.

I found a new issue (when 8 players are selected, the "up" button is disabled, but when you press "down", the "up" button is not enabled again). In current trunk this is not testable, as it crashes after selecting "8". If you want, I can open a new bug for that.

Revision history for this message
GunChleoc (gunchleoc) wrote :

The assert(nr_players <= 99) isn't a loop boundary, it is there to ensure that a condition is met. In debug mode, if the condition isn't met, Widelands will terminate with a message. The reason for assertions is to define certain wanted behaviour and thus help guard against regression bugs.

In this case, the assertion is there because there is some string assembly going on directly below it that relies on the number not being larger than 2 digits. Your code change is not wrong at the moment, because MAX_PLAYERS is smaller than 99, but the 99 is semantically more clear. E.g. imagine we would allow more than 99 players some day, then the string assembly code would need changing - this is is signalled by the assertion.

Good catch about the button, I have fixed it.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editor/ui_menus/editor_player_menu.cc'
2--- src/editor/ui_menus/editor_player_menu.cc 2015-09-08 07:16:17 +0000
3+++ src/editor/ui_menus/editor_player_menu.cc 2015-10-11 07:56:12 +0000
4@@ -176,12 +176,12 @@
5
6 // Get/Set (localized) tribe names
7 if (map.get_scenario_player_tribe(p) != UNDEFINED_TRIBE_NAME) {
8- m_selected_tribes[p] = map.get_scenario_player_tribe(p);
9+ m_selected_tribes[p - 1] = map.get_scenario_player_tribe(p);
10 } else {
11- m_selected_tribes[p] = m_tribenames[0];
12- map.set_scenario_player_tribe(p, m_selected_tribes[p]);
13+ m_selected_tribes[p - 1] = m_tribenames[0];
14+ map.set_scenario_player_tribe(p, m_selected_tribes[p - 1]);
15 }
16- m_plr_set_tribes_buts[p - 1]->set_title(m_tribe_descnames.find(m_selected_tribes[p])->second);
17+ m_plr_set_tribes_buts[p - 1]->set_title(m_tribe_descnames.find(m_selected_tribes[p - 1])->second);
18
19 // Set default AI and closeable to false (always default - should be changed by hand)
20 map.set_scenario_player_ai(p, "");
21@@ -248,6 +248,7 @@
22 set_starting_pos_clicked(nr_players);
23 }
24 map.set_nrplayers(nr_players);
25+ m_add_player .set_enabled(nr_players < MAX_PLAYERS);
26 m_remove_last_player.set_enabled(1 < nr_players);
27
28 update();

Subscribers

People subscribed via source and target branches

to status/vote changes: