Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / dbGetImageData - shall you free the pData pointer?

Author
Message
Rudolpho
13
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 4th Jun 2012 15:56
After some headscratching I just figured out that the function dbGetImageData's LPSTR pData reference actually is set to the address of the actual image data and not the pixel data directly.


I was wondering if you have to free this (second) memory area after you're done with it or not? Since DGDK doesn't use any const declarations and there's no documentation for the said function it's far from obvious.

Speaking in favor of freeing it is that that's how things usually work - you get a copy of the (private) data returned and not the data itself.
Speaking against it is the fact that you have to lock the affected image's pixels before using the function as well as the fact that an exception (_Block_Type_Is_Valid (pHead->nBlockUse)) is thrown in my face when I try to delete the pointer.
I still believe that it needs to be freed though (maybe through unlocking the images pixels, which I have found no way of doing?); if you change the returned pixel data the changes aren't reflected in the image when rendered or saved to disk anyway.

If somebody could shed some light on this that would be very nice; I don't want to introduce any unneccessary memory leaks.


"Why do programmers get Halloween and Christmas mixed up?"
Dar13
11
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 5th Jun 2012 20:31
Quote: "Speaking in favor of freeing it is that that's how things usually work - you get a copy of the (private) data returned and not the data itself."

I'm not sure about DarkGDK, but in Ogre you have direct access to the image data through a pointer.

Quote: " dbGetImageData's LPSTR pData"

dbGetImageData gives you a pointer to a string? That's peculiar.

Rudolpho
13
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 6th Jun 2012 12:15 Edited at: 6th Jun 2012 12:20
Quote: "dbGetImageData gives you a pointer to a string? That's peculiar."

Not really, it's just a pointer to a byte array, which can hold any data. It would only cause problems if you tried to use it with any string-expecting functions


Anyway, it turns out that the problem lies in the dbGetImageData function allocating the memory on its own heap (since it is called from a dll (using DGDK 2)) and thus cannot be free'd from the "local" heap.
Since the DBProImageDebug dll doesn't provide any method for either giving it a pre-allocated memory pointer that it will just fill, or a function for freeing memory allocated by the dll, there seems to be no way to overcome this type of issue.

For this particular function a work-around can be created using another method from the dll though and basically re-implementing the dbGetImageData function so that it resides on your own heap:



Note that this workaround is only required with DarkGDK 2, in the original edition this function works out of the box.


"Why do programmers get Halloween and Christmas mixed up?"

Login to post a reply

Server time is: 2019-09-16 17:54:57
Your offset time is: 2019-09-16 17:54:57