Repository: ManimCommunity/manim

Issue:
`stop_condition` of `Wait(...)` is never called.
## Description of bug / unexpected behavior
<!-- Add a clear and concise description of the problem you encountered. -->

As the title describes, playing a `Wait(...)` with a `stop_condition` specified never leads to the `stop_condition` being evaluated. Furthermore the combination of `Wait(...)` with a specified `stop_condition` seems to mess with the duration of other animations?!


## Expected behavior
<!-- Add a clear and concise description of what you expected to happen. -->

When playing a `Wait(stop_condition=..., ...)` the specified `stop_condition` should be evaluated every frame as described in the [docs](https://docs.manim.community/en/stable/reference/manim.animation.animation.Wait.html).


## How to reproduce the issue
<!-- Provide a piece of code illustrating the undesired behavior. -->

```py
from manim import *


class Example(Scene):

    def construct(self) -> None:
        def increase_time(time: ValueTracker, dt: float) -> None:
            time.increment_value(dt)

        self.time = ValueTracker(0)
        self.time.add_updater(increase_time)
        self.add(self.time)

        def stop_condition() -> bool:
            print('checking stop condition')
            return self.time.get_value() > 3

        self.play(Create(Circle(), run_time=1))
        self.play(Wait(stop_condition=stop_condition))
        self.play(Create(Square(), run_time=1))
```

**Note:** I would expect above code to create a 4 seconds long video. Instead it produces a **1 second long video**?!


## Logs
<details><summary>Terminal output</summary>
<!-- Add "-v DEBUG" when calling manim to generate more detailed logs -->

```
$ manim example.py 
Manim Community v0.17.2

[02/02/23 22:32:55] INFO     Animation 0 : Partial movie file written in 'C:\Users\...\media\videos\example\1080p60\partial_movie_files\Example\1413466013_3709342055_3805741643.mp4' scene_file_writer.py:527                    
                    INFO     Animation 1 : Partial movie file written in 'C:\Users\...\media\videos\example\1080p60\partial_movie_files\Example\1672018281_2198544816_3517487940.mp4' scene_file_writer.py:527
[02/02/23 22:32:56] INFO     Animation 2 : Partial movie file written in 'C:\Users\...\media\videos\example\1080p60\partial_movie_files\Example\1672018281_3828930679_184856414.mp4'  scene_file_writer.py:527                    
                    INFO     Combining to Movie file.                                                                                                                                 scene_file_writer.py:617                    
                    INFO                                                                                                                                                              scene_file_writer.py:736                             
                             File ready at 'C:\Users\...\media\videos\example\1080p60\Example.mp4'

                    INFO     Rendered Example                                                                                                                                         scene.py:241                             
                             Played 3 animations
```

<!-- Insert screenshots here (only when absolutely necessary, we prefer copy/pasted output!) -->

</details>


## System specifications

<details><summary>System Details</summary>

- OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): Windows 10 Version 22H2 (OS Build 19045.2546)
- RAM: 16 GB
- Python version (`python/py/python3 --version`): 3.10.9
- Installed modules (provide output from `pip list`):
```
$ conda list
# packages in environment at C:\ProgramData\Miniconda3\envs\research_project:
#
# Name                    Version                   Build  Channel
aom                       3.5.0                h63175ca_0    conda-forge
appdirs                   1.4.4              pyh9f0ad1d_0    conda-forge
attrs                     22.2.0             pyh71513ae_0    conda-forge
autopep8                  1.6.0              pyhd3eb1b0_1
bresenham                 0.2.1                    pypi_0    pypi
brotli                    1.0.9                hcfcfb64_8    conda-forge
brotli-bin                1.0.9                hcfcfb64_8    conda-forge
brotlipy                  0.7.0           py310h8d17308_1005    conda-forge
bzip2                     1.0.8                he774522_0
ca-certificates           2022.12.7            h5b45459_0    conda-forge
cachecontrol              0.12.11            pyhd8ed1ab_0    conda-forge
cairo                     1.16.0            hd694305_1014    conda-forge
certifi                   2022.12.7          pyhd8ed1ab_0    conda-forge
cffi                      1.15.1          py310h628cb3f_3    conda-forge
charset-normalizer        2.1.1              pyhd8ed1ab_0    conda-forge
cleo                      2.0.1              pyhd8ed1ab_0    conda-forge
click                     8.1.3           win_pyhd8ed1ab_2    conda-forge
click-default-group       1.2.2              pyhd8ed1ab_1    conda-forge
cloup                     0.13.1             pyhd8ed1ab_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
colour                    0.1.5                      py_0    conda-forge
contourpy                 1.0.7           py310h232114e_0    conda-forge
crashtest                 0.4.1              pyhd8ed1ab_0    conda-forge
cryptography              39.0.0          py310h52f42fa_0    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
dataclasses               0.8                pyhc8e2a94_3    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
distlib                   0.3.6              pyhd8ed1ab_0    conda-forge
dulwich                   0.20.50         py310h8d17308_0    conda-forge
expat                     2.5.0                h1537add_0    conda-forge
ffmpeg                    5.1.2           gpl_h5b1d025_106    conda-forge
filelock                  3.9.0              pyhd8ed1ab_0    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.14.2               hbde0cde_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
fonttools                 4.38.0          py310h8d17308_1    conda-forge
freetype                  2.12.1               h546665d_1    conda-forge
fribidi                   1.0.10               h8d14728_0    conda-forge
future                    0.18.3             pyhd8ed1ab_0    conda-forge
gettext                   0.21.1               h5728263_0    conda-forge
glcontext                 2.3.7           py310h00ffb61_0    conda-forge
glib                      2.74.1               h12be248_1    conda-forge
glib-tools                2.74.1               h12be248_1    conda-forge
graphite2                 1.3.13                     1000    conda-forge
gst-plugins-base          1.21.3               h001b923_1    conda-forge
gstreamer                 1.21.3               h6b5321d_1    conda-forge
harfbuzz                  6.0.0                he256f1b_0    conda-forge
html5lib                  1.1                pyh9f0ad1d_0    conda-forge
icu                       70.1                 h0e60522_0    conda-forge
idna                      3.4                pyhd8ed1ab_0    conda-forge
importlib-metadata        6.0.0              pyha770c72_0    conda-forge
importlib_metadata        6.0.0                hd8ed1ab_0    conda-forge
importlib_resources       5.10.2             pyhd8ed1ab_0    conda-forge
intel-openmp              2023.0.0         h57928b3_25922    conda-forge
isosurfaces               0.1.0              pyhd8ed1ab_0    conda-forge
jaraco.classes            3.2.3              pyhd8ed1ab_0    conda-forge
jpeg                      9e                   h8ffe710_2    conda-forge
jsonschema                4.17.3             pyhd8ed1ab_0    conda-forge
keyring                   23.13.1         py310h5588dad_0    conda-forge
kiwisolver                1.4.4           py310h232114e_1    conda-forge
krb5                      1.20.1               h6609f42_0    conda-forge
lcms2                     2.14                 ha5c8aab_1    conda-forge
lerc                      4.0.0                h63175ca_0    conda-forge
libblas                   3.9.0              16_win64_mkl    conda-forge
libbrotlicommon           1.0.9                hcfcfb64_8    conda-forge
libbrotlidec              1.0.9                hcfcfb64_8    conda-forge
libbrotlienc              1.0.9                hcfcfb64_8    conda-forge
libcblas                  3.9.0              16_win64_mkl    conda-forge
libclang                  15.0.7          default_h77d9078_0    conda-forge
libclang13                15.0.7          default_h77d9078_0    conda-forge
libdeflate                1.17                 hcfcfb64_0    conda-forge
libffi                    3.4.2                hd77b12b_6
libglib                   2.74.1               he8f3873_1    conda-forge
libhwloc                  2.8.0                h039e092_1    conda-forge
libiconv                  1.17                 h8ffe710_0    conda-forge
libjpeg-turbo             2.1.4                hcfcfb64_0    conda-forge
liblapack                 3.9.0              16_win64_mkl    conda-forge
libogg                    1.3.4                h8ffe710_1    conda-forge
libopus                   1.3.1                h8ffe710_1    conda-forge
libpng                    1.6.39               h19919ed_0    conda-forge
libsqlite                 3.40.0               hcfcfb64_0    conda-forge
libtiff                   4.5.0                hf8721a0_2    conda-forge
libvorbis                 1.3.7                h0e60522_0    conda-forge
libwebp-base              1.2.4                h8ffe710_0    conda-forge
libxcb                    1.13              hcd874cb_1004    conda-forge
libxml2                   2.10.3               hc3477c8_0    conda-forge
libzlib                   1.2.13               hcfcfb64_4    conda-forge
lockfile                  0.12.2                     py_1    conda-forge
m2w64-gcc-libgfortran     5.3.0                         6    conda-forge
m2w64-gcc-libs            5.3.0                         7    conda-forge
m2w64-gcc-libs-core       5.3.0                         7    conda-forge
m2w64-gmp                 6.1.0                         2    conda-forge
m2w64-libwinpthread-git   5.0.0.4634.697f757               2    conda-forge
manim                     0.17.2             pyhd8ed1ab_0    conda-forge
manimpango                0.4.3           py310h92b0978_0    conda-forge
mapbox_earcut             1.0.0           py310h232114e_5    conda-forge
markdown-it-py            2.1.0              pyhd8ed1ab_0    conda-forge
matplotlib                3.6.3           py310h5588dad_0    conda-forge
matplotlib-base           3.6.3           py310h51140c5_0    conda-forge
mdurl                     0.1.0              pyhd8ed1ab_0    conda-forge
mkl                       2022.1.0           h6a75c08_874    conda-forge
moderngl                  5.7.4           py310h1c4a608_0    conda-forge
moderngl-window           2.4.1              pyhd8ed1ab_0    conda-forge
more-itertools            9.0.0              pyhd8ed1ab_0    conda-forge
msgpack-python            1.0.4           py310h232114e_1    conda-forge
msys2-conda-epoch         20160418                      1    conda-forge
multipledispatch          0.6.0                      py_0    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
networkx                  2.8.8              pyhd8ed1ab_0    conda-forge
numpy                     1.24.1          py310h4a8f9c9_0    conda-forge
openh264                  2.3.1                h63175ca_1    conda-forge
openjpeg                  2.5.0                ha2aaf27_2    conda-forge
openssl                   1.1.1s               hcfcfb64_1    conda-forge
packaging                 23.0               pyhd8ed1ab_0    conda-forge
pango                     1.50.12              hdffb7b3_1    conda-forge
pcre2                     10.40                h17e33f8_0    conda-forge
pexpect                   4.8.0              pyh1a96a4e_2    conda-forge
pillow                    9.4.0           py310h3d7015a_0    conda-forge
pip                       22.3.1          py310haa95532_0
pixman                    0.40.0               h8ffe710_0    conda-forge
pkginfo                   1.9.6              pyhd8ed1ab_0    conda-forge
pkgutil-resolve-name      1.3.10             pyhd8ed1ab_0    conda-forge
platformdirs              2.6.2              pyhd8ed1ab_0    conda-forge
ply                       3.11                       py_1    conda-forge
poetry                    1.3.1           py310h5588dad_0    conda-forge
poetry-core               1.4.0              pyhd8ed1ab_0    conda-forge
poetry-plugin-export      1.2.0              pyhd8ed1ab_1    conda-forge
pooch                     1.6.0              pyhd8ed1ab_0    conda-forge
pthread-stubs             0.4               hcd874cb_1001    conda-forge
pthreads-win32            2.9.1                hfa6e2cd_3    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pycairo                   1.23.0          py310h42c1a3e_0    conda-forge
pycodestyle               2.10.0          py310haa95532_0
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pydub                     0.25.1             pyhd8ed1ab_0    conda-forge
pyglet                    1.5.27          py310h5588dad_3    conda-forge
pygments                  2.14.0             pyhd8ed1ab_0    conda-forge
pyopenssl                 23.0.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.9              pyhd8ed1ab_0    conda-forge
pyqt                      5.15.7          py310h1fd54f2_3    conda-forge
pyqt5-sip                 12.11.0         py310h00ffb61_3    conda-forge
pyqt5-stubs               5.15.6.0                 pypi_0    pypi
pyrr                      0.10.3                     py_0    conda-forge
pyrsistent                0.19.3          py310h8d17308_0    conda-forge
pysocks                   1.7.1              pyh0701188_6    conda-forge
python                    3.10.9               h966fe2a_0
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python_abi                3.10                    2_cp310    conda-forge
pywin32-ctypes            0.2.0           py310h5588dad_1006    conda-forge
pyyaml                    6.0             py310h8d17308_5    conda-forge
qt-main                   5.15.6               h068e40c_6    conda-forge
rapidfuzz                 2.13.7          py310h00ffb61_0    conda-forge
requests                  2.28.2             pyhd8ed1ab_0    conda-forge
requests-toolbelt         0.10.1             pyhd8ed1ab_0    conda-forge
rich                      13.3.0             pyhd8ed1ab_0    conda-forge
scipy                     1.10.0          py310h578b7cb_0    conda-forge
screeninfo                0.8.1           py310h5588dad_1    conda-forge
setuptools                65.6.3          py310haa95532_0
shellingham               1.5.0.post1        pyhd8ed1ab_0    conda-forge
sip                       6.7.6           py310h00ffb61_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
skia-pathops              0.7.4           py310h232114e_0    conda-forge
slam                      0.1.0                    pypi_0    pypi
sqlite                    3.40.1               h2bbff1b_0
srt                       3.5.2           py310h5588dad_5    conda-forge
svgelements               1.9.0              pyhd8ed1ab_0    conda-forge
svt-av1                   1.4.1                h63175ca_0    conda-forge
tbb                       2021.7.0             h91493d7_1    conda-forge
tk                        8.6.12               h2bbff1b_0
toml                      0.10.2             pyhd3eb1b0_0
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
tomlkit                   0.11.6             pyha770c72_0    conda-forge
tornado                   6.2             py310h8d17308_1    conda-forge
tqdm                      4.64.1             pyhd8ed1ab_0    conda-forge
trove-classifiers         2023.1.20          pyhd8ed1ab_0    conda-forge
typing                    3.10.0.0           pyhd8ed1ab_0    conda-forge
typing-extensions         4.4.0                hd8ed1ab_0    conda-forge
typing_extensions         4.4.0              pyha770c72_0    conda-forge
tzdata                    2022g                h04d1e81_0
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
unicodedata2              15.0.0          py310h8d17308_0    conda-forge
urllib3                   1.26.14            pyhd8ed1ab_0    conda-forge
vc                        14.2                 h21ff451_1
virtualenv                20.17.1         py310h5588dad_0    conda-forge
vs2015_runtime            14.34.31931         h4c5c07a_10    conda-forge
watchdog                  2.2.1           py310h5588dad_0    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.37.1             pyhd3eb1b0_0
win_inet_pton             1.1.0              pyhd8ed1ab_6    conda-forge
wincertstore              0.2             py310haa95532_2
x264                      1!164.3095           h8ffe710_2    conda-forge
x265                      3.5                  h2d74725_3    conda-forge
xorg-libxau               1.0.9                hcd874cb_0    conda-forge
xorg-libxdmcp             1.1.3                hcd874cb_0    conda-forge
xz                        5.2.10               h8cc25b3_1
yaml                      0.2.5                h8ffe710_2    conda-forge
zipp                      3.11.0             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               hcfcfb64_4    conda-forge
zstd                      1.5.2                h12be248_6    conda-forge
```
</details>

