diff --git a/examples/core/demo_player.py b/examples/core/demo_player.py index 7d42318..e2ed66c 100644 --- a/examples/core/demo_player.py +++ b/examples/core/demo_player.py @@ -13,7 +13,7 @@ player.launch() # Run some steps of the simulation - for _ in range(500): + while player.is_open: simu.step() player.render() diff --git a/examples/core/demo_viewer.py b/examples/core/demo_viewer.py index 87483e5..e322c75 100644 --- a/examples/core/demo_viewer.py +++ b/examples/core/demo_viewer.py @@ -13,7 +13,7 @@ viewer.launch() # Run some steps of the simulation - for _ in range(500): + while viewer.is_open: simu.step() viewer.render() diff --git a/examples/sofa/demo_player.py b/examples/sofa/demo_player.py index 6d95fa1..5e8e595 100644 --- a/examples/sofa/demo_player.py +++ b/examples/sofa/demo_player.py @@ -19,7 +19,7 @@ # SOFA: run a few time steps # VIEWER: update the rendering - for i in range(300): + while player.is_open: Sofa.Simulation.animate(root, root.dt.value) player.render() diff --git a/examples/sofa/demo_viewer.py b/examples/sofa/demo_viewer.py index 46cf665..6fa0d00 100644 --- a/examples/sofa/demo_viewer.py +++ b/examples/sofa/demo_viewer.py @@ -22,7 +22,7 @@ # SOFA: run a few time steps # VIEWER: update the rendering - for i in range(300): + while viewer.is_open: Sofa.Simulation.animate(root, root.dt.value) viewer.render() diff --git a/src/SimRender/core/local/factory.py b/src/SimRender/core/local/factory.py index 8dd0014..9993fa8 100644 --- a/src/SimRender/core/local/factory.py +++ b/src/SimRender/core/local/factory.py @@ -37,6 +37,10 @@ def __init__(self, sync: bool): self.__sync_arr = ndarray(shape=sync_array.shape, dtype=sync_array.dtype, buffer=self.__sync_sm.buf) self.__sync_arr[...] = sync_array[...] + @property + def is_open(self) -> bool: + return self.__sync_arr[0] == 0 + def init(self, batch_key: Optional[int]) -> int: """ Initialize the local socket. @@ -99,7 +103,7 @@ def __sync(self): self.__sync_arr[1] = 1 # Wait for the remote process to be done (after several tests, it appears to be the faster way) - self.__remote.recv(4) + a = self.__remote.recv(4) # Turn the 'do_synchronize' shared flag off self.__sync_arr[1] = 0 diff --git a/src/SimRender/core/local/viewer.py b/src/SimRender/core/local/viewer.py index 65beeec..88802bd 100644 --- a/src/SimRender/core/local/viewer.py +++ b/src/SimRender/core/local/viewer.py @@ -23,6 +23,10 @@ def __init__(self, sync: bool = False): self.__subprocess: Optional[Thread] = None self._remote_script = viewer.__file__ + @property + def is_open(self) -> bool: + return self.__factory.is_open + @property def objects(self) -> Objects: """ diff --git a/src/SimRender/core/remote/factory.py b/src/SimRender/core/remote/factory.py index bf12d5d..2d51c08 100644 --- a/src/SimRender/core/remote/factory.py +++ b/src/SimRender/core/remote/factory.py @@ -130,6 +130,10 @@ def close(self): Close the communication with the simulation process. """ + # If the window is closed manually then turn the do_exit flag to True + if not self.__sync_arr[0]: + self.__sync_arr[0] = 1 + # Close the connection with the shared memories (synchronization array and each visual object array) self.__sync_sm.close() for memory in self.__memories: diff --git a/src/SimRender/core/remote/viewer.py b/src/SimRender/core/remote/viewer.py index 455c90a..525c539 100644 --- a/src/SimRender/core/remote/viewer.py +++ b/src/SimRender/core/remote/viewer.py @@ -37,6 +37,7 @@ def launch(self): # Launch the visualization window self.factory.listen() self.show(axes=4).close() + self.factory.close() def time_step(self, _) -> None: """ diff --git a/src/SimRender/core/remote/viewer_batch.py b/src/SimRender/core/remote/viewer_batch.py index 90fc359..dfc34e3 100644 --- a/src/SimRender/core/remote/viewer_batch.py +++ b/src/SimRender/core/remote/viewer_batch.py @@ -88,7 +88,7 @@ def on_close_event(self): # Executed code when the visualization process is launched batch_socket_ports = [int(port) for port in sys.argv[1].split(' ')] win = ViewerBatch(socket_ports=batch_socket_ports) + win.showMaximized() - # sys.exit(app.exec()) app.aboutToQuit.connect(win.on_close_event) app.exec()