ftp://ftp.krokus.ru/pub/OpenBSD/distfiles/xscreensaver-5.01.tar.gz
[xscreensaver] / hacks / crystal.c
index be090c2efc0a8fa076da55596a8e3116d9468a5d..5ceb91f6f2a2f29d2b1a862c8fe2703fe3d14f9e 100644 (file)
@@ -92,6 +92,9 @@ static const char sccsid[] = "@(#)crystal.c   4.12 98/09/10 xlockmore";
 #define DEF_MAXSIZE "False"
 #define DEF_CYCLE "True"
 
+#undef NRAND
+#define NRAND(n)           ( (n) ? (int) (LRAND() % (n)) : 0)
+
 #define min(a,b) ((a) <= (b) ? (a) : (b))
 
 static int  nx, ny;
@@ -980,9 +983,12 @@ init_crystal(ModeInfo * mi)
                        cryst->offset_w = (int) (cryst->b * 0.5);
                }
        } else {
+               int max_repeat = 10;
                cryst->offset_w = -1;
-               while (cryst->offset_w < 4 || (int) (cryst->offset_w - cryst->b *
-                                   sin((cryst->gamma - 90) * PI_RAD)) < 4) {
+               while (max_repeat-- && 
+                 (cryst->offset_w < 4 || (int) (cryst->offset_w - cryst->b *
+                                   sin((cryst->gamma - 90) * PI_RAD)) < 4)
+                          ) {
                        cryst->b = NRAND((int) (cryst->win_height / (cos((cryst->gamma - 90) *
                                            PI_RAD))) - cell_min) + cell_min;
                        if (cryst->planegroup > 8)