From bde6a939e62514be4df552d41fbdca9d6aa873af Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Thu, 18 Apr 2013 10:22:42 +0000 Subject: [PATCH] View2D could potentially divide stuff by zero, giving bad matrices. --- source/blender/editors/interface/view2d.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index a7061ca0fed..74047abb17e 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -1022,15 +1022,19 @@ static void view2d_map_cur_using_mask(View2D *v2d, rctf *curmasked) void UI_view2d_view_ortho(View2D *v2d) { rctf curmasked; - float xofs, yofs; + int sizex = BLI_rcti_size_x(&v2d->mask); + int sizey = BLI_rcti_size_y(&v2d->mask); + float xofs = 0.0f, yofs = 0.0f; /* pixel offsets (-GLA_PIXEL_OFS) are needed to get 1:1 correspondence with pixels for smooth UI drawing, * but only applied where requested */ /* XXX brecht: instead of zero at least use a tiny offset, otherwise * pixel rounding is effectively random due to float inaccuracy */ - xofs = 0.001f * BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask); - yofs = 0.001f * BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask); + if (sizex > 0) + xofs = 0.001f * BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask); + if (sizey > 0) + yofs = 0.001f * BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask); /* apply mask-based adjustments to cur rect (due to scrollers), to eliminate scaling artifacts */ view2d_map_cur_using_mask(v2d, &curmasked);