# Stencil buffer set wrong in highlightlayer excluded meshes after render

**URL:** <https://forum.babylonjs.com/t/stencil-buffer-set-wrong-in-highlightlayer-excluded-meshes-after-render/39839>\
**Category:** Bugs\
**Created:** [April 13, 2023, 1:58am UTC](https://forum.babylonjs.com/t/stencil-buffer-set-wrong-in-highlightlayer-excluded-meshes-after-render/39839 "2023-04-13T01:58:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tanpopo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tanpopo/32/32025_2.png) [@tanpopo](https://forum.babylonjs.com/u/tanpopo)\
**Post date:** [April 13, 2023, 1:58am UTC](https://forum.babylonjs.com/t/stencil-buffer-set-wrong-in-highlightlayer-excluded-meshes-after-render/39839/1 "2023-04-13T01:58:29Z")

</div>

Bug reproduce: [https://playground.babylonjs.com/#K11VKJ#1](https://playground.babylonjs.com/#K11VKJ#1)

> <https://github.com/BabylonJS/Babylon.js/blob/4f4d3131a9886160508fabac118abb52e66de738/packages/dev/core/src/Layers/highlightLayer.ts#L634>

StencilBuffer should be set to the previous state in beforeBind rather than true.

---

<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:** [April 13, 2023, 10:37am UTC](https://forum.babylonjs.com/t/stencil-buffer-set-wrong-in-highlightlayer-excluded-meshes-after-render/39839/2 "2023-04-13T10:37:41Z")

</div>

Thanks for the report and the fix!

Here’s the PR:

> <https://github.com/BabylonJS/Babylon.js/pull/13734>
>
> See https://forum.babylonjs.com/t/stencil-buffer-set-wrong-in-highlightlayer-exc…luded-meshes-after-render/39839
