How do I dispose a rendering pipeline?

      manager.detachCamerasFromAllPipelines();
      scene.postProcessRenderPipelineManager.pipelines.forEach(p => p.dispose());

This code is not working. Any idea why?

probably because the code iterates over a list you are changing with each calls to dispose ?

Can you explain? I don’t get it.

p.dispose() removes the pipeline from scene.postProcessRenderPipelineManager.pipelines

so if you have 3 pipelines after the first iteration in the foreach the list has changed.

you could try:

while (scene.postProcessRenderPipelineManager.pipelines.length) {
  scene.postProcessRenderPipelineManager.pipelines[0].dispose();
}

It says thatscene.postProcessRenderPipelineManager.pipelines.length
Uncaught TypeError: Cannot read properties of undefined (reading 'length')

@TadKing42 try using postProcessRenderPipelineManager.supportedPipelines (there is no property called pipelines)

  while (scene.postProcessRenderPipelineManager.supportedPipelines) {
    scene.postProcessRenderPipelineManager[0].dispose();
  }

So what is wrong with this now?
It’s saying Cannot read properties of undefined (reading 'dispose')

It should be:

while (scene.postProcessRenderPipelineManager.supportedPipelines.length > 0) {
    scene.postProcessRenderPipelineManager.supportedPipelines[0].dispose();
  }

PostProcessRenderPipelineManager contains the array of supported render pipelines.

That works, but after running my app for the second time, depth of field seems to just turn into a blur effect. It’s not blurring stuff based on distance… It’s just blurring stuff?

Could you share a playground reproducing the issue you are having?

My workspace isn’t really a standalone project but an extension for Turbowarp, meaning that I can’t really share it. I will try though


This is what is happening.

I will share code snippets that I can.

    test(){
      pipelines.forEach((name) => {
        scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(name, camera);
      });
      pipelines.clear();
      while (scene.postProcessRenderPipelineManager.supportedPipelines.length > 0) {
        scene.postProcessRenderPipelineManager.supportedPipelines[0].dispose();
      }
      camera._postProcesses = [];
      console.log(camera)
    }
    async initializescene() {
      scene.meshes.slice().forEach(mesh => mesh.dispose());

      scene.lights.slice().forEach(light => light.dispose());

      scene.cameras.slice().forEach(camera => {
        if (camera !== scene.activeCamera) camera.dispose();
      });

      scene.particleSystems.slice().forEach(system => system.dispose());

      scene.textures.slice().forEach(texture => texture.dispose());

      scene.materials.slice().forEach(material => material.dispose());

      objects.clear();
      particlesystems.clear();
      lights = [];
      shadowGenerators = [];
      const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0));
      console.log(scene.postProcessRenderPipelineManager.supportedPipelines);
    }
    addrenderingpipeline(args){
      pipelines.set(args.name, new BABYLON.DefaultRenderingPipeline(args.name, true, scene, [camera]));
      const defaultPipeline = pipelines.get(args.name)
      if (defaultPipeline.isSupported) {
        /* MSAA */
        defaultPipeline.samples = 1; // 1 by default
        /* imageProcessing */
        defaultPipeline.imageProcessingEnabled = true; //true by default
        if (defaultPipeline.imageProcessingEnabled) {
          defaultPipeline.imageProcessing.contrast = 1; // 1 by default
          defaultPipeline.imageProcessing.exposure = 1; // 1 by default
          /* color grading */
          //defaultPipeline.imageProcessing.colorGradingEnabled = false; // false by default
          //if (defaultPipeline.imageProcessing.colorGradingEnabled) {
            //defaultPipeline.imageProcessing.colorGradingTexture = new BABYLON.ColorGradingTexture("textures/LateSunset.3dl", scene);
          //}
          /* color curves */
          defaultPipeline.imageProcessing.colorCurvesEnabled = false; // false by default
          if (defaultPipeline.imageProcessing.colorCurvesEnabled) {
            var curve = new BABYLON.ColorCurves();
            curve.globalDensity = 0; // 0 by default
            curve.globalExposure = 0; // 0 by default
            curve.globalHue = 30; // 30 by default
            curve.globalSaturation = 0; // 0 by default
            curve.highlightsDensity = 0; // 0 by default
            curve.highlightsExposure = 0; // 0 by default
            curve.highlightsHue = 30; // 30 by default
            curve.highlightsSaturation = 0; // 0 by default
            curve.midtonesDensity = 0; // 0 by default
            curve.midtonesExposure = 0; // 0 by default
            curve.midtonesHue = 30; // 30 by default
            curve.midtonesSaturation = 0; // 0 by default
            curve.shadowsDensity = 0; // 0 by default
            curve.shadowsExposure = 0; // 0 by default
            curve.shadowsHue = 30; // 30 by default
            curve.shadowsDensity = 80;
            curve.shadowsSaturation = 0; // 0 by default;
            defaultPipeline.imageProcessing.colorCurves = curve;
          }
        }

        defaultPipeline.bloomEnabled = false;

        defaultPipeline.chromaticAberrationEnabled = false;

        defaultPipeline.depthOfFieldEnabled = false;

        defaultPipeline.fxaaEnabled = false;

        defaultPipeline.glowLayerEnabled = false;

        defaultPipeline.grainEnabled = false;

        defaultPipeline.sharpenEnabled = false;

      }
      console.log(scene.postProcessRenderPipelineManager.supportedPipelines);
    }

P.S. Don’t look at imageProcessing, look at other postprocesses.

We need a playground to investigate further, this would really help

a simpler way is to call dispose on the scene.postProcessRenderPipelineManager cause this simply disposes the render pipelines it contains.