PDA

View Full Version : Error #2015 Invalid BitmapData



Domox
December 5th, 2007, 07:12 PM
I get the following:



ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData$iinit()
at com.psyphon.pcl.display::BitMapRenderer$iinit()[C:\Users\Dylan\Desktop\POC\com\psyphon\pcl\display \BitMapRenderer.as:40]
at com.psyphon.poc::Main$iinit()[C:\Users\Dylan\Desktop\POC\com\psyphon\poc\Main.as :46]


Whenever I initialize the following class using:


renderer = new BitMapRenderer(stage.width, stage.height);


And it does not matter what stagesize i set so it isnt a bitmapdata size/memory issue (AFAIK)....



package com.psyphon.pcl.display {

//Flash libs
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.*;

//Extra libs
import com.psyphon.pcl.*;
import com.psyphon.pcl.math.*;
import com.psyphon.pcl.display.*;
import com.psyphon.poc.*;
import de.polygonal.ds.*;

public class BitMapRenderer extends Sprite
{

public static const DEFAULT_COLOR:uint = 0x00000000;

protected var drawCanvas: BitmapData;
protected var bufferCanvas: BitmapData;
protected var bitmap: Bitmap;

protected var currentCanvas: BitmapData;

private var renderStack: ArrayedQueue;

public function BitMapRenderer( width:Number = 512, height:Number = 512)
{
renderStack = new ArrayedQueue(9); //suppports 512 objects (2^9), if you need more change the value to 10 for 1024 entities
drawCanvas = new BitmapData(width, height, false, DEFAULT_COLOR);
bitmap = addChild( new Bitmap(drawCanvas)) as Bitmap;
}

public function addEntity(ent:Entity) : void
{
renderStack.enqueue(ent);
}

public function draw() : void
{
drawCanvas.copyPixels(bufferCanvas, bufferCanvas.rect, new Point(0,0));
currentCanvas = drawCanvas;
}

public function buffer() : void
{
currentCanvas = bufferCanvas = new BitmapData( width, height, false, DEFAULT_COLOR );

var i:Iterator = renderStack.getIterator()
while (i.hasNext())
{
var ent:Entity = i.next();
renderItem(ent);
}
draw();
}

public function renderItem(ent:Entity) : void
{
if(ent.texture.loaded){
//ent.mat.identity();
//ent.mat.translate(-texture.bitmap.width/2, -texture.bitmap.height/2);
//ent.mat.rotate(Math.atan2(vector.y, vector.x));
//ent.mat.translate(pos.x, pos.y);
ent.colorTransform.alphaMultiplier = 100;
currentCanvas.copyPixels(ent.texture.bitmap,ent.te xture.bitmap.rect,new Point(ent.pos.x,ent.pos.y),null,null,true)
//r.draw(texture.bitmap, mat, colorTransform);
}
}

}

}

Domox
December 5th, 2007, 09:33 PM
so, i was using stage.width and stage.height, when i should have been using stage.stagewidth/height. Thanks to Sirisian for pointing it out! :P

Domox
December 5th, 2007, 09:33 PM
http://poc.psyphon.com

And she works! Thanks to everyone for your insight into the efficiency of copyPixels() :P

ryancameron
February 22nd, 2008, 11:51 PM
I was able to produce this error by adding a bunch of bitmaps to the stage, then overwriting them again and again (on mouse move) eventually the error came up. I fixed it by using this removeChild script so that I was not just adding children overtop like an overwrite, and it seemed to do the trick
removeChildren("clipCommonWordInTheNameOfTheInstances",this);

function removeChildren(precursor:String,container:DisplayO bjectContainer) {
var child:DisplayObject;
for (var i:uint=0; i < container.numChildren; i++) {
child = container.getChildAt(i);
if (child.name.indexOf(precursor) != -1) {
removeChild(child);
}
}
}

ryancameron
February 23rd, 2008, 08:25 AM
Here it is a bit more readable.



function removeChildren(precursor:String,container:DisplayO bjectContainer) {
var child:DisplayObject;
for (var i:uint=0; i < container.numChildren; i++) {
child = container.getChildAt(i);
if (child.name.indexOf(precursor) != -1) {
removeChild(child);
}
}
}