I’m using SDL 2.32.8.0 and calling:
SDL_Surface* pIcon = IMG_Load("icon64.png");
if (pIcon != NULL)
{
SDL_SetWindowIcon(g_Window, pIcon);
SDL_FreeSurface(pIcon);
}
My icon is set in the top left of the window, but not in the taskbar. I think this used to work but at some point seems to have stopped working?
Are you using Wayland by any chance?
See SDL3/README-wayland - SDL Wiki
Mik
August 25, 2025, 5:24pm
3
I tested SDL_SetWindowIcon() on Windows and Linux Mint with SDL 2.32.8 and it works.
But I am not using wayland.
I’m on Windows and using Visual Studio. My 64x64 .png icon appears in the window’s application icon at the top left, but not in the taskbar at the bottom of the screen.
Mik
August 27, 2025, 5:48pm
5
I can reproduce the same issue but it seems that you forgot an event handling.
Here is a short example
void test_main(void) {
SDL_RWops* pSDLStreamPointer;
SDL_Surface *pSurface;
SDL_Window *pWindow = NULL;
SDL_Event Event;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) == 0) {
pWindow = SDL_CreateWindow("hello sdl2",50,50,640,480,0);
if (pWindow != NULL) {
pSDLStreamPointer = SDL_RWFromMem((void*)badsmile_bmp,sizeof(badsmile_bmp));
if (pSDLStreamPointer != NULL) {
pSurface = SDL_LoadBMP_RW(pSDLStreamPointer,1); // Surface from Stream
if (pSurface != NULL) {
SDL_SetWindowIcon(pWindow,pSurface);
while (1) {
// A little event handling :-)
while (SDL_PollEvent(&Event) != 0) {
}
SDL_Delay(100);
}
}
}
}
}
}
Can you post the PNG here (or privately email it to me, if you prefer: icculus@icculus.org ) ? I don’t think any of this code has changed in a long time in SDL2, but I’ll take a look at it.
This is the png file, but I’m not sure that’s the problem as I get the same issue with all of my other games too.
I’m using:
SDL2 2.32.8.0
SDL2_image 2.8.8.0
Mik
August 28, 2025, 10:09am
8
As already mentioned, I only get the icon displayed in the upper left corner of the window if I remove the event handling.
Does your main loop handle events?
I get the icon displayed in the top left corner - that isn’t the problem! It doesn’t appear in the taskbar
Mik
August 28, 2025, 10:30am
10
Sorry my english is so bad:
I get the icon displayed in the top left corner if I remove the event handling
I get the icon displayed in the top left corner and in the taskbar if the event handling is in use.
Ah sorry, as soon as I posted I realised I’d misunderstood you! My code has a loop like this:
// loop
while (!bQuit)
{
if (SDL_WaitEvent(&event))
{
switch (event.type)
{
Mik
August 28, 2025, 10:35am
12
OK, I will try my code with SDL_WaitEvent(&event) instead of SDL_PollEvent(&event).
Mik
August 28, 2025, 10:53am
13
SDL_WaitEvent(&event) and SDL_PollEvent(&event) works both for me.
My code does not use SDL2_image. So my surface for the icon is generated from a bitmap.
OK, I’ve gone through the start up code in my game and commented things out and found that if I comment out just this line:
mixChunk = Mix_LoadWAV(szPathWithExtension);
the icon will appear in the taskbar.
Weird!
BTW I mostly load .ogg sound files and I have SDL_mixer 2.6.3.0
Calling SDL_SetWindowIcon after I have loaded all of my sound files fixes the issue and I now get the icon in the taskbar!
Something else strange I’ve noticed is if I set up a breakpoint in Visual Studio after calling SDL_SetWindowIcon but before the loop starts, and then get VS to continue, no taskbar icon appears.
It’s as if hitting a breakpoint, or loading a sound file, eats up the Windows message SDL_SetWindowIcon has added to the queue?
Mik
August 28, 2025, 11:59am
17
Oh, this sounds a little bit “dangerous”.I also installed the SDL mixer 2.6.3.0. However, it makes no difference for me whether I load the wav file before SDL_SetWindowIcon or after. It works both for me.
My test code:
void test_main(void) {
SDL_RWops* pSDLStreamPointer;
SDL_Surface *pSurface;
SDL_Window *pWindow = NULL;
SDL_Event Event;
Mix_Chunk *mixChunk;
const char * wavfile = “sound_nut.wav”;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) == 0) {
if (Mix_OpenAudio(44100,AUDIO_S16,2,8192) == 0) {
SDL_Log("Mix_OpenAudio OK");
} else {
SDL_Log("Mix_OpenAudio Error: %s",SDL_GetError());
}
pWindow = SDL_CreateWindow("hello sdl2",50,50,640,480,0);
if (pWindow != NULL) {
pSDLStreamPointer = SDL_RWFromMem((void*)badsmile_bmp,sizeof(badsmile_bmp));
if (pSDLStreamPointer != NULL) {
pSurface = SDL_LoadBMP_RW(pSDLStreamPointer,1); // Surface from Stream erzeugen
if (pSurface != NULL) {
SDL_SetWindowIcon(pWindow,pSurface);
// Loading sound chunk after SDL_SetWindowIcon()
mixChunk = Mix_LoadWAV(wavfile);
if (mixChunk != NULL) {
SDL_Log("WAV Chunk OK");
} else {
SDL_Log("Mix_LoadWAV failed, error: %s",SDL_GetError());
}
while (1) {
SDL_WaitEvent(&Event);
SDL_Log("an event: %u",SDL_GetTicks());
}
}
}
}
}
}
jbl4ir
August 31, 2025, 4:43pm
18
I noticed the taskbar icon wasn’t showing for my application, found this thread, and can confirm that initializing sdl_mixer and loading my audio files before setting the window icon works around the problem. I’m using SDL 3.2.20 and a recent version of SDL mixer.
slouken
August 31, 2025, 10:37pm
19
Can you report an issue on GitHub?
New Issue
Please include a minimal example to demonstrate the problem and provide information about the version of OS you’re using.
Thanks!