From 785fbcefdf8e2e71063f947abf307becc0bf8c26 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Thu, 15 Nov 2012 13:01:25 +0000 Subject: Fix divide-by-zero error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...  when displaying save buttons that have zero votes. diff --git a/src/interface/SaveButton.cpp b/src/interface/SaveButton.cpp index 93a22f7..eb2640b 100644 --- a/src/interface/SaveButton.cpp +++ b/src/interface/SaveButton.cpp @@ -68,19 +68,27 @@ SaveButton::SaveButton(Point position, Point size, SaveInfo * save): votesString = votes; int voteMax = std::max(save->GetVotesUp(),save->GetVotesDown()); - if (voteMax < 34) + if (voteMax) { - float ry = 33.0f/voteMax; - if (voteMax<8) - ry = ry/(8-voteMax); - voteBarHeightUp = (int)(save->GetVotesUp()*ry)-1; - voteBarHeightDown = (int)(save->GetVotesDown()*ry)-1; + if (voteMax < 34) + { + float ry = 33.0f/voteMax; + if (voteMax<8) + ry = ry/(8-voteMax); + voteBarHeightUp = (int)(save->GetVotesUp()*ry)-1; + voteBarHeightDown = (int)(save->GetVotesDown()*ry)-1; + } + else + { + float ry = voteMax/33.0f; + voteBarHeightUp = (int)(save->GetVotesUp()/ry)-1; + voteBarHeightDown = (int)(save->GetVotesDown()/ry)-1; + } } else { - float ry = voteMax/33.0f; - voteBarHeightUp = (int)(save->GetVotesUp()/ry)-1; - voteBarHeightDown = (int)(save->GetVotesDown()/ry)-1; + voteBarHeightUp = 0; + voteBarHeightDown = 0; } } } -- cgit v0.9.2-21-gd62e