Mail Archives: djgpp/1999/11/06/01:30:04
From: | Dave Dribin <drib AT enteract DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Allegro 3.12: page fault in generate_optimized_palette()
|
Date: | 6 Nov 1999 06:06:48 GMT
|
Organization: | EnterAct L.L.C. Turbo-Elite News Server
|
Lines: | 94
|
Message-ID: | <800gho$aut$1@eve.enteract.com>
|
NNTP-Posting-Host: | 207.229.143.41
|
User-Agent: | tin/pre-1.4-19990624 ("Dawnrazor") (UNIX) (FreeBSD/3.3-STABLE (i386))
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Hello,
I'm getting a page fault in generate_optimized_palette() using Allegro
3.12 (more info on what I'm trying to do below):
----- crash -----
Exiting due to signal SIGSEGV
Page fault at eip=0009e991, error=0004
eax=000000a8 ebx=00000000 ecx=fffe1a34 edx=00251a34 esi=00270000 edi=0026fffc
ebp=00171178 esp=0017116c program=C:\SRC\GLAUNCH\_gl32.exe
cs: sel=0137 base=104c0000 limit=0026ffff
ds: sel=013f base=104c0000 limit=0026ffff
es: sel=013f base=104c0000 limit=0026ffff
fs: sel=013f base=104c0000 limit=0026ffff
gs: sel=014f base=00000000 limit=0010ffff
ss: sel=013f base=104c0000 limit=0026ffff
App stack: [001727cc..000f27cc] Exceptn stack: [000f26ac..000f076c]
Call frame traceback EIPs:
0x0009e991 ___dj_movedata+37
0x000268f1 _generate_optimized_palette+2713, line 375 of quantize.c
0x00001749 show(char *)+245, line 47 of glmain32.cc
0x00001a8f _main+143, line 147 of glmain32.cc
0x00092306 ___crt1_startup+174
-----
Looking at ling 375 of my modified quantize.c, it's a memcpy():
----- quantize.c + fprintf()'s -----
367 for (i=0; i<rsvdcnt; i++) {
368 for (j=rsvdcnt; j<rsvdcnt+100; j++) { /* +100 should be enough */
369 fprintf(stderr,
370 "i = %d, j = %d, max = %d, [j]=%08x [i]=%08x [j+1]=%08x\n",
371 i, j, max, common[j], common[i], common[j+1]);
372 if ((tmp = compare_cols(common[i], common[j])) == 0) {
373 fprintf(stderr, "%08x %08x %d\n", &common[j], &common[j+1],
374 (max - j) * 4);
375 memcpy(&common[j], &common[j + 1], (max - j) * 4);
376 j--;
377 max--;
378 }
379 }
380 }
-----
Here's the output from the prints I added:
-----
i = 0, j = 40, max = 42, [j]=0000208e [i]=00000000 [j+1]=0000630e
i = 0, j = 41, max = 42, [j]=0000630e [i]=00000000 [j+1]=00000000
i = 0, j = 42, max = 42, [j]=00000000 [i]=00000000 [j+1]=00000000
00251a34 00251a38 0
i = 0, j = 42, max = 41, [j]=00000000 [i]=00000000 [j+1]=00000000
00251a34 00251a38 -4
Shutting down Allegro
Exiting due to signal SIGSEGV
-----
As you can see (max - j) ends up being negative and causing havoc on
the memcpy(). Is this a known problem? Am I using the function
wrong?
Here's what I'm trying to do:
I'm running at a depth of 8-bits. I'd like to reserve about 8 or 9
colors in the palette for stuff that I need. Yet I still would like
to load in and display a 256-color PCX file. I cannot just use the
palette from load_bitmap(), 'cause it clobbers the colors I setup in
the palette. I need to somehow merge the 2 palettes keeping only the
colors that both of them need. After reading the documentation on
generate_optimized_palette(), this souned perfect. Fist problem,
g_o_p() doesn't work on 8-bit images. Doh! So I get this idea of
converting the PCX image to a 16-bit image, use g_o_p() on the new
bitmap, and then bring it back to 8-bit:
bmp = load_bitmap(name, pal);
select_palette(pal);
bmp16 = create_bitmap_ex(16, bmp->w, bmp->h);
blit(bmp, bmp16, 0, 0, 0, 0, bmp->w, bmp->h);
unselect_palette();
i = generate_optimized_palette(bmp16, pal, my_reserved_colors);
set_palette(pal);
blit(bmp16, bmp, 0, 0, 0, 0, bmp->w, bmp->h);
/* Blit somewhere on screen... */
This works just fine and dandy..... until one of the colors I reserve
is black! Then I get the page fault as above. Can I not reserve
black? Any ideas? Is there an easier way to do this? Can I do it at
all? :)
Thanx for any help,
-Dave
- Raw text -