← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1818494-no-negative-zoom into lp:widelands


GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1818494-no-negative-zoom into lp:widelands.

Commit message:
Safeguards in draw_terrain to prevent negative zoom.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1818494 in widelands: "Crash on "Reset zoom" bzr9005-201903031251 (Release)"

For more details, see:

This is our last remaining known crash, so I'd like this for Build 20. If we can get it in by the weekend, we'll still do the Release Candidate on Monday.

The branch has already been tested and only needs a code review.
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1818494-no-negative-zoom into lp:widelands.
=== modified file 'src/wui/mapview.cc'
--- src/wui/mapview.cc	2019-03-31 15:37:35 +0000
+++ src/wui/mapview.cc	2019-04-18 06:18:35 +0000
@@ -352,10 +352,12 @@
 		// Linearly interpolate between the next and the last.
-		const float t = (now - plan[0].t) / static_cast<float>(plan[1].t - plan[0].t);
+		// Using std::max as a workaround for https://bugs.launchpad.net/widelands/+bug/1818494
+		const float t = (std::max(1U, now - plan[0].t)) / static_cast<float>(std::max(1U, plan[1].t - plan[0].t));
 		const View new_view = {
 		   mix(t, plan[0].view.viewpoint, plan[1].view.viewpoint),
-		   mix(t, plan[0].view.zoom, plan[1].view.zoom),
+			// Using math::clamp as a workaround for https://bugs.launchpad.net/widelands/+bug/1818494
+		   math::clamp(mix(t, plan[0].view.zoom, plan[1].view.zoom), 1.f / kMaxZoom, kMaxZoom)
 		set_view(new_view, Transition::Jump);

Follow ups