Hey Jaimie

thanx for the report. We will be uploading a refactor on the mateirals api
in the next few days that should address this problem, but make sure to add
it to the fixes if it doesn't. Please add your report and the above code to
the issues tracker in github so that we have a log of it being recorded:

https://github.com/away3d/away3d-core-fp11/issues

cheers

Rob

On Thu, Oct 13, 2011 at 11:34 AM, jamie655321 <jamie.ow...@gmail.com> wrote:

> Hi,
>
> I seem to run into some memory problems using BitmapMaterials in
> Away3D 4.
> I have narrowed down the cause to the
> away3d.core.managers.BitmapDataTextureCache class.  But the fix is
> just a change to two Dictionaries that are not using weak keys.  I'm
> thinking that as it is such a trivial thing then perhaps it should be
> kept as is and I am doing something wrong.
>
> Basically the two Dictionaries hang on to BitmapData instances when
> you update a BitmapMaterial's bitmapData property directly.  You can
> confirm this in the Flex Profiler with this basic setup:
>
> package
> {
>        import away3d.containers.View3D;
>        import away3d.materials.BitmapMaterial;
>        import away3d.primitives.Plane;
>
>        import flash.display.Bitmap;
>        import flash.display.Sprite;
>        import flash.display.StageAlign;
>        import flash.display.StageScaleMode;
>        import flash.events.Event;
>        import flash.events.TimerEvent;
>        import flash.geom.Vector3D;
>        import flash.utils.Timer;
>
>        import net.hires.debug.Stats;
>
>        public class Main extends Sprite
>        {
>                [Embed(source="kt_sheet1.png")]
>                public static const BITMAP:Class;
>
>                public var view3D:View3D;
>                public var plane:Plane;
>                public var material:BitmapMaterial;
>
>                public function Main()
>                {
>                        stage.scaleMode = StageScaleMode.NO_SCALE;
>                        stage.align =StageAlign.TOP_LEFT;
>
>                        var stats:Stats = new Stats();
>                        addChild( stats );
>
>                        view3D = new View3D();
>                        addChild( view3D );
>
>                        addEventListener( Event.ENTER_FRAME, onEnterFrame );
>
>                        var timer:Timer = new Timer(100,1000);
>                        timer.addEventListener( TimerEvent.TIMER,
> updateMaterialBitmapData );
>                        timer.start();
>
>                        material = new BitmapMaterial(( new BITMAP() as
> Bitmap ).bitmapData);
>
>                        plane = new Plane(material);
>                        view3D.scene.addChild( plane );
>
>                        view3D.camera.z = -500;
>                        view3D.camera.lookAt(new Vector3D() );
>                }
>
>                private function
> updateMaterialBitmapData($event:TimerEvent):void
>                {
>                        material.bitmapData = null;
>                        material.bitmapData = ( new BITMAP() as Bitmap
> ).bitmapData;
>
>                }
>
>                private function onEnterFrame( $event:Event ):void
>                {
>                        view3D.render();
>                }
>        }
> }
>
>
> If you run this in the profiler you'll see the memory collect. Then
> comparing two memory snapshots and checking loitering objects shows
> the bitmap data are not being cleared from these dictionaries in
> BitmapDataTextureCache :
>
>                public function BitmapDataTextureCache(singletonEnforcer :
> SingletonEnforcer)
>                {
>                        if (!singletonEnforcer) throw new Error("Cannot
> instantiate a
> singleton class. Use static getInstance instead.");
>
>                        _textures = new Dictionary();
>                        _usages = new Dictionary()
>                }
>
>
> https://github.com/away3d/away3d-core-fp11/blob/master/src/away3d/core/managers/BitmapDataTextureCache.as
>
> Passing true to the two dictinoaries fixes the problem.
>
> Perhaps I shouldn't update a BitmapMaterials bitmapData instance like
> this.  But i was under the impression its better to reuse Material
> instances.
> The problem came about when i implemented a Factory pattern with
> reusable Plane objects ( say for an image gallery )
>
> Cheers
>
> Jamie




-- 
Rob Bateman
Flash Development & Consultancy

rob.bate...@gmail.com
www.infiniteturtles.co.uk
www.away3d.com

Reply via email to