Hi Madhur,

Thanks for your email.

The way you have used the PNGwriter constructor seems ok to me, what would be really useful is a backtrace from the point where the program crashes.

Ah! Wait a second, I have just read your follow-up (the email I'm replying to now) and I'm a bit puzzled. Indeed, your program crashes on my machine as well (OS X 10.3).

A few things to note:

int main (int argc, char **argv) {

        int i=0, j=0, k=0, col=0;
int dcol_r=0xffff/NCOL_R, dcol_g=0xffff/NCOL_G, dcol_b=0xffff/NCOL_B;
        long int pixel;
        pngwriter image (w, h, 0, output_file_name);
//0.3 0.3 1 0.5 0.5 30 10 output_file_name
if (argc<9) { cout<<"USAGE: julia_xpm cr ci zoom creal cimg w hmax_itr output_file_name\n"; return 0; }
        cr=atof (argv[1]);
        ci=atof (argv[2]);
        zoom=atof (argv[3]);
        creal=atof (argv[4]);
        cimg=atof (argv[5]);
        w=atoi (argv[6]);
        h=atoi (argv[7]);
        max_itr=atoi (argv[8]);
        output_file_name=argv[9];
        cout<<"Arguments read successfully\n";

You set the user-supplied values for width and height *after* the pngwriter constructor is called. I haven't checked if you resize the image later but it is worth noting. w and h have default values so this shouldn't be a critical problem.

In fact, I removed all mention of PNGwriter from your code and it still crashes. Am I correct in assuming then that this is not a PNGwriter-related bug? If that is the case, I'm as stumped as you are, and I'm definitely no code guru. You might want to take this issue to a C++ list. If you do figure it out, I'd be interested in knowing what was wrong.


Best of luck.

Paul



On 2 Aug 2005, at 19:20, Madhur Kashyap wrote:

Hi Paul,

After struggling for some more time I found the reason behind the
problem. I did not expect this to be the problem. If possible for you
please clarify the reason because I am unaware of any such thing.

While cruising the code through gdb the code used to crash as soon as
I step into the main() function. After removing every single compile
time option and extra piece of code,  I found out that the error was
because of creating an array of a structure (size 3 ints) of large
number of elements. Look at the code snippet at the end of email....

MAX_COLORS=16777216 in the code.
I modified the code to initialize the array as

color color_palette[100000];

and looped within bounds of array no problem. But with no. of
elem=1000000 the program again started crashing with wierd output at
gdb. I have earlier tried running a similar code to dump images in XPM
format but with vector class rather than arrays.  That used to work
like anything.

If possible please help me understand the reason behind this problem
so that I can avoid it in future.

Thanks & Sincerely,
Madhur Kashyap

Code Snippet
===========
 // Define 24-bit true colors
#define NCOL_R 256
#define NCOL_G 256
#define NCOL_B 256
#define MAX_COLORS NCOL_R*NCOL_G*NCOL_B

struct color {
        int red, green, blue;
};


        // create color palette
        color color_palette[MAX_COLORS]; <<<<<<< ERROR because of this.
        for (i=0; i<NCOL_R; i++) {
                for (j=0; j<NCOL_G; j++) {
                        for (k=0; k<NCOL_B; k++) {
                                color_palette[col].red=0xffff-dcol_r*i;
                                color_palette[col].green=0xffff-dcol_g*j;
                                color_palette[col].blue=0xffff-dcol_b*k;
                                col++;
                        }
                }
        }




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
http://pngwriter.sourceforge.net/
PNGwriter-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pngwriter-users

Reply via email to