[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60334] trunk/blender: Fix related to #36319: restore SDL_VIDEODRIVER=dummy environment variable, it

Brecht Van Lommel brechtvanlommel at pandora.be
Mon Sep 23 16:48:28 CEST 2013


Revision: 60334
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60334
Author:   blendix
Date:     2013-09-23 14:48:28 +0000 (Mon, 23 Sep 2013)
Log Message:
-----------
Fix related to #36319: restore SDL_VIDEODRIVER=dummy environment variable, it
seems that somehow not having this is causing keyboard events to be caught by
SDL. This was removed because it broke addons that could use SDL, now set the
environment variable only temporary during SDL initialization.

This may have been causing issues with keyboard events getting missed in the
game engine, but I couldn't confirm the issue here.

Modified Paths:
--------------
    trunk/blender/intern/utfconv/utf_winfunc.c
    trunk/blender/source/blender/blenlib/intern/path_util.c
    trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp

Modified: trunk/blender/intern/utfconv/utf_winfunc.c
===================================================================
--- trunk/blender/intern/utfconv/utf_winfunc.c	2013-09-23 13:58:46 UTC (rev 60333)
+++ trunk/blender/intern/utfconv/utf_winfunc.c	2013-09-23 14:48:28 UTC (rev 60334)
@@ -166,12 +166,23 @@
 {
 	int r = -1;
 	UTF16_ENCODE(name);
-	UTF16_ENCODE(value);
 
-	if (name_16 && value_16) {
-		r = (SetEnvironmentVariableW(name_16,value_16)!= 0) ? 0 : -1;
+	if (value) {
+		/* set */
+		UTF16_ENCODE(value);
+
+		if (name_16 && value_16) {
+			r = (SetEnvironmentVariableW(name_16,value_16)!= 0) ? 0 : -1;
+		}
+		UTF16_UN_ENCODE(value);
 	}
-	UTF16_UN_ENCODE(value);
+	else {
+		/* clear */
+		if (name_16) {
+			r = (SetEnvironmentVariableW(name_16,NULL)!= 0) ? 0 : -1;
+		}
+	}
+
 	UTF16_UN_ENCODE(name);
 
 	return r;

Modified: trunk/blender/source/blender/blenlib/intern/path_util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/path_util.c	2013-09-23 13:58:46 UTC (rev 60333)
+++ trunk/blender/source/blender/blenlib/intern/path_util.c	2013-09-23 14:48:28 UTC (rev 60334)
@@ -1324,15 +1324,20 @@
 #endif
 
 /**
- * Sets the specified environment variable to the specified value.
+ * Sets the specified environment variable to the specified value,
+ * and clears it if val == NULL.
  */
 void BLI_setenv(const char *env, const char *val)
 {
 	/* free windows */
 #if (defined(WIN32) || defined(WIN64)) && defined(FREE_WINDOWS)
-	char *envstr = MEM_mallocN(sizeof(char) * (strlen(env) + strlen(val) + 2), "envstr"); /* one for = another for \0 */
+	char *envstr;
 
-	sprintf(envstr, "%s=%s", env, val);
+	if (val)
+		envstr = BLI_sprintfN("%s=%s", env, val);
+	else
+		envstr = BLI_sprintfN("%s=", env);
+
 	putenv(envstr);
 	MEM_freeN(envstr);
 
@@ -1343,7 +1348,10 @@
 
 #else
 	/* linux/osx/bsd */
-	setenv(env, val, 1);
+	if (val)
+		setenv(env, val, 1);
+	else
+		unsetenv(env);
 #endif
 }
 

Modified: trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp	2013-09-23 13:58:46 UTC (rev 60333)
+++ trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp	2013-09-23 14:48:28 UTC (rev 60334)
@@ -39,6 +39,8 @@
 #include "SCA_Joystick.h"
 #include "SCA_JoystickPrivate.h"
 
+#include "BLI_path_util.h"
+
 SCA_Joystick::SCA_Joystick(short int index)
 	:
 	m_joyindex(index),
@@ -88,14 +90,26 @@
 	if (m_refCount == 0) 
 	{
 		int i;
+
 		/* The video subsystem is required for joystick input to work. However,
-		 * when GHOST is running under SDL, video is initialized elsewhere.
-		 * Do this once only. */
+		 * when GHOST is running under SDL, video is initialized elsewhere. We
+		 * also need to set the videodriver to dummy, and do it here to avoid
+		 * interfering with addons that may use SDL too.
+		 *
+		 * We also init SDL once only. */
 #  ifdef WITH_GHOST_SDL
-		if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1 ) {
+		int success = (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1 );
 #  else
-		if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO) == -1 ) {
+		/* set and restore environment variable */
+		char *videodriver = getenv("SDL_VIDEODRIVER");
+		BLI_setenv("SDL_VIDEODRIVER", "dummy");
+
+		int success = (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO) != -1 );
+
+		BLI_setenv("SDL_VIDEODRIVER", videodriver);
 #  endif
+
+		if (!success) {
 			JOYSTICK_ECHO("Error-Initializing-SDL: " << SDL_GetError());
 			return NULL;
 		}




More information about the Bf-blender-cvs mailing list