galatolofederico / manim-presentation

Tool for live presentations using manim
GNU General Public License v3.0
162 stars 18 forks source link

Can't run multiple scenes behind each other #5

Closed linusheck closed 3 years ago

linusheck commented 3 years ago

Hi, another issue: I can't run multiple scenes behind each other. When I do manim_presentation Scene1 Scene2, manim-presentation crashes with:

    return self.caps[self.current_animation]
IndexError: list index out of range

I will look at the code and see if I can fix it.

galatolofederico commented 3 years ago

That is weird, i have used it for a live presentation at a conference with like 15 scenes without any problem. I assumed in the code that in each Scene there is at least a pause or a loop so maybe this is the problem. Good luck with the debugging and thank for your help!

linusheck commented 3 years ago

Hi, there was a pause at the end, and I spent the last hour debugging the state machine. I ended up changing quite a lot of things, maybe some unjustifiedly - I will use my fork for my presentation, not sure I improved your code. Pull request incoming.

leleogere commented 3 years ago

I'm also facing the same issue with a scene. Here is the code:

class Example3(Slide, ThreeDScene):
    def construct(self):
        axes = ThreeDAxes()
        self.set_camera_orientation(phi=80 * DEGREES, theta=-60 * DEGREES)
        self.pause()
        self.play(Create(axes))
        self.pause()

It raises an IndexError, preventing the program to continue with another scene. The first pause don't even work... It might be due to the ThreeDScene?

I also observed the same bug when a scene ends with a self.end_loop().

linusheck commented 3 years ago

Can you try using my branch? Loops don't work there, I think, that must still be fixed, but maybe your thing already works?

leleogere commented 3 years ago

Looks like it is indeed fixed on your branch!

galatolofederico commented 3 years ago

Fixed in #7

linusheck commented 3 years ago

This occurs in 0.2.0 as well.

linusheck commented 3 years ago

I think this is again because of the add_last_slide function.

galatolofederico commented 3 years ago

I cant reproduce this issue can you paste the scenes you are trying to run here?

linusheck commented 3 years ago

Basic example.

from manim import *
from manim_presentation import Slide

config.background_color = WHITE

class Example(Slide):
    def construct(self):
        text = Text("Look at this cool circle!", color=BLACK)

        self.play(Write(text))
        self.pause()
manim -ql start.py Example
(rush-hour-manim) rush-hour-manim:master* λ manim_presentation Example Example
Traceback (most recent call last):
  File "/home/linus/.local/share/virtualenvs/rush-hour-manim-Nc15sNoH/bin/manim_presentation", line 8, in <module>
    sys.exit(main())
  File "/home/linus/.local/share/virtualenvs/rush-hour-manim-Nc15sNoH/lib/python3.9/site-packages/manim_presentation/present.py", line 296, in main
    display.run()
  File "/home/linus/.local/share/virtualenvs/rush-hour-manim-Nc15sNoH/lib/python3.9/site-packages/manim_presentation/present.py", line 190, in run
    self.handle_key()
  File "/home/linus/.local/share/virtualenvs/rush-hour-manim-Nc15sNoH/lib/python3.9/site-packages/manim_presentation/present.py", line 251, in handle_key
    self.current_presentation.next()
  File "/home/linus/.local/share/virtualenvs/rush-hour-manim-Nc15sNoH/lib/python3.9/site-packages/manim_presentation/present.py", line 92, in next
    self.rewind_slide()
  File "/home/linus/.local/share/virtualenvs/rush-hour-manim-Nc15sNoH/lib/python3.9/site-packages/manim_presentation/present.py", line 100, in rewind_slide
    self.current_cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
  File "/home/linus/.local/share/virtualenvs/rush-hour-manim-Nc15sNoH/lib/python3.9/site-packages/manim_presentation/present.py", line 108, in current_cap
    return self.caps[self.current_animation]
IndexError: list index out of range
linusheck commented 3 years ago

I can't reproduce this error not happening in any configuration

galatolofederico commented 3 years ago

Try end your slide with an animation, like a self.play(...) or a self.wait(...). I was thinking to automatically add a millisecond wait animation at the and of each Slide to fix this issue

linusheck commented 3 years ago

Try end your slide with an animation, like a self.play(...) or a self.wait(...). I was thinking to automatically add a millisecond wait animation at the and of each Slide to fix this issue

ooh... i think i had this in my branch. I can drop a PR

galatolofederico commented 3 years ago

I tried adding it in render() before calling super(Slide, self).render(*args, **kwargs) but it doesnt seems to work :sweat_smile:

linusheck commented 3 years ago

Hi you said: Because it is not needed with the add_last_slide(). Or this is was my understanding reading the code. The video of the last slide is the last animation of the current video I don't think that's true. Can you try it out?

linusheck commented 3 years ago

For instance in my example, look at the exclamation mark.

galatolofederico commented 3 years ago

As soon as i will have some spare time i will look into it

linusheck commented 3 years ago

That would be nice :) I think I will first of all just add wait()s. The exports of manim itself actually end one frame too early. That's why I think waiting for one frame at pause() is correct.