diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp
index fc147d928..cd366ff91 100644
--- a/source/build/src/sdlayer.cpp
+++ b/source/build/src/sdlayer.cpp
@@ -1149,8 +1149,8 @@ void(*timerSetCallback(void(*callback)(void)))(void)
 static int sortmodes(const void *a_, const void *b_)
 {
 
-    auto a = (const struct validmode_t *)a_;
-    auto b = (const struct validmode_t *)b_;
+    auto a = (const struct validmode_t *)b_;
+    auto b = (const struct validmode_t *)a_;
 
     int x;
 
diff --git a/source/build/src/winlayer.cpp b/source/build/src/winlayer.cpp
index 3c14e4743..a8b262510 100644
--- a/source/build/src/winlayer.cpp
+++ b/source/build/src/winlayer.cpp
@@ -1750,8 +1750,8 @@ static int sortmodes(const void *a_, const void *b_)
 {
     int32_t x;
 
-    const struct validmode_t *a = (const struct validmode_t *)a_;
-    const struct validmode_t *b = (const struct validmode_t *)b_;
+    const struct validmode_t *a = (const struct validmode_t *)b_;
+    const struct validmode_t *b = (const struct validmode_t *)a_;
 
     if ((x = a->fs   - b->fs)   != 0) return x;
     if ((x = a->bpp  - b->bpp)  != 0) return x;