You Are Here:

Community: Developer Discussion Boards

#1 Old canvas.blit - 2006-02-17, 00:39

Join Date: Feb 2006
Posts: 10
mihaicezar
Offline
Registered User
Why two consecutive blits with different images won't work?

The application crashes if I do this:
Code:
canvas.blit(image1)
canvas.blit(image2)
But all is fine with
Code:
canvas.blit(image1)
canvas.blit(image1)
or
Code:
canvas.blit(image2)
canvas.blit(image2)
Thank you in advance.
Cezar
Reply With Quote

#2 Old Re: canvas.blit => design flaw in the _graphics module - 2006-02-18, 02:53

Join Date: Feb 2006
Posts: 10
mihaicezar
Offline
Registered User
Ok, I wish I wasn't the only one to respond to my threads, but I'll continue posting...

I found the answer and we may say it's a design flaw in _graphics. This blit crash appears because:
  • image1 and image2 share a resource
  • image1 is destroyed by the interpreter just after canvas.blit(image1)
Hence image2 is corrupted and the second blit crashes the app.

What resource is involved? It's a bmp:
Code:
bmp = my_graphical_ext.get_bmp()
image1 = Image.from_cfbsbitmap(bmp)
canvas.blit(image1)

my_graphical_ext.update(bmp)
image2 = Image.from_cfbsbitmap(bmp)
canvas.blit(image2) crash...
By destroying image1, Python will go till the end: some CFbsBitmap* iBitmap is destroyed. Therefore, bmp will point to an inexistent object. I do think destroying that CFbsBitmap is not Image's business.

I see 2 solutions:
  1. the clean one: reprogram the Image destructor (is there someone involved in the project who could say a word about that?)
  2. my hack: keeping on using the same image1 until the end. In order to do that, I still need a way to update (redraw) the image after bmp's value was changed. I tried to add an update_bmp method to Image in graphics.py, but obviously I'm not so good, as I can see no screen refresh.

Could someone help me with the second, please? I need at least some hints

Thanks.
Cezar
Last edited by mihaicezar : 2006-02-19 at 00:19.
Reply With Quote

#3 Old Re: canvas.blit - 2006-02-20, 13:23

Join Date: Dec 2004
Posts: 646
jplauril's Avatar
jplauril
Offline
Forum Nokia Expert
Image.from_cfbsbitmap is an undocumented method that was basically meant for internal use, so you're very much in "caveat emptor" territory here. As you said, it assumes ownership of the given CFbsBitmap, and will destroy it when the Image is destroyed. Now on reflection, it might have been a better idea to have that function to allocate its own CFbsBitmap object that shares the bitmap handle with the original one.

However, that code should _not_ crash on that canvas.blit(image2) line. It will crash when image1 and image2 are destroyed, but it shouldn't crash on the blit. What exactly does the my_graphical_ext.update() function do?
Reply With Quote

#4 Old Re: canvas.blit - 2006-02-20, 13:29

Join Date: Dec 2004
Posts: 646
jplauril's Avatar
jplauril
Offline
Forum Nokia Expert
I'd just like to add that this behaviour of from_cfbsbitmap is not set in stone by any means. We can change it to interoperate better with graphical native extensions people do, and make it a part of the "official" API, once we figure out the best way to do it.
Reply With Quote

#5 Old Re: canvas.blit - 2006-02-22, 02:03

Join Date: Feb 2006
Posts: 10
mihaicezar
Offline
Registered User
Quote:
Originally Posted by jplauril
However, that code should _not_ crash on that canvas.blit(image2) line. It will crash when image1 and image2 are destroyed, but it shouldn't crash on the blit. What exactly does the my_graphical_ext.update() function do?
It crashes there because image2 is already corrupted (the CFbsBitmap has just been destroyed, as a collateral effect of image1 automatic destruction).

my_graphical_ext.update() computes the next value of the CFbsBitmap; the values calculated by this extension are consecutive frames of an animation.
Reply With Quote

#6 Old Re: canvas.blit - 2006-02-22, 08:58

Join Date: Dec 2004
Posts: 646
jplauril's Avatar
jplauril
Offline
Forum Nokia Expert
In the code you posted, image1 should not get destroyed. Is that the actual code you used or is there something else?

By the way, couldn't you just reuse the same CFbsBitmap, and draw any changes you need into it in my_graphical_ext.update()?
Reply With Quote

#7 Old Re: canvas.blit - 2006-02-22, 23:15

Join Date: Feb 2006
Posts: 10
mihaicezar
Offline
Registered User
Indeed, all works fine if I keep working with the same image.

I still think image1 was destroyed at that point because, after modifying the ~ImageObject() in _graphics, the 2-image code finally worked.
Code:
if(!iFromFbsBitmap) //my change. Init iFromFbsBitmap in ConstructL!
    delete iBitmap;
Conclusions:
- don't share the bmp (try rather to reuse the image);
- if you do so (or if you just want to offer your own bmp destructor), modify the image destructor in _graphics.pyd.

Thank you, jplauril, for your suggestions.
Cezar
Last edited by mihaicezar : 2006-02-23 at 01:04.
Reply With Quote

#8 Old Re: canvas.blit - 2006-02-23, 12:45

Join Date: Dec 2004
Posts: 646
jplauril's Avatar
jplauril
Offline
Forum Nokia Expert
My point is: image1 should _not_ get destroyed at that second blit line. If it does, there's something seriously wrong.

If you have two Image objects that share a CFbsBitmap then obviously that will lead to a crash when both of them are destroyed, but it shouldn't crash on that blit line.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia