Why does rendering_to_image require post_to_main_thread and why does it take a significantly long time to run?
- Dominant language
- C++
- Stars
- 14k
- Forks
- 2.6k
- Avg merge
- 5d 18h
- Merged PRs (30d)
- 6
Description
### Checklist
- [X] I have searched for [similar issues](https://github.com/isl-org/Open3D/issues).
- [X] For Python issues, I have tested with the [latest development wheel](http://www.open3d.org/docs/latest/getting_started.html#development-version-pip).
- [X] I have checked the [release documentation](http://www.open3d.org/docs/release/) and the [latest documentation](http://www.open3d.org/docs/latest/) (for `master` branch).
### My Question
I have the following code:
```
def _start_recording(self):
self._last_animation_time = 0.0
self.main_thread_finished = True
def callable():
def render_callback(image):
image = np.asarray(image)
image = Image.fromarray(image, "RGB")
image.save(os.path.join(self.file_path, f"{self.index:05d}.png"))
self.index += 1
self.scene.scene.render_to_image(render_callback)
self.main_thread_finished = True
while self._running.is_set():
now = time.time()
if self.main_thread_finished and now >= self._last_animation_time + self.animation_delay_time:
print(now - self._last_animation_time)
self._last_animation_time = now
self.main_thread_finished = False
gui.Application.instance.post_to_main_thread(self.simulator.window, callable)
```
`self.animation_delay_time = 0.1` and `self.scene` is a gui.SceneWidget()
`self._running` is a threading.Event()
The function is called through `threading.Thread(target=self._start_recording).start()`
The first Issue I am encountering is the huge delay between each frame if I post_to_main_thread. The time it takes to render + save each image is around 0.002 seconds whereas the complete process takes about 1-2 seconds. Is there a reason why post_to_main_thread is significantly slower and is there a fix for it?
The second issue has to do with a threading error I am encountering. If I put callable() instead of gui.Application.instance.post_to_thread, I get the following error:
```
class utils::PreconditionPanic
in struct utils::JobSystem::ThreadState &__cdecl utils::JobSystem::getState(void) noexcept:228
reason: This thread has not been adopted.
```
What does it mean and how can I fix it?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.