# Viewer causes renderingGroupId to become invalid

**URL:** <https://forum.babylonjs.com/t/viewer-causes-renderinggroupid-to-become-invalid/35360>\
**Category:** Bugs\
**Created:** [November 3, 2022, 3:40am UTC](https://forum.babylonjs.com/t/viewer-causes-renderinggroupid-to-become-invalid/35360 "2022-11-03T03:40:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiehangyun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/xiehangyun/32/30777_2.png) [@xiehangyun](https://forum.babylonjs.com/u/xiehangyun)\
**Post date:** [November 3, 2022, 3:40am UTC](https://forum.babylonjs.com/t/viewer-causes-renderinggroupid-to-become-invalid/35360/1 "2022-11-03T03:40:53Z")

</div>

The sample project：[test.zip](https://forum.babylonjs.com/uploads/short-url/wMt5GglY6XSK0ZR8g6c4qzqCoPy.zip) (65.0 KB)  
Our project used defaultViewer of the viewer to build the scene, and I found renderingGroupId invalid.  
This is an unusual situation：

 ![异常代码](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/0/b0ab551ae4e38354483955827fc93c320ccff326.png)  
 ![异常](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/a/bac9c8a94e2c764660eeff7a015af5710ee377a0.jpeg)  
This is normal：  
 ![正常代码](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/6/367bfece6db65443fb3ee249849de09c9c61e788.png)

 ![正常](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/d/1/d174c6e481937d5376803610345217682c980aa7.png)

仅仅只是 new DefaultViewer 就会导致本该正常的另外一个本该正常的场景同样发生renderingGroupId 失效的问题，我怀疑可能是 new DefaultViewer 时，修改了某个常量导致了这个问题。可以下载示例代码压缩包后 npm install、npm dev 进行复现。

---

<div class="post-metadata">

**Author:** ![xiehangyun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/xiehangyun/32/30777_2.png) [@xiehangyun](https://forum.babylonjs.com/u/xiehangyun)\
**Post date:** [November 3, 2022, 3:41am UTC](https://forum.babylonjs.com/t/viewer-causes-renderinggroupid-to-become-invalid/35360/2 "2022-11-03T03:41:20Z")

</div>

Just the new DefaultViewer will cause renderingGroupId to fail in another otherwise normal scene. I suspect that the new DefaultViewer may have changed a constant to cause the problem. npm install and npm dev can be downloaded to reproduce the sample code.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [November 3, 2022, 8:00am UTC](https://forum.babylonjs.com/t/viewer-causes-renderinggroupid-to-become-invalid/35360/3 "2022-11-03T08:00:52Z")

</div>

I don’t see any change in the viewer since at least march this year which could explain this new behaviour…

It looks like `scene.setRenderingAutoClearDepthStencil` is called to disable clearing. You can try to add:

```javascript
scene.setRenderingAutoClearDepthStencil(0, true);
scene.setRenderingAutoClearDepthStencil(1, true);
scene.setRenderingAutoClearDepthStencil(2, true);

```

after you get the scene with `let scene = viewer.engine.scenes[0];` and see if that helps.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [November 3, 2022, 8:42am UTC](https://forum.babylonjs.com/t/viewer-causes-renderinggroupid-to-become-invalid/35360/4 "2022-11-03T08:42:09Z")

</div>

Ok, I found this one.

That’s because the viewer is setting `RenderingManager.AUTOCLEAR = false`, which disables the clearing between the rendering groups.

You can reactivate clearing by doing `RenderingManager.AUTOCLEAR = true;` after `let scene = viewer.engine.scenes[0];`.

Note however that this is not new, the viewer is disabling this clearing since april 2018.

---

<div class="post-metadata">

**Author:** ![xiehangyun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/xiehangyun/32/30777_2.png) [@xiehangyun](https://forum.babylonjs.com/u/xiehangyun)\
**Post date:** [November 3, 2022, 8:42am UTC](https://forum.babylonjs.com/t/viewer-causes-renderinggroupid-to-become-invalid/35360/5 "2022-11-03T08:42:51Z")

</div>

I think there’s some static property that controls how renderingGroupId works, otherwise scene and engine shouldn’t contaminate each other.

---

<div class="post-metadata">

**Author:** ![xiehangyun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/xiehangyun/32/30777_2.png) [@xiehangyun](https://forum.babylonjs.com/u/xiehangyun)\
**Post date:** [November 4, 2022, 1:42am UTC](https://forum.babylonjs.com/t/viewer-causes-renderinggroupid-to-become-invalid/35360/6 "2022-11-04T01:42:12Z")

</div>

Thank you. That’s right
