Re: DrawContext -- reports on self?
[email protected] Mon, 29 Aug 2011 04:29:09 +0000
| Newsgroups | gmane.comp.video.graphicsmagick.apis |
|---|---|
| Message-ID | <[email protected]> |
On Sun, Aug 28, 2011 at 11:24:27PM -0500, Bob Friesenhahn wrote: > On Mon, 29 Aug 2011, [email protected] wrote: >> Hrmm... so I should: >> >> DrawContext *dc; >> dc=DrawAllocateContext(); /* like this? */ > > No, because DrawContext is already a pointer. > >> I was having a tough time w/ leaks and core dumps w/ my various attempts... am currently: >> >> DrawContext dc; >> dc=DrawAllocateContext(); /* this is leak-free, crash-free */ > > Looks better. > >> but my tests: if(!dc) { // no draw context... } were not working like I expected. > > It seems like that should work. However, if the DrawContext is not > immediately allocated via DrawAllocateContext(), then it is safest to > allocate it like > > DrawContext dc = (DrawContext) NULL; > > so it has a known initial value. Also, if you destroy and re-use the > same context, then it could have a pointer value for the previously > destroyed context since DrawDestroyContext() does not change the passed > pointer value. ^--- this might have been what stung me. I'll work with what you've described here; I was initializing to NULL until I had an image (otherwise fails w/ assert()), but was probably expecting more w/ the Destroy()... and was a bit confused by it's pointerness, but not stored in a pointer. I saw the MagickMalloc() (might be wrongname) and freeing... but didn't fully understand how to treat the handle. Thanks for the reply :) -bch > A complex example (which is part of the test suite) may be seen in > Mercurial at > > http://graphicsmagick.hg.sourceforge.net/hgweb/graphicsmagick/graphicsmagick/file/775816effda4/tests/drawtest.c > > This one does not have leaks or crash. > > Bob > -- > Bob Friesenhahn > [email protected], http://www.simplesystems.org/users/bfriesen/ > GraphicsMagick Maintainer, http://www.GraphicsMagick.org/ -- Brad Harder Method Logic Digital Consulting http://methodlogic.net/ http://twitter.com/bcharder ------------------------------------------------------------------------------ EMC VNX: the world's simplest storage, starting under $10K The only unified storage solution that offers unified management Up to 160% more powerful than alternatives and 25% more efficient. Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev