NOSALRO / robot_dart

RobotDART: a versatile robot simulator for robotics and machine learning researchers
https://nosalro.github.io/robot_dart/
BSD 2-Clause "Simplified" License
45 stars 25 forks source link

Saving images corrupted on MacOS Windowed mode #209

Closed c-joly closed 1 week ago

c-joly commented 3 months ago

Hi @costashatz , here is an issue linked to the JOSS review https://github.com/openjournals/joss-reviews/issues/6771.

I figured out that the png export generates corrupted image (almost empty if I open the binary file). However, it works well in windowless mode... I adapted the hello_world.py example to provide a minimal test:

Does not work

# @HELLO_WORLD_INCLUDE_PYTHON@
import RobotDART as rd
# @HELLO_WORLD_INCLUDE_PYTHON_END@

# @HELLO_WORLD_ROBOT_CREATION_PYTHON@
robot = rd.Robot("pexod.urdf");
# @HELLO_WORLD_ROBOT_CREATION_PYTHON_END@

# @HELLO_WORLD_ROBOT_PLACING_PYTHON@
robot.set_base_pose([0., 0., 0., 0., 0., 0.2])
# @HELLO_WORLD_ROBOT_PLACING_PYTHON_END@

# @HELLO_WORLD_ROBOT_SIMU_PYTHON@
simu = rd.RobotDARTSimu(0.001); # dt=0.001, 1KHz simulation
simu.add_floor();
simu.add_robot(robot);
# @HELLO_WORLD_ROBOT_SIMU_PYTHON_END@

# @HELLO_WORLD_ROBOT_GRAPHIC_PYTHON@
configuration = rd.gui.GraphicsConfiguration()
configuration.shadowed = False # Prevent segfault shadow
graphics = rd.gui.Graphics(configuration)
simu.set_graphics(graphics)
graphics.look_at([0.5, 3., 0.75], [0.5, 0., 0.2])
# @HELLO_WORLD_ROBOT_GRAPHIC_PYTHON_END@
# @HELLO_WORLD_ROBOT_RUN_PYTHON@
simu.run(10.)
img = graphics.image()
rd.gui.save_png_image('Test.png', img)
# @HELLO_WORLD_ROBOT_RUN_PYTHON_END@

Works well

# @HELLO_WORLD_INCLUDE_PYTHON@
import RobotDART as rd
# @HELLO_WORLD_INCLUDE_PYTHON_END@

# @HELLO_WORLD_ROBOT_CREATION_PYTHON@
robot = rd.Robot("pexod.urdf");
# @HELLO_WORLD_ROBOT_CREATION_PYTHON_END@

# @HELLO_WORLD_ROBOT_PLACING_PYTHON@
robot.set_base_pose([0., 0., 0., 0., 0., 0.2])
# @HELLO_WORLD_ROBOT_PLACING_PYTHON_END@

# @HELLO_WORLD_ROBOT_SIMU_PYTHON@
simu = rd.RobotDARTSimu(0.001); # dt=0.001, 1KHz simulation
simu.add_floor();
simu.add_robot(robot);
# @HELLO_WORLD_ROBOT_SIMU_PYTHON_END@

# @HELLO_WORLD_ROBOT_GRAPHIC_PYTHON@
graphics = rd.gui.WindowlessGraphics()
simu.set_graphics(graphics)
graphics.look_at([0.5, 3., 0.75], [0.5, 0., 0.2])
# @HELLO_WORLD_ROBOT_GRAPHIC_PYTHON_END@
# @HELLO_WORLD_ROBOT_RUN_PYTHON@
simu.run(10.)
img = graphics.image()
rd.gui.save_png_image('Test.png', img)
# @HELLO_WORLD_ROBOT_RUN_PYTHON_END@
costashatz commented 1 week ago

This should be fixed by https://github.com/NOSALRO/robot_dart/commit/9412aa2936e6f331431708d2c4d04ee8af635463. I basically added a few lines describing possible issues so that Mac users are aware that the GUI is not working as expected. For this specific issue, I still believe that this is a problem of HiDPI but haven't been able to pin it down. I added an issue to have a look on HiDPI in total (see #223). @c-joly let me know if I forgot something or if you are not happy with what I wrote in the docs.