pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

Accessing pixels of RLE surface with alpha after blitting causes color key to leak

Open marcin-serwin opened this issue 1 week ago • 7 comments
trafficstars

Environment:

If possible, please include the output of pygame.print_debug_info() from your program in your bug report. It looks something like this:

pygame-ce 2.5.6 (SDL 2.32.56, Python 3.13.8)
Platform:		Linux-6.17.7-x86_64-with-glibc2.40
System:			Linux
System Version:		#1-NixOS SMP PREEMPT_DYNAMIC Sun Nov  2 13:18:05 UTC 2025
Processor:			SSE2: Yes	AVX2: Yes	NEON: No
Architecture:		Bits: 64bit	Linkage: ELF

Python:			CPython 3.13.8 (main, Oct  7 2025, 12:01:51) [GCC 14.3.0]
GIL Enabled:		True
pygame version:		2.5.6
SDL versions:		Linked: 2.32.56	Compiled: 2.32.56
SDL Mixer versions:	Linked: 2.8.1	Compiled: 2.8.1
SDL Font versions:	Linked: 2.24.0	Compiled: 2.24.0
SDL Image versions:	Linked: 2.8.8	Compiled: 2.8.8
Freetype versions:	Linked: 2.13.3	Compiled: 2.13.3

Display Driver:		Display Not Initialized
Mixer Driver:		Mixer Not Initialized

I've also tested with SDL 2.30.6 and sdl2-compat 2.30.58 and the results are consistent.

Current behavior:

If you have a surface with alpha, color key, and RLE acceleration then after blitting and accessing its pixels the color becomes visible.

Expected behavior:

Blitting and accessing RLE surfaces should not change their pixels.

Steps to reproduce:

  1. Run the code below.
  2. Look at the produced test.png

The image will be reddish. If you either disable RLEACCEL, comment out blit or get_at then the image is white.

Test code

import pygame

surf = pygame.Surface((100, 100))
surf.fill((255, 255, 255))
surf.set_colorkey((128, 0, 0))

surf.set_alpha(90, pygame.RLEACCEL)

dest_surf = pygame.Surface((100, 100))
dest_surf.blit(surf, (0, 0))

surf.get_at((50, 50))

pygame.image.save(surf, "test.png")

marcin-serwin avatar Nov 08 '25 18:11 marcin-serwin