View2D could potentially divide stuff by zero, giving bad matrices.
authorTon Roosendaal <ton@blender.org>
Thu, 18 Apr 2013 10:22:42 +0000 (10:22 +0000)
committerTon Roosendaal <ton@blender.org>
Thu, 18 Apr 2013 10:22:42 +0000 (10:22 +0000)
source/blender/editors/interface/view2d.c

index a7061ca0fed0bbef1f5f19eced2742414c895655..74047abb17ef714cdb57564a0ce49e923f6034da 100644 (file)
@@ -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);