Deleting a carver object
Forum » General / Help requests » Deleting a carver object
Started by: Andi (guest)
On: 1238782152|%e %b %Y, %H:%M %Z|agohover
Number of posts: 5
rss icon RSS: New posts
Summary:
Other ways to delete a carver object?
Deleting a carver object
Andi (guest) 1238782152|%e %b %Y, %H:%M %Z|agohover

Hi,

we use the LQR in an image plugin of the digiKam image editor (well we are writing a plugin at the moment).

The problem is that we have a crash when the plugin is finishing. This is due to the way we assign the image data to the carver. The data comes from a DImg object (digikam image object) that holds the data.
We pass the pointer to the carver, but after the carver is destroyed by the appropriate function call, the DImg object crashes in the destructor because it tries to free the data (which has already been done by the carver).

My actual question is: do we need to call this destroy method or will it be enough to just do "delete carver;" in the destructor of the plugin?
If not, we need to do a deep copy of the image data first (like we do now) and provide this copy to the carver object. But this is not very efficient of course.

Andi

unfold Deleting a carver object by Andi (guest), 1238782152|%e %b %Y, %H:%M %Z|agohover
Re: Deleting a carver object
UnNeuroneUnNeurone 1238785568|%e %b %Y, %H:%M %Z|agohover

Hi,

in fact, the library contructor expects to receive a copy of the image, since it manipulates the buffer internally (e.g. it may actually free and reallocate memory for it many times, not only when calling the destuctor). Also, calling the carver destructor method is necessary, since there are a number of other internal structures which need to be freed. So the way in which you're doing things now is the right one.

I know that passing a copy is not very efficient, particularly in terms of memory managment, however this has the benefit to ensure that, if there's an error at some point, the orignal image is left untouched.

Of course, this benefit would not hold if the DImg object you're manipulating is itself a copy instead of a reference (I'd be surprised, but I don't know that). From the library point of view, the only workaround in such case would actually be to hold a copy internally, since as I wrote above it needs to be able to reallocate the internal buffer (consider for example that at each carving operation the image is actually enlarged, and therefore it requires more memory), so this solution would of course be as much inefficient as copying it beforehand. Therefore, I don't think there's a way out of this (but suggestions are welcome if you have any).

BTW I am glad to know that you're using the library in digiKam.

unfold Re: Deleting a carver object by UnNeuroneUnNeurone, 1238785568|%e %b %Y, %H:%M %Z|agohover
Re: Deleting a carver object
Andi (guest) 1238792649|%e %b %Y, %H:%M %Z|agohover

Ok, I guessed so… :-)
We will be using your library some day, right now we only have received patches for a plugin. It is not used officially. We need to fix a lot of code before it can be used :-)
I will tell the other devs that the way we are doing it know is the right one.
Thanks for your answer!!!

Best,

Andi

unfold Re: Deleting a carver object by Andi (guest), 1238792649|%e %b %Y, %H:%M %Z|agohover
Re: Deleting a carver object
UnNeuroneUnNeurone 1239270768|%e %b %Y, %H:%M %Z|agohover

I've been thinking a little bit more about this issue and maybe I have an idea about how the library could handle the buffer which is passed to it in a non-destructive way. I'll keep you updated.

unfold Re: Deleting a carver object by UnNeuroneUnNeurone, 1239270768|%e %b %Y, %H:%M %Z|agohover
Re: Deleting a carver object
UnNeuroneUnNeurone 1239277522|%e %b %Y, %H:%M %Z|agohover

Ok, I think I made it. I have introduced a new function:

void lqr_carver_set_preserve_input_image(LqrCarver * carver)

it must be called right after the carver object creation, and it should ensure that your image data is left untouched by the lqr library (hopefully).
You can pull the new version from the git repo, master branch.
The manual is also updated there.

unfold Re: Deleting a carver object by UnNeuroneUnNeurone, 1239277522|%e %b %Y, %H:%M %Z|agohover
New post
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License