esmini icon indicating copy to clipboard operation
esmini copied to clipboard

esmini fails to run xosc file in Ubuntu 22.04 shell session but successfully

Open erikpolano opened this issue 1 year ago • 6 comments

I am trying to run esmini on Ubuntu 22.04 to generate screenshots which can be used to generate a video of a traffic simulation on an AWS EC2 instance.

When running esmini from a terminal I have open while logged in through DCV Viewer, it runs successfully.

However, when I try to execute the command using only a shell session (no GUI open) it fails with an error specifying a segmentation fault. (see screenshot) Screenshot 2023-09-29 at 15 18 57

I use the exact same command in both cases from the exact same directory, but do not get the error when I executre through DCV Viewer.

The below is the command I try running: ./esmini --window 100 100 800 400 --osc "Sesmini_path$xosc_filename" --fixed_timestep 0.033 --capture_screen --aa _mode 0 --headless

The error I get when executing through the shell are the following lines:

No protocol specified No protocol specified 0.000: Viewer failure. Probably requested level of Anti Aliasing (0 multisamples) is not supported. Making another attempt without Anti-Alias and on first screen No protocol specified No protocol specified 0.000: Failed 2nd attempt to create viewer, giving up. Try --headless option to run without viewer 0.000: Viewer initialization failed

Any idea what I can change? I am running it with --headless to try to ensure no window is opened for the simulation but cannot get it working.

erikpolano avatar Oct 03 '23 15:10 erikpolano

It seems that esmini (or OpenGL in the end) fails to create a window with a graphics context.

If the case is that you have no X environment, only a shell, I see two options:

1. Run esmini with off-screen rendering. Try: ./bin/esmini --window 60 60 800 400 --headless --osc ./resources/xosc/cut-in.xosc --fixed_timestep 0.01 --record sim.dat --capture_screen

This will 1. create a series of images on disk (see User guide - Screenshots and video clips) and 2. a dat file which is a recording of the scenario that can be played later in replayer (see User guide - Replay scenario).

2. Run esmini without rendering Similar to above, but skip the --window and --capture_screen arguments: ./bin/esmini --headless --osc ./resources/xosc/cut-in.xosc --fixed_timestep 0.01 --record sim.dat

It will create the dat file for later replay of the scenario. Note that .dat files also need graphics context to run, but the .dat file can be moved to another computer (virtual or physical) which have a graphic OS (it's also portable between systems Win, Linux and Mac).

Let us know if this helps your use case, or if we should look further for solution.

eknabevcc avatar Oct 03 '23 18:10 eknabevcc

BTW: From the images you can easily create video clip. See info here: User guide - Create video clip of a scenario.

For creation of videos no GUI or X graphics system is needed. Only for playing them.

eknabevcc avatar Oct 04 '23 05:10 eknabevcc

Thank you for the quick response and for sharing the documentation.

My use case is to build a prototype application in which a user can generate a video of a simulation of a traffic simulation using an OpenScenario file from a web front end in AWS.

To add further context, we have been able to successfully use your documentation to create a bash script that: i) downloads the OpenScenario file from an S3 bucket to the EC2 instance ii) runs the simulation outputting screenshots on the EC2 instance. iii) uses ffmpeg to generate the video iv) uploads video to s3 bucket and display it in the web front end.

This runs perfectly when executed through DCV viewer with the GUI/x graphics system available but triggering it remotely with our current approach fails. We need to be able to run the simulation and generate the screenshots in some way on the EC2 instance remotely to handle the user requests sent from the web front end.

This is currently being done through an AWS Lambda function that calls on AWS Systems Manager's Run Command functionality to run the bash script using the ssm-user on the instance.

Outside of the scope of esmini, but if you have any suggestions how to trigger esmini remotely with a graphic context, that would be much appreciated.

erikpolano avatar Oct 04 '23 10:10 erikpolano

This is outside my comfort zone, but maybe you could create a minimalistic script that launces esmini with specified scenario.

Something like:

#!/bin/bash
./bin/esmini --window 60 60 800 400 --headless --fixed_timestep 0.033 --record sim.dat --capture_screen --osc $1

make sure to make it executable: chmod +x your_script.sh

Then hopefully you can trig the script with scenariofile as argument, like:

./your_script.sh your_scenario.xosc

But I guess you already tried something similar...

eknabevcc avatar Oct 04 '23 12:10 eknabevcc

Thanks for all your support @eknabevcc !

We found a breakthrough on how we can run the simulation with the AWS SSM command remotely.

It's not the most optimal solution, but i think we can currently live with that. 1/ We have to be connected to NICE DCV, there is currently no timely way around this. 2/ There has to be a terminal opened up in NICE DCV 3/ We are going to make use of pynput library to simulate, somebody that is going to type in our arguments in the previously opened up terminal. The SSM Run Command will just pass the parameters and execute to the pynput script and the pynput script will simulate our input in the display. It's super hacky, but it's working as a way to get esmini to be able to function as the back-end rendering of the simulation and screenshots before a video is sent to our front end.

We will update this if we find a more elegant way to get this to work.

erikpolano avatar Oct 06 '23 10:10 erikpolano

I'm glad that you found a working solution. Good enough is usually good enough.

Thanks for sharing the temporary solution. Maybe someone, with more experience than me on this topic, can provide some advise.

eknabevcc avatar Oct 06 '23 11:10 eknabevcc