Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenlib/intern/path_util.c16
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp22
2 files changed, 30 insertions, 8 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 68e0f2c4026..d323098827b 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1324,15 +1324,20 @@ const char *BLI_get_folder_version(const int id, const int ver, const bool do_ch
#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;
+
+ if (val)
+ envstr = BLI_sprintfN("%s=%s", env, val);
+ else
+ envstr = BLI_sprintfN("%s=", env);
- sprintf(envstr, "%s=%s", env, val);
putenv(envstr);
MEM_freeN(envstr);
@@ -1343,7 +1348,10 @@ void BLI_setenv(const char *env, const char *val)
#else
/* linux/osx/bsd */
- setenv(env, val, 1);
+ if (val)
+ setenv(env, val, 1);
+ else
+ unsetenv(env);
#endif
}
diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
index 64ab0af4d26..793ce6a7b83 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
+++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
@@ -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 @@ SCA_Joystick *SCA_Joystick::GetInstance( short int joyindex )
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;
}