Using PmMem Functions

Hello all,

I am trying to use the PmMem funcs. to draw a square pixel by pixel,
then display the whole image when it’s complete. I tried to follow the
steps exactly as described in the Programmer’s Guide and the Library
Reference, but I keep getting a memory fault when I run the program,
even though I get no compiler errors.

Here is the code I’ve written:
int success, i, j ;
PmMemoryContext_t *mc ;
PhImage_t *image ;
PhDim_t *dim ;

typedef struct Ph_point {
short x, y;
} PhPoint_t ;

typedef struct Ph_rect {
PhPoint_t ul, lr;
} PhRect_t;

PhPoint_t points[64], offset[1];

image->type = Pg_IMAGE_DIRECT_888 ;
image->size = *dim ;
(*dim).w = 64 ;
(*dim).h = 64 ;
for ( i = 0 ; i < 64; i++) {
points_.x = i+5 ;
points.y = i+5 ;
}
offset[0].x = 0 ;
offset[0].y = 0 ;
mc = PmMemCreateMC (image, dim, offset) ;

PmMemStart (mc) ;
for (i=1; i < 65 ; i++){
for (j=1; j < 65; j++){
PgSetFillColor (Pg_WHITE);
success = PgDrawIRect (i, j, i, j, Pg_DRAW_FILL);
}
}

PmMemFlush (mc, image) ;
PmMemStop (mc) ;
PmMemReleaseMC (mc);

I am very new to this application, so if anyone sees what I’m going
wrong or can help explain how I should do this, I’d be very appreciative
of the help.

Thanks,
Shannon_

Hi Shannon,

I have spoken to the developer and there are a couple of places where
you could be passing NULL, which could cause your memory fault:

Hope it helps
Regards
Brenda

a-cherian@northwestern.edu wrote:

Hello all,

I am trying to use the PmMem funcs. to draw a square pixel by pixel,
then display the whole image when it’s complete. I tried to follow the
steps exactly as described in the Programmer’s Guide and the Library
Reference, but I keep getting a memory fault when I run the program,
even though I get no compiler errors.

Here is the code I’ve written:
int success, i, j ;
PmMemoryContext_t *mc ;
PhImage_t *image ;
PhDim_t *dim ;

unitialized pointer, probably pointing to NULL

typedef struct Ph_point {
short x, y;
} PhPoint_t ;

typedef struct Ph_rect {
PhPoint_t ul, lr;
} PhRect_t;

PhPoint_t points[64], offset[1];

image->type = Pg_IMAGE_DIRECT_888 ;
image->size = *dim ;
(*dim).w = 64 ;
(*dim).h = 64 ;

using unitialized pointer, probably pointing to NULL, dereference NULL
get a crash

for ( i = 0 ; i < 64; i++) {
points> .x = i+5 ;
points> .y = i+5 ;
}
offset[0].x = 0 ;
offset[0].y = 0 ;
mc = PmMemCreateMC (image, dim, offset) ;

PmMemStart (mc) ;
for (i=1; i < 65 ; i++){
for (j=1; j < 65; j++){
PgSetFillColor (Pg_WHITE);
success = PgDrawIRect (i, j, i, j, Pg_DRAW_FILL);
}
}

PmMemFlush (mc, image) ;
PmMemStop (mc) ;
PmMemReleaseMC (mc);

I am very new to this application, so if anyone sees what I’m going
wrong or can help explain how I should do this, I’d be very appreciative
of the help.

Thanks,
Shannon