<details><summary>LaTeX details</summary>

+ LaTeX distribution (e.g. TeX Live 2020): One MiKTeX Utility 1.4 (MiKTeX 22.10)

</details>

<details><summary>FFMPEG</summary>

Output of `ffmpeg -version`:

```
ffmpeg version 5.1.2 Copyright (c) 2000-2022 the FFmpeg developers
built with clang version 15.0.7
configuration: --prefix=/d/bld/ffmpeg_1674566436592/_h_env/Library --cc=clang.exe --cxx=clang++.exe --nm=llvm-nm --ar=llvm-ar --disable-doc --disable-openssl --enable-demuxer=dash --enable-hardcoded-tables --enable-libfreetype --enable-libfontconfig --enable-libopenh264 --ld=lld-link --target-os=win64 --enable-cross-compile --toolchain=msvc --host-cc=clang.exe --extra-libs=ucrt.lib --extra-libs=vcruntime.lib --extra-libs=oldnames.lib --strip=llvm-strip --disable-stripping --host-extralibs= --enable-gpl --enable-libx264 --enable-libx265 --enable-libaom --enable-libsvtav1 --enable-libxml2 --enable-pic --enable-shared --disable-static --enable-version3 --enable-zlib --enable-libopus --pkg-config=/d/bld/ffmpeg_1674566436592/_build_env/Library/bin/pkg-config
libavutil      57. 28.100 / 57. 28.100
libavcodec     59. 37.100 / 59. 37.100
libavformat    59. 27.100 / 59. 27.100
libavdevice    59.  7.100 / 59.  7.100
libavfilter     8. 44.100 /  8. 44.100
libswscale      6.  7.100 /  6.  7.100
libswresample   4.  7.100 /  4.  7.100
libpostproc    56.  6.100 / 56.  6.100
```
</details>


