isl-org / isl-org/Open3D

Bug: Rendering becomes corrupted after a certain amount of frames

Open
#7,129 2 comments 1 reaction 0 assignees View on GitHub
bug
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](https://www.open3d.org/docs/latest/getting_started.html#development-version-pip).
- [X] I have checked the [release documentation](https://www.open3d.org/docs/release/) and the [latest documentation](https://www.open3d.org/docs/latest/) (for `main` branch).

### Describe the issue

I am creating an application where a renderer is created and destoyed 1000s of times. A single renderer is created inside a loop and destroyed at the end of the loop.

The problem is that after some 18700 iterations, rendering becomes corrupted and it turns black.

The rendered images move from this:

To (after 18700 iterations or less than 15 minutes):

I managed to replicate this issue on the [Offscreenrendering.cpp](https://github.com/isl-org/Open3D/blob/main/examples/cpp/OffscreenRendering.cpp) example. Please run the modified example below:

### Steps to reproduce the bug

```
// Modified offscreenrendering example such that the bug is reproduced.
#include "open3d/Open3D.h"
#include "open3d/visualization/rendering/Camera.h"
#include "open3d/visualization/rendering/filament/FilamentEngine.h"
#include "open3d/visualization/rendering/filament/FilamentRenderer.h"

using namespace open3d;
using namespace open3d::visualization::gui;
using namespace open3d::visualization::rendering;

// Headless rendering requires Open3D to be compiled with OSMesa support.
// Add -DENABLE_HEADLESS_RENDERING=ON when you run CMake.
static const bool kUseHeadless = false;

static const std::string kOutputFilename = "offscreen.png";

int main(int argc, const char *argv[]) {
const int width = 640;
const int height = 480;

auto &app = Application::GetInstance();
app.Initialize("/usr/local/share/resources/");

if (kUseHeadless) {
EngineInstance::EnableHeadless();
}

// This example demonstrates rendering to an image without a window.
// If you want to render to an image from within a window you should use
// scene->GetScene()->RenderToImage() instead.
int counter = 0;
while(true) {
auto *renderer =
new FilamentRenderer(EngineInstance::GetInstance(), width, height,
EngineInstance::GetResourceManager());
auto *scene = new Open3DScene(*renderer);

MaterialRecord mat;
mat.shader = "defaultLit";
auto torus = open3d::geometry::TriangleMesh::CreateTorus();
torus->ComputeVertexNormals();
torus->PaintUniformColor({1.0f, 1.0f, 0.0f});
scene->AddGeometry("torus", torus.get(), mat);
scene->ShowAxes(true);

scene->GetCamera()->SetProjection(60.0f, float(width) / float(height), 0.1f,
10.0f, Camera::FovType::Vertical);
scene->GetCamera()->LookAt({0.0f, 0.0f, 0.0f}, {3.0f, 3.0f, 3.0f},
{0.0f, 1.0f, 0.0f});

auto img = app.RenderToImage(*renderer, scene->GetView(), scene->GetScene(), width, height);
if (counter % 100 == 0) {
io::WriteImage("./out/" + std::to_string(counter) + ".png", *img);
}
counter++;

// We manually delete these because Filament requires that things get
// destructed in the right order.
delete scene;
delete renderer;
}

// Cleanup Filament. Normally this is done by app.Run(), but since we are
// not using that we need to do it ourselves.
app.OnTerminate();
}
```

### Error message

No error messages.

### Expected behavior

The rendering should not turn to black; instead it turns to black every time on exactly the same iteration.

A standalone example is pasted above. It is a replica of [Offscreenrendering example](https://github.com/isl-org/Open3D/blob/main/examples/cpp/OffscreenRendering.cpp) but repeated 1000s of times. I run it on my machine for 15 minutes until the rendered images start to become corrupted.

### Open3D, Python and System information

```markdown
- Operating system: `Ubuntu 24.04`
- Python version: `3.12.3 (main, Nov 6 2024, 18:32:19) [GCC 13.2.0]`
- Open3D version: `0.19 build from source with and without CUDA; with SHARED_LIBS=ON and OFF`. Also tried `0.18 with and without CUDA precompiled packages.`
- System architecture: `x86`
- Is this a remote workstation?: no
- How did you install Open3D?: 0.19 build from source; also tried precompiled package for 0.18.
- Compiler version (if built from source): `gcc 13.3.0`
```

### Additional information

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.