Animator can use the incorrect engine in some circumstances
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 316
- Avg merge
- 7h 44m
- Merged PRs (30d)
- 5
Description
Spawn from a failing unittest in https://github.com/simphony/simphony-mayavi/pull/173
Briefly said, this test fails
```
def _setUp(self):
self.engine = DummyEngine()
self.mayavi_engine = NullEngine()
# Add a dataset to scene
self.engine_source = EngineSource(engine=self.engine,
dataset="particles")
self.mayavi_engine.add_source(self.engine_source)
# RunAndAnimatePanel
self.panel = RunAndAnimatePanel(engine=self.engine,
mayavi_engine=self.mayavi_engine)
def test_animate_fired(self):
# given
self._setUp()
self.panel._number_of_runs = 2
ui = self.panel.show_config()
def engine_ran_twice(source):
return source.engine.time >= 20.
# animate as the engine ran for 2 times
with self.assertTraitChangesInEventLoop(self.engine_source,
"data_changed",
count=2,
condition=engine_ran_twice):
press_button_by_label(ui, "Animate")
```
The problem was bisected to this PR https://github.com/enthought/mayavi/pull/411/files
specifically this code
```
def _update_movie_maker(self):
if self._movie_maker is None:
from .engine_manager import get_engine
scene = get_engine().current_scene.scene
```
The problem is that get_engine() is highly deceiving in its behavior. If a current_engine is already present, it still goes through the registry, appends them to the list, select a valid engine according to the options, and pick the last one. This has the consequence that even if you have an engine currently set and active (even when created with get_null_engine()), it will be thrown away in favour of another one.
I see two possibilities to fix this problem
1. don't use get_engine() to retrieve the engine, but use engine_manager.current_engine (which however can be None)
2. have get_engine() behavior to fall back only if an engine is not already defined.
I don't understand the rationale behind the current behavior, I'm sure there's something I am not aware of, but seems rather counterintuitive that asking for the engine when it's already set returns a completely new one.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.