Merge lp:~widelands-dev/widelands/bug-1795976-port-attack-crash into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8878
Proposed branch: lp:~widelands-dev/widelands/bug-1795976-port-attack-crash
Merge into: lp:widelands
Diff against target: 49 lines (+9/-10)
1 file modified
src/ai/defaultai.cc (+9/-10)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1795976-port-attack-crash
Reviewer Review Type Date Requested Status
GunChleoc Approve
TiborB Approve
Review via email: mp+356454@code.launchpad.net

Commit message

Fix endless loop in DefaultAI::dispensable_road_test

To post a comment you must log in.
Revision history for this message
TiborB (tiborb95) wrote :

Code looks good to me

review: Approve
Revision history for this message
TiborB (tiborb95) wrote :

now when I look more deep into the code I think the function has a logical error there, I will investigate and let you know..

Revision history for this message
GunChleoc (gunchleoc) wrote :

Do you want to take up this branch and improve it before we merge?

I'll hold off merging for now.

Revision history for this message
TiborB (tiborb95) wrote :

OK, good idea... thanks

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4110. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/440029552.
Appveyor build 3905. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1795976_port_attack_crash-3905.

Revision history for this message
TiborB (tiborb95) wrote :

@Gun, can you look at the diff?

I removed your std::set and just look into vector instead. Usually it is <=5 items, so no big overhead

I tested with bug's savegame and with a random game from scratch...

Revision history for this message
GunChleoc (gunchleoc) wrote :

Tested, bug is fixed :)

@bunnybot merge

review: Approve
Revision history for this message
kaputtnik (franku) wrote :

Great, thanks :)

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks yourself for the savegame!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ai/defaultai.cc'
2--- src/ai/defaultai.cc 2018-09-29 14:35:29 +0000
3+++ src/ai/defaultai.cc 2018-10-12 10:03:30 +0000
4@@ -3584,19 +3584,18 @@
5 Flag& roadstartflag = road.get_flag(Road::FlagStart);
6 Flag& roadendflag = road.get_flag(Road::FlagEnd);
7
8- // Collecting full path (from crossing/building to another crossing/building)
9+ // Calculating full road (from crossing/building to another crossing/building),
10+ // this means we calculate vector of all flags of the "full road"
11 std::vector<Widelands::Flag*> full_road;
12 full_road.push_back(&roadstartflag);
13 full_road.push_back(&roadendflag);
14
15- // Making sure it starts with proper flag
16 uint16_t road_length = road.get_path().get_nsteps();
17
18 for (int j = 0; j < 2; ++j) {
19 bool new_road_found = true;
20 while (new_road_found && full_road.back()->nr_of_roads() <= 2 &&
21 full_road.back()->get_building() == nullptr) {
22- const size_t full_road_size = full_road.size();
23 new_road_found = false;
24 for (uint8_t i = 1; i <= 6; ++i) {
25 Road* const near_road = full_road.back()->get_road(i);
26@@ -3613,16 +3612,16 @@
27 other_end = &near_road->get_flag(Road::FlagStart);
28 }
29
30- if (other_end->get_position() == full_road[full_road_size - 2]->get_position()) {
31- continue;
32+ // Have we already the end of road in our full_road?
33+ if (std::find(full_road.begin(), full_road.end(), other_end) == full_road.end()) {
34+ full_road.push_back(other_end);
35+ road_length += near_road->get_path().get_nsteps();
36+ new_road_found = true;
37+ break;
38 }
39- full_road.push_back(other_end);
40- road_length += near_road->get_path().get_nsteps();
41- new_road_found = true;
42- break;
43 }
44 }
45- // we walked to one end, now let revert the concent of full_road and repeat in opposite
46+ // we walked to one end, now let revert the content of full_road and repeat in opposite
47 // direction
48 std::reverse(full_road.begin(), full_road.end());
49 }

Subscribers

People subscribed via source and target branches

to status/vote changes: