Skip to main content
Lorenzo Nuvoletta
Inspiring
June 19, 2013
Answered

isValid parameter in BitmapData

  • June 19, 2013
  • 2 replies
  • 2314 views

Hi,

I am not sure if this has been asked before, but would it be hard to add an isValid parameter to BitmapData?

currently this is what I have to do to figure it out:

try {  myBitmapData.width; }

catch (e:Error) { return; }

Unless I am missing something and there is already something to help me out.

Thanks.

This topic has been closed for replies.
Correct answer Lorenzo Nuvoletta

That works if a BitmapData is null, not if it has been disposed.

2 replies

Jeff__Ward
Inspiring
July 1, 2013

Hmm, I'm honestly not sure why BitmapData.dispose() exists - does it free memory faster than nullifying the reference and waiting for garbage collection?  I suppose if you're in a tight loop of bitmap creation and destruction, maybe there's a use for it.

Since .dispose does exist, it creates this odd circumstance.  Since you can't construct a bitmap with an invalid width or height (like 0), it seems .dispose() is the only way to have an "invalid" bitmap.  And I assume the typical usage is dispose and clear your reference.  Holding the reference seems useless once disposed...

Bottom line - meh.  I don't understand how .isValid would be very useful, and try/catch is a perfectly valid workaround.

Lorenzo Nuvoletta
Inspiring
July 1, 2013

Imagine the case where you have passed a BitmapData as a dependency to another class and the reference of that new class is inaccessible, then at one point in the class generator you dispose the BitmapData but you have no way of telling the class that holds the dependency to nullify it, you now have a BitmapData that is disposed but not null and you don't have anyway to check for that other than performing an expensive try catch.

User Unknow
Legend
June 29, 2013

BitmapData.width can't be accessed before BitmapData instance created. So use

if ( myBitmapData ) {

      doSomething();

} else {

     return;

}

Lorenzo Nuvoletta
Lorenzo NuvolettaAuthorCorrect answer
Inspiring
June 29, 2013

That works if a BitmapData is null, not if it has been disposed.

User Unknow
Legend
June 29, 2013

Now I understand.

https://bugbase.adobe.com/index.cfm?event=bug&id=3587403 please add your vote there