Michael Briggs
|
RE: cleaning up an img_t* in C++
|
Michael Briggs
02/25/2011 8:05 AM
post83491
|
RE: cleaning up an img_t* in C++
Derek -
Thanks for the sample. It worked perfectly...and helped demonstrate my lack of deep understanding of the img_t
structure. :-)
I made a cleanup function that passes in an img_t* item, runs your code, then deletes the img_t* item.
- Mike
-----Original Message-----
From: Derek Leach [mailto:community-noreply@qnx.com]
Sent: Wednesday, February 23, 2011 1:20 PM
To: advanced-graphics
Subject: RE: cleaning up an img_t* in C++
try this:
if (img->flags & IMG_DIRECT) {
free(img->access.direct.data);
img->flags &= ~IMG_DIRECT;
if (img->flags & IMG_PALETTE) {
img->flags &= ~IMG_PALETTE;
}
} else if (img->flags & IMG_PALETTE) {
free(img->palette);
img->flags &= ~IMG_PALETTE;
}
-----Original Message-----
From: Michael Briggs [mailto:community-noreply@qnx.com]
Sent: February 23, 2011 1:09 PM
To: advanced-graphics
Subject: cleaning up an img_t* in C++
So, i've been working with the IMG library in C++ and I'm working on
closing down memory leaks.
The way i've been creating my img_t objects is:
img_t* OrigImage = new img_t();
This works well enough until I start doing my house cleaning:
if (OrigImage->access.direct.data != NULL) {
delete OrigImage->access.direct.data;
}
if (OrigImage->palette != NULL) {
delete OrigImage->palette;
}
delete OrigImage;
This code works pretty good, except when there's palette
information...and then it crashes.
So, anybody know a better way to fully clean up an img_t* ?
_______________________________________________
Advanced Graphics
http://community.qnx.com/sf/go/post83429
_______________________________________________
Advanced Graphics
http://community.qnx.com/sf/go/post83432
|
|
|
Reza Salehi
|
Re: RE: cleaning up an img_t* in C++
|
Reza Salehi
05/24/2011 8:13 PM
post86102
|
Re: RE: cleaning up an img_t* in C++
Hi Derek,
I have a question with regard to img_t but in regard to who is allocating memory for access.direct.data pointer when
using setting the IMG_DIRECT flag? Will the img_load_file() allocate memory for it?
I am trying to read a .png file, make some modification to the file and then save it as new .png file. However, when I
set the IMG_DIRECT flag, my system hangs. If I don't set the IMG_DIRECT flag, the file is loaded correctly.
I am using QNX 6.4.1 on the host and the same version running on a VM target.
I appreciate it if you can give me pointer on where the problem could be.
Thanks,
RS.
|
|
|