Re: DrawContext -- reports on self?
Bob Friesenhahn <[email protected]> Sun, 28 Aug 2011 23:24:27 -0500 (CDT)
| Newsgroups | gmane.comp.video.graphicsmagick.apis |
|---|---|
| Message-ID | <[email protected]> |
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. 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/ ------------------------------------------------------------------------------ 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