@@ -739,8 +739,8 @@ void glColorTableEXT( int target, int empty1, u16 width, int empty2, int empty3,
739739 if ( texture -> palIndex ) // Remove prior palette if exists
740740 removePaletteFromTexture ( texture );
741741
742- // Exit if no color table or color count is 0 (helpful in emptying the palette for the active texture)
743- if ( !width || table == NULL )
742+ // Exit if color count is 0 (helpful in emptying the palette for the active texture)
743+ if ( !width )
744744 return ;
745745
746746 // Allocate new palette block based on the texture's format
@@ -776,6 +776,19 @@ void glColorTableEXT( int target, int empty1, u16 width, int empty2, int empty3,
776776 palette -> connectCount = 1 ;
777777 palette -> palSize = width << 1 ;
778778
779+ if ( glGlob -> deallocPalSize )
780+ texture -> palIndex = (u32 )DynamicArrayGet ( & glGlob -> deallocPal , glGlob -> deallocPalSize -- );
781+ else
782+ texture -> palIndex = glGlob -> palCount ++ ;
783+ DynamicArraySet ( & glGlob -> palettePtrs , texture -> palIndex , (void * )palette );
784+
785+ GFX_PAL_FORMAT = palette -> addr ;
786+ glGlob -> activePalette = texture -> palIndex ;
787+
788+ // allocate, but don't touch VRAM if table is NULL
789+ if ( table == NULL )
790+ return ;
791+
779792 // copy straight to VRAM, and assign a palette name
780793 u32 tempVRAM = VRAM_EFG_CR ;
781794 u16 * startBank = vramGetBank ( (u16 * )palette -> vramAddr );
@@ -795,15 +808,6 @@ void glColorTableEXT( int target, int empty1, u16 width, int empty2, int empty3,
795808
796809 swiCopy ( table , palette -> vramAddr , width | COPY_MODE_HWORD );
797810 vramRestoreBanks_EFG ( tempVRAM );
798-
799- if ( glGlob -> deallocPalSize )
800- texture -> palIndex = (u32 )DynamicArrayGet ( & glGlob -> deallocPal , glGlob -> deallocPalSize -- );
801- else
802- texture -> palIndex = glGlob -> palCount ++ ;
803- DynamicArraySet ( & glGlob -> palettePtrs , texture -> palIndex , (void * )palette );
804-
805- GFX_PAL_FORMAT = palette -> addr ;
806- glGlob -> activePalette = texture -> palIndex ;
807811 } else
808812 GFX_PAL_FORMAT = glGlob -> activePalette = texture -> palIndex ;
809813 }
0 commit comments