Discussion:

Resolving patch:
diff --git a/manim/animation/animation.py b/manim/animation/animation.py
--- a/manim/animation/animation.py
+++ b/manim/animation/animation.py
@@ -528,8 +528,8 @@ class Wait(Animation):
     stop_condition
         A function without positional arguments that evaluates to a boolean.
         The function is evaluated after every new frame has been rendered.
-        Playing the animation only stops after the return value is truthy.
-        Overrides the specified ``run_time``.
+        Playing the animation stops after the return value is truthy, or
+        after the specified ``run_time`` has passed.
     frozen_frame
         Controls whether or not the wait animation is static, i.e., corresponds
         to a frozen frame. If ``False`` is passed, the render loop still
diff --git a/manim/scene/scene.py b/manim/scene/scene.py
--- a/manim/scene/scene.py
+++ b/manim/scene/scene.py
@@ -383,6 +383,7 @@ def should_update_mobjects(self) -> bool:
             should_update = (
                 self.always_update_mobjects
                 or self.updaters
+                or wait_animation.stop_condition is not None
                 or any(
                     [
                         mob.has_time_based_updater()
@@ -974,10 +975,7 @@ def get_run_time(self, animations: list[Animation]):
         """
 
         if len(animations) == 1 and isinstance(animations[0], Wait):
-            if animations[0].stop_condition is not None:
-                return 0
-            else:
-                return animations[0].duration
+            return animations[0].duration
 
         else:
             return np.max([animation.run_time for animation in animations])
@@ -1060,7 +1058,8 @@ def wait(
         stop_condition
             A function without positional arguments that is evaluated every time
             a frame is rendered. The animation only stops when the return value
-            of the function is truthy. Overrides any value passed to ``duration``.
+            of the function is truthy, or when the time specified in ``duration``
+            passes.
         frozen_frame
             If True, updater functions are not evaluated, and the animation outputs
             a frozen frame. If False, updater functions are called and frames
@@ -1097,18 +1096,15 @@ def pause(self, duration: float = DEFAULT_WAIT_TIME):
         self.wait(duration=duration, frozen_frame=True)
 
     def wait_until(self, stop_condition: Callable[[], bool], max_time: float = 60):
-        """
-        Like a wrapper for wait().
-        You pass a function that determines whether to continue waiting,
-        and a max wait time if that is never fulfilled.
+        """Wait until a condition is satisfied, up to a given maximum duration.
 
         Parameters
         ----------
         stop_condition
-            The function whose boolean return value determines whether to continue waiting
-
+            A function with no arguments that determines whether or not the
+            scene should keep waiting.
         max_time
-            The maximum wait time in seconds, if the stop_condition is never fulfilled.
+            The maximum wait time in seconds.
         """
         self.wait(max_time, stop_condition=stop_condition)
 


Test patch:
diff --git a/tests/test_scene_rendering/test_play_logic.py b/tests/test_scene_rendering/test_play_logic.py
--- a/tests/test_scene_rendering/test_play_logic.py
+++ b/tests/test_scene_rendering/test_play_logic.py
@@ -73,6 +73,22 @@ def test_non_static_wait_detection(using_temp_config, disabling_caching):
     assert not scene.is_current_animation_frozen_frame()
 
 
+def test_wait_with_stop_condition(using_temp_config, disabling_caching):
+    class TestScene(Scene):
+        def construct(self):
+            self.wait_until(lambda: self.renderer.time >= 1)
+            assert self.renderer.time >= 1
+            d = Dot()
+            d.add_updater(lambda mobj, dt: self.add(Mobject()))
+            self.add(d)
+            self.play(Wait(run_time=5, stop_condition=lambda: len(self.mobjects) > 5))
+            assert len(self.mobjects) > 5
+            assert self.renderer.time < 2
+
+    scene = TestScene()
+    scene.render()
+
+
 def test_frozen_frame(using_temp_config, disabling_caching):
     scene = SceneForFrozenFrameTests()
     scene.render()