| Reply | « Previous Thread | Next Thread » |
|
Why two consecutive blits with different images won't work?
The application crashes if I do this: Code:
canvas.blit(image1) canvas.blit(image2) Code:
canvas.blit(image1) canvas.blit(image1) Code:
canvas.blit(image2) canvas.blit(image2) Cezar |
| mihaicezar |
| View Public Profile |
| Find all posts by mihaicezar |
|
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:
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... I see 2 solutions:
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.
|
| mihaicezar |
| View Public Profile |
| Find all posts by mihaicezar |
|
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? |
|
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.
|
|
Quote:
my_graphical_ext.update() computes the next value of the CFbsBitmap; the values calculated by this extension are consecutive frames of an animation. |
| mihaicezar |
| View Public Profile |
| Find all posts by mihaicezar |
|
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()? |
|
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;
- 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.
|
| mihaicezar |
| View Public Profile |
| Find all posts by mihaicezar |
|
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 | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |