Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2016-02-01 07:05:45 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-02-01 07:23:30 +0300
commit25f5fdc070fb295003e323ce0db9bee49d64f0df (patch)
tree560d1bd87245d27a57c39fcc07b44fede55c0b5b /source/blender/editors/interface/view2d.c
parent526dbd808914bb5303ad5e5a4efebfb685e75025 (diff)
View2D: avoid divide-by-zero
Diffstat (limited to 'source/blender/editors/interface/view2d.c')
-rw-r--r--source/blender/editors/interface/view2d.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index fd991660110..ef001f42a3b 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -1221,7 +1221,7 @@ View2DGrid *UI_view2d_grid_calc(
{
View2DGrid *grid;
- float space, pixels, seconddiv;
+ float space, seconddiv;
/* check that there are at least some workable args */
if (ELEM(V2D_ARG_DUMMY, xunits, xclamp) && ELEM(V2D_ARG_DUMMY, yunits, yclamp))
@@ -1241,32 +1241,37 @@ View2DGrid *UI_view2d_grid_calc(
/* calculate x-axis grid scale (only if both args are valid) */
if (ELEM(V2D_ARG_DUMMY, xunits, xclamp) == 0) {
space = BLI_rctf_size_x(&v2d->cur);
- pixels = (float)BLI_rcti_size_x(&v2d->mask);
-
- if (pixels != 0.0f) {
- grid->dx = (U.v2d_min_gridsize * UI_DPI_FAC * space) / (seconddiv * pixels);
- step_to_grid(&grid->dx, &grid->powerx, xunits);
- grid->dx *= seconddiv;
+
+ if (space != 0.0f) {
+ const float pixels = (float)BLI_rcti_size_x(&v2d->mask);
+ if (pixels != 0.0f) {
+ grid->dx = (U.v2d_min_gridsize * UI_DPI_FAC * space) / (seconddiv * pixels);
+ step_to_grid(&grid->dx, &grid->powerx, xunits);
+ grid->dx *= seconddiv;
+ }
}
if (xclamp == V2D_GRID_CLAMP) {
- if (grid->dx < 0.1f) grid->dx = 0.1f;
+ CLAMP_MIN(grid->dx, 0.1f);
+ CLAMP_MIN(grid->powerx, 0);
grid->powerx -= 2;
- if (grid->powerx < -2) grid->powerx = -2;
}
}
/* calculate y-axis grid scale (only if both args are valid) */
if (ELEM(V2D_ARG_DUMMY, yunits, yclamp) == 0) {
space = BLI_rctf_size_y(&v2d->cur);
- pixels = (float)winy;
-
- grid->dy = U.v2d_min_gridsize * UI_DPI_FAC * space / pixels;
- step_to_grid(&grid->dy, &grid->powery, yunits);
-
+ if (space != 0.0f) {
+ const float pixels = (float)winy;
+ if (pixels != 0.0f) {
+ grid->dy = U.v2d_min_gridsize * UI_DPI_FAC * space / pixels;
+ step_to_grid(&grid->dy, &grid->powery, yunits);
+ }
+ }
+
if (yclamp == V2D_GRID_CLAMP) {
- if (grid->dy < 1.0f) grid->dy = 1.0f;
- if (grid->powery < 1) grid->powery = 1;
+ CLAMP_MIN(grid->dy, 1.0f);
+ CLAMP_MIN(grid->powery, 1);
}
}