← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1797792-shading-language-version-comparison into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1797792-shading-language-version-comparison into lp:widelands.

Commit message:
Fix shading language version detection for system locales that don't use . as a decimal separator

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1797792-shading-language-version-comparison/+merge/356699
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1797792-shading-language-version-comparison into lp:widelands.
=== modified file 'src/graphic/gl/initialize.cc'
--- src/graphic/gl/initialize.cc	2018-10-15 05:26:10 +0000
+++ src/graphic/gl/initialize.cc	2018-10-15 06:50:28 +0000
@@ -23,6 +23,7 @@
 #include <cstdlib>
 
 #include <SDL.h>
+#include <boost/algorithm/string.hpp>
 
 #include "base/macros.h"
 #include "graphic/gl/utils.h"
@@ -178,11 +179,26 @@
 	glGetIntegerv(GL_MAX_TEXTURE_SIZE, max_texture_size);
 	log("Graphics: OpenGL: Max texture size: %u\n", *max_texture_size);
 
-	// TODO(GunChleoc): Localize the on-screen error messages
-	// Exit if we can't detect the shading language version
 	const char* const shading_language_version_string =
 	   reinterpret_cast<const char*>(glGetString(GL_SHADING_LANGUAGE_VERSION));
-	if (strcmp(shading_language_version_string, "(null)") == 0) {
+	log("Graphics: OpenGL: ShadingLanguage: \"%s\"\n", shading_language_version_string);
+
+	std::vector<std::string> shading_language_version_vector;
+	boost::split(shading_language_version_vector, shading_language_version_string, boost::is_any_of("."));
+	if (shading_language_version_vector.size() >= 2) {
+		// The shading language version has been detected properly. Exit if the shading language version is too old.
+		const int major_shading_language_version = atoi(shading_language_version_vector.front().c_str());
+		const int minor_shading_language_version = atoi(shading_language_version_vector.at(1).c_str());
+		if (major_shading_language_version < 1 || (major_shading_language_version == 1 && minor_shading_language_version < 20)) {
+			log("ERROR: Shading language version is too old!\n");
+			SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OpenGL Error",
+									 "Widelands won’t work because your graphics driver is too old.\nThe "
+									 "Shading language needs to be version 1.20 or newer.",
+									 NULL);
+			exit(1);
+		}
+	} else {
+		// Exit because we couldn't detect the shading language version, so there must be a problem communicating with the graphics adapter.
 		log("ERROR: Unable to detect the shading language version!\n");
 		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OpenGL Error",
 		                         "Widelands won't work because we were unable to detect the shading "
@@ -192,23 +208,6 @@
 		exit(1);
 	}
 
-	log("Graphics: OpenGL: ShadingLanguage: \"%s\"", shading_language_version_string);
-
-	// Exit if the shading language version is too old
-	/* NOCOM(GunChleoc): Commenting this out as a hotfix for https://bugs.launchpad.net/widelands/+bug/1797792
-	const double shading_language_version = atof(shading_language_version_string);
-	log(" (%.2f)\n", shading_language_version);
-
-	if (shading_language_version < 1.20) {
-		log("ERROR: Shading language version is too old!\n");
-		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OpenGL Error",
-		                         "Widelands won’t work because your graphics driver is too old.\nThe "
-		                         "Shading language needs to be version 1.20 or newer.",
-		                         NULL);
-		exit(1);
-	}
-	*/
-
 	glDrawBuffer(GL_BACK);
 
 	glDisable(GL_DEPTH_TEST);


Follow ups