vle-forge / vle

Virtual Laboratory Environment
http://www.vle-project.org
GNU General Public License v3.0
21 stars 22 forks source link

Win32: error launching SPAWN simulations #396

Closed rtrepos closed 2 years ago

rtrepos commented 2 years ago

Most of the time, launching a spawned simulation leads to the following exception :

error: VLE sub process: unable to start 'C:\Users\rtrepos\AppData\Local\Temp\vle-aec8-3b60-033b-g9g3.vpz' in 'C:\Users\rtrepos\Documents' with the 'vle.exe -V '5' --write-output 'C:\Users\rtrepos\AppData\Local\Temp\vle-aec8-3b60-033b-g9g3.value' 'C:\Users\rtrepos\AppData\Local\Temp\vle-aec8-3b60-033b-g9g3.vpz'' command (Path::file_size(): cannot stat file C:\Users\rtrepos\AppData\Local\Temp\vle-aec8-3b60-033b-g9g3.value) error: fail to run

This error is caught here :

https://github.com/vle-forge/vle/blob/d163b23b19aa7fe63f51649d597772ec227b8913/src/vle/manager/Simulation.cpp#L281

This occurs with both gvle and rvle. Note also that sometimes the same simulation can work.

rtrepos commented 2 years ago

Output files (files *.value) of the SPAWN simulation are not created when simulation fails. The CMD works well yet and creates the output file: "vle.exe --write-output res.value model.vpz"

rtrepos commented 2 years ago

It looks like the vpz is not written soon enough before the simulation is launched. The writing of the vpz is here :

https://github.com/vle-forge/vle/blob/d163b23b19aa7fe63f51649d597772ec227b8913/src/vle/manager/Simulation.cpp#L195

A way around is to add the two followinfg lines just after the previous line :

  using namespace std::chrono_literals;
  std::this_thread::sleep_for(2000ms);

This suggests that there is a missing flush of the output stream when writing the vpz file. Nevertheless, when the flush is added at all possible locations, there is stille the error.

rtrepos commented 2 years ago

The simulation works. This suggests that the writing of the vpz is not the problem.

rtrepos commented 2 years ago

THe initialisation of the random number generator is done differently on Windows with std::time(0)

https://github.com/vle-forge/vle/blob/d163b23b19aa7fe63f51649d597772ec227b8913/src/vle/utils/Filesystem.cpp#L468

THis is maybe due to an old bug on std::random_device (see the Note of the documentation). Replacing std::time(0) by std::random_device (same code for linux and windows) fixes the probelm. I will propose the commit.