]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
add bounds check to menu function to query resolutions
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 5 Aug 2009 13:04:50 +0000 (13:04 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 5 Aug 2009 13:04:50 +0000 (13:04 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9090 d7cf8633-e32d-0410-b094-e92efae38249

mvm_cmds.c
vid_shared.c

index f5976ac68bf100f3aa44022a43162b58b5dd00a1..876deaec6578b6817c17440a3b7bb98dbc714656 100644 (file)
@@ -227,10 +227,18 @@ void VM_M_getresolution(void)
 
        nr = (int)PRVM_G_FLOAT(OFS_PARM0);
 
-       // FIXME bounds check
-       PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr].width;
-       PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr].height;
-       PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
+       if(nr < 0 || nr >= video_resolutions_count)
+       {
+               PRVM_G_VECTOR(OFS_RETURN)[0] = 0;
+               PRVM_G_VECTOR(OFS_RETURN)[1] = 0;
+               PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
+       }
+       else
+       {
+               PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr].width;
+               PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr].height;
+               PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
+       }
 }
 
 /*
index daf9b0456a0dc9625c7ba4c4f446c458b4743fe9..ce164b4d48b511a32b5ee82cf387624f32f6e7c9 100644 (file)
@@ -1267,7 +1267,7 @@ void VID_Start(void)
        VID_OpenSystems();
 }
 
-int VID_SortModes_Compare(void *a_, void *b_)
+int VID_SortModes_Compare(const void *a_, const void *b_)
 {
        vid_mode_t *a = (vid_mode_t *) a_;
        vid_mode_t *b = (vid_mode_t *) b_;
@@ -1297,26 +1297,31 @@ size_t VID_SortModes(vid_mode_t *modes, size_t count, qboolean usebpp, qboolean
 {
        size_t i;
        if(count == 0)
-               return;
+               return 0;
        // 1. sort them
        qsort(modes, count, sizeof(*modes), VID_SortModes_Compare);
        // 2. remove duplicates
-       for(i = 1; i < count; ++i)
+       for(i = 0; i < count; ++i)
        {
-               if(modes[i].width != modes[i-1].width)
-                       continue;
-               if(modes[i].height != modes[i-1].height)
-                       continue;
-               if(userefreshrate)
-                       if(modes[i].refreshrate != modes[i-1].refreshrate)
+               if(modes[i].width && modes[i].height)
+               {
+                       if(i == 0)
                                continue;
-               if(usebpp)
-                       if(modes[i].bpp != modes[i-1].bpp)
+                       if(modes[i].width != modes[i-1].width)
                                continue;
-               if(useaspect)
-                       if(modes[i].pixelheight_num * modes[i-1].pixelheight_denom != modes[i].pixelheight_denom * modes[i-1].pixelheight_num)
+                       if(modes[i].height != modes[i-1].height)
                                continue;
-               // a dupe!
+                       if(userefreshrate)
+                               if(modes[i].refreshrate != modes[i-1].refreshrate)
+                                       continue;
+                       if(usebpp)
+                               if(modes[i].bpp != modes[i-1].bpp)
+                                       continue;
+                       if(useaspect)
+                               if(modes[i].pixelheight_num * modes[i-1].pixelheight_denom != modes[i].pixelheight_denom * modes[i-1].pixelheight_num)
+                                       continue;
+               }
+               // a dupe, or a bogus mode!
                if(i < count-1)
                        memmove(&modes[i], &modes[i+1], sizeof(*modes) * (count-1 - i));
                --i; // check this index again, as mode i+1 is now here