[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

1942.0. "X$STORE_COLOR gives BadAccess" by UTRTSC::JONKER () Tue Dec 19 1989 04:14

Hoi,

I'm having trouble with setting colors in the default color map.
On a 4 planes VS2000 I do a  X$ALLOC_COLOR_CELLS which returns oke.
Next I do a X$STORE_COLOR or COLORS and both return the error ;
 BadAccess - attempt to access private resource
The fortan example in the next reply is an extract from pg 5-14 Gd to Xlib prg
on VAX. Tested on VMS 5.1-1 and 5.2.
Can anyone tell me what's going wrong ?

Thanks, Rob
T.RTitleUserPersonal
Name
DateLines
1942.1Example FTN codeUTRTSC::JONKERTue Dec 19 1989 04:1798
	PROGRAM color_prg
	implicit none
C
C	Includings
C
	INCLUDE 'SYS$LIBRARY:DECW$XLIBDEF'
C
C	Records
C
	RECORD /X$VISUAL/ VISUAL	    ! visual type
	RECORD /X$GC_VALUES/ XGCVL	    ! gc values
	RECORD /X$SIZE_HINTS/ XSZHN	    ! hints
	RECORD /X$COLOR/ COLOR(256)         ! colors
C
 	COMMON /IDS/   	DPY_ID,SCR_ID,GC_ID
	   INTEGER*4    DPY_ID         ! Display  identifier
	   INTEGER*4    SCR_ID         ! Scr_id   identifier
           INTEGER*4    GC_ID          ! Graph char identifier
	   INTEGER*4    CM_ID          ! Colormap identifier
C
	INTEGER*4     FUNC             ! Syncronize function address 
	INTEGER*4     PIXELS(256)      !
	INTEGER*4     PLANE_MASKS(256) !
	INTEGER*4     COLOR_MAP_SIZE
	INTEGER*4     I,count
	INTEGER*4     FONT			! font id
	CHARACTER*60  FONT_NAME
	INTEGER*4     FLAGS
	INTEGER*4     CONTIG
C
C
	CHARACTER*80 CHOICES(4)
	INTEGER*4    CHOICES_LEN(4)
	INTEGER*4    SEL,STATUS
	INTEGER*4    CHOICE
C
C
C	%%%%%%%%%%%%%%% Initialize X windows %%%%%%%%%%%%%%%
C
	DPY_ID = X$OPEN_DISPLAY()
	IF (DPY_ID.EQ.0) THEN
	   WRITE (6,*) 'Display can not be opened'
	   STOP
	END IF
C
C	get screen id
C
	SCR_ID = X$DEFAULT_SCREEN_OF_DISPLAY(DPY_ID)
C
C	enable (1) display syncronisation
C
  	STATUS = X$SYNCHRONIZE(DPY_ID, 1, FUNC)	
C
C	Create colormap
C
	CALL X$DEFAULT_VISUAL_OF_SCREEN(SCR_ID,VISUAL)
	IF (VISUAL.X$L_VISU_CLASS .EQ. X$C_PSEUDO_COLOR .OR.
     +	    VISUAL.X$L_VISU_CLASS .EQ. X$C_DIRECT_COLOR) THEN
C
C	   if color system get size of color map
C
	   CM_ID = X$DEFAULT_COLORMAP_OF_SCREEN(SCR_ID)
	   COLOR_MAP_SIZE 
     +        = X$DISPLAY_CELLS(DPY_ID,
     +                          X$DEFAULT_SCREEN(DPY_ID))
           IF (COLOR_MAP_SIZE.ne.16) THEN
              WRITE (6,*) 'Color system to small'
	      STOP
	   ENDIF
	   STATUS = X$ALLOC_COLOR_CELLS(DPY_ID,      ! display id
     +                                  CM_ID,       ! colormap id
     +                                  CONTIG,      ! Contegious bits
     +                                  PLANE_MASKS, ! return
     +                                  0,           ! number of planes
     +                                  PIXELS,      ! return
     +                                  16)         ! number of colors
	   IF (STATUS.EQ.0) THEN
	      WRITE (6,*) 'Cant allocate color map'
	      STOP
	   ENDIF
        ELSE
           WRITE(6,*) 'No DIRECT or PSUEDO colors possible.'
	   STOP
	ENDIF
C
C
	FLAGS = X$M_DO_RED .OR. X$M_DO_GREEN .OR. X$M_DO_BLUE
	DO I=1,16
	   COLOR(I).X$L_COLR_PIXEL = I-1
	   COLOR(I).X$B_COLR_FLAGS = FLAGS
	   COLOR(I).X$W_COLR_RED   = 0
	   COLOR(I).X$W_COLR_GREEN = 0
	   COLOR(I).X$W_COLR_BLUE  = 0
	ENDDO
	CALL X$STORE_COLOR(DPY_ID,CM_ID,COLOr(5))
c	CALL X$STORE_COLORs(DPY_ID,CM_ID,COLOr(1),i-1)
	STOP
	END
1942.2PSW::WINALSKICareful with that VAX, EugeneTue Dec 19 1989 19:2117
Your problem is this line:

	   COLOR(I).X$L_COLR_PIXEL = I-1

you want to change this to read:

	   COLOR(I).X$L_COLR_PIXEL = PIXELS(I)

X$ALLOC_COLOR_CELLS returns in the PIXELS array the pixel values that have been
allocated to your program.  You then must put one of these values in the
X$L_COLR_PIXEL field of the COLOR structure to tell Xlib which pixel you are
setting the RGB values for.  Your original code was simply setting this field
to an integer in the range 0 to 15, which is is incorrect-- you have to use the
pixel values that X allocated to you.  You got the BadAccess error because one
or more of pixel values 0-15 belonged to somebody else.

--PSW
1942.3X$ALLOC_COLOR_CELL is the one to blaim ?UTRTSC::JONKERWed Dec 20 1989 11:3621
Hoi,

Thanks for your reply, I didn't specify an array because I intend to alloc 
all the 16 possible color indices on the 4 plane system, and since 
X$ALLOC_COLOR_CELL returns succesfully I can use the values 1-16.
  But you pointed me in a nice direction i.e., I looked at the pixels() 
array which I received from the X$ALLOC_COLOR_CELL and all 16 returned values 
where 0 !
If I alloc 8 colorcells then I receive 8 valid pixel values for my application.
Starting at 15,14,13,12,11,10,9,8. Now my X$STORE_COLORS work fine.
With allocating 9 cels I again receive all zero's in the returned pixels()
values. It Seems that it's possible to alloc all the color cells without
an error returned, but if you allocate more the 8 colors then ALL returned
pixel values are zero ! This is strange. The same behavior with FT DECW 2.0.
I can imaging that 2 color cells are reserved for cursor, but not one plane.
( i.e. missing pixel values 7,6,,,1 ).
Is this normal behaviour that allocating color cells from default colormap
is restricted to 8 cells (4 plane) and perhaps 128 ( for 8 plane systems) ?
What am I doing wrong ?

Rob.
1942.4PSW::WINALSKICareful with that VAX, EugeneWed Dec 20 1989 12:5016
RE: .3

It sounds like X$ALLOC_COLOR_CELLS is failing.  Since you're trying to allocate
all 16 colors out of the default colormap on a 4-plane system, I'm not 
surprised.  From the sound of it, there are 8 colormap cells in use on your
system by other applications.

If you want to use 16 different, nonshared colormap cells on a 4-plane system,
then you must use a private colormap.  Be warned that when your private
colormap is installed, other applications will go false colors.  Also note that,
even if you allocate all of the colormap cells, you must still use the PIXELS
array returned by X$ALLOC_COLOR_CELLS to obtain the proper pixel values to
reference those cells.  The pixel values are implementation-dependent and are
not necessarily the numbers 0-15, even on a 4-plane system.

--PSW
1942.5X$C_BAD_ALLOC should be returned ?UTRTSC::JONKERFri Dec 22 1989 03:0913
    Thank you for explaining, especially for the implementation specific
    pixel return values, which was one problem. My other problem was that 
    I expected when alloc color cells returns succesfully, that I've got all 
    the requested color cells for private use. As far as I can see this is
    not the case. You may alloc everything succesfully and have nothing.
    I expected in this case, that X$ALLOC_COLOR_CELLS would return
    X$C_BAD_ALLOC. But it doesn't.  Apparently, you have to test the returned 
    pixel array on all_none_zero values to be sure on a succefull
    allocation.
    
    P.S. I will now use a private cmap in case the default is not sufficient.
    
    Rob
1942.6PSW::WINALSKICareful with that VAX, EugeneFri Dec 22 1989 21:167
RE: .5

The documentation that I have says that X$ALLOC_COLOR_CELLS should return 0 if
it succeeds and a non-zero value otherwise.  The behavior you're seeing sounds
like a bug, if that's indeed what's happening.  I'd QAR it.

--PSW