Skip to content

Commit

Permalink
Merge pull request #988 from robotology/fix986
Browse files Browse the repository at this point in the history
Add workaround for using iDynTree.Visualizer on Windows with SDL 1.2.52
  • Loading branch information
traversaro authored May 9, 2022
2 parents 7be8e22 + bc09651 commit fcb7cb2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased Major]

## [5.2.0] - 2022-05-09

### Added
- Added `DHChain` class to the bindings.
- Added `DHChain` class to the bindings (https://github.com/robotology/idyntree/pull/984).

### Fixed
- Fixed problems of running two (or more) times the `iDynTree.Visualizer` class on Windows when using SDL >= 1.2.52 (https://github.com/robotology/idyntree/pull/988, https://github.com/robotology/idyntree/pull/986).

## [5.1.0] - 2022-02-25

Expand Down
27 changes: 27 additions & 0 deletions src/visualization/src/Visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
#include "TexturesHandler.h"
#include "CameraAnimator.h"
#include "Label.h"

#if defined(_WIN32) && defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
// Required by SetEnvironmentVariableA, _putenv is not unsetting
// correctly the variables
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

#endif

#include "DummyImplementations.h"
Expand Down Expand Up @@ -285,8 +294,26 @@ bool Visualizer::init(const VisualizerOptions &visualizerOptions)
}

pimpl->m_irrDevice = 0;

// The Irrlicht SDL device overwrites the value of the SDL_VIDEODRIVER
// environment variable, and this prevents the driver to work correctly.
// For this reason, we save the value before the irr::createDeviceEx call,
// and we restore it (or we unset it) after call
// Workaround for https://github.com/robotology/idyntree/issues/986
#if defined(_WIN32) && defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
const char * SDL_VIDEODRIVER_value = NULL;
if (irrDevParams.DeviceType == irr::EIDT_SDL) {
SDL_VIDEODRIVER_value = std::getenv("SDL_VIDEODRIVER");
}
#endif

pimpl->m_irrDevice = irr::createDeviceEx(irrDevParams);

#if defined(_WIN32) && defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
if (irrDevParams.DeviceType == irr::EIDT_SDL) {
SetEnvironmentVariableA("SDL_VIDEODRIVER", SDL_VIDEODRIVER_value);
}
#endif

if (pimpl->m_irrDevice == 0)
{
Expand Down
6 changes: 6 additions & 0 deletions src/visualization/tests/VisualizerUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ void checkVizLoading(const iDynTree::Model & model)
label.setSize(1.0);
label.setPosition(iDynTree::Position(-1.0, -1.0, 0.3));

// Check if run is returning true
// Regression test for https://github.com/robotology/idyntree/issues/986
ok = viz.run();
ASSERT_IS_TRUE(ok);


for(int i=0; i < 5; i++)
{
viz.draw();
Expand Down

0 comments on commit fcb7cb2

Please sign in to comment.