Merge lp:~widelands-dev/widelands/bug-1422452 into lp:widelands

Proposed by TiborB
Status: Merged
Merged at revision: 7413
Proposed branch: lp:~widelands-dev/widelands/bug-1422452
Merge into: lp:widelands
Diff against target: 12 lines (+1/-1)
1 file modified
src/logic/playercommand.cc (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1422452
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+250232@code.launchpad.net

Description of the change

So many hours of work and so tiny fix. :(

There is a question in a diff....

I have not tested the attached (to the bug) file, but I have own replay files that were broken before and "worked" after the fix

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

I think something like:

ScoutingDirection unsign = static_cast<ScoutingDirection>(des.unsigned_8());

should work. The compiler will tell you if I'm wrong.

Revision history for this message
TiborB (tiborb95) wrote :

then there would be only one line:

scouting_direction = static_cast<ScoutingDirection>(des.unsigned_8());

compiler says it is OK, but this kind of bugs is extremly hard to trace, so this must be 100% reliable

Revision history for this message
SirVer (sirver) wrote :

The one liner is fine.

An enum class is internally always represented as an (unsigned) int, but since enum class are guaranteed to be typesafe you must explicitly tell the compiler to interpret the integer as another type, ergo the static_cast is needed.

Good catch! Since when was this broken?

Revision history for this message
TiborB (tiborb95) wrote :

"An enum class is internally always represented as an (unsigned) int" - I presumed it is this way but was not sure.

The bug was introduced in seafaring-ai branch....

Revision history for this message
GunChleoc (gunchleoc) wrote :

Using enum classes instead of enums does take some getting used to in these cases. LGTM, thanks for hunting!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/logic/playercommand.cc'
2--- src/logic/playercommand.cc 2015-02-13 18:48:37 +0000
3+++ src/logic/playercommand.cc 2015-02-19 07:59:28 +0000
4@@ -910,7 +910,7 @@
5 PlayerCommand (0, des.unsigned_8())
6 {
7 serial = des.unsigned_32();
8- scouting_direction = ScoutingDirection::kClockwise;
9+ scouting_direction = static_cast<ScoutingDirection>(des.unsigned_8());
10 }
11
12 void CmdShipExploreIsland::execute (Game & game)

Subscribers

People subscribed via source and target branches

to status/vote changes: