away3d/away3d-core-fp11 — Issue #165: Cannot toggle DepthOfField3D
Author: lbergman
Created: 2011-10-26 06:05:41+00:00
State: open

Attempting to toggle DepthOfField3D filter on and off will result in Context3D throwing an error.

Here is a simple example class using a timer to switch DepthOfField3D on and off every two seconds:

```as3
package
{
import away3d.containers.ObjectContainer3D;
import away3d.containers.View3D;
import away3d.filters.DepthOfFieldFilter3D;
import away3d.materials.ColorMaterial;
import away3d.primitives.Cube;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;

public class Main extends Sprite
{
private var _view:View3D;
private var _container:ObjectContainer3D;
private var _cube:Cube;
private var _dofFilter:DepthOfFieldFilter3D;
private var _useDof:Boolean = false;

public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
_view = new View3D();

addChild(_view);

_container = new ObjectContainer3D();
_view.scene.addChild(_container);
_view.width = 1024;
_view.height = 600;

_dofFilter = new DepthOfFieldFilter3D(10, 10);
draw();

addEventListener(Event.ENTER_FRAME, onEnterFrame);

var timer:Timer = new Timer(2000);
timer.addEventListener(TimerEvent.TIMER, onToggleDofTimer);
timer.start();
}

private function onToggleDofTimer(e:TimerEvent):void
{
_useDof = !_useDof;
trace("Main.as.onToggleDofTimer: _useDof = "+_useDof);
_view.filters3d = _useDof ? [_dofFilter] : null;
}

private function onEnterFrame(e:Event):void
{
_cube.rotationX += 5;
_cube.rotationY += 5;
_view.render();
}

private function draw():void
{
_cube = new Cube(new ColorMaterial(0xFF0000));
_view.scene.addChild(_cube);
}

}

}
```

And here is the stack trace:
Error: Error #3663: Sampler 1 binds an undefined texture.
at flash.display3D::Context3D/drawTriangles()
at away3d.core.render::Filter3DRenderer/render()[C:\Users\Spindrift\Documents\DofTest\src\away3d\core\render\Filter3DRenderer.as:136]
at away3d.containers::View3D/render()[C:\Users\Spindrift\Documents\DofTest\src\away3d\containers\View3D.as:436]
at Main/onEnterFrame()[C:\Users\Spindrift\Documents\DofTest\src\Main.as:64]