Skip to content

Commit

Permalink
fix #6077 redux
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed Nov 14, 2018
1 parent 957787a commit f17149d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions rts/System/Platform/WindowManagerHelper.cpp
Expand Up @@ -2,25 +2,26 @@

#include "WindowManagerHelper.h"

#include <string>
#include <SDL_video.h>

#include "Game/GameVersion.h"
#include "Rendering/GlobalRendering.h"
#include "Rendering/Textures/Bitmap.h"
#include "System/Log/ILog.h"
#include "Game/GameVersion.h"


namespace WindowManagerHelper {

struct WindowIcon {
CBitmap bmp;
SDL_Surface* surf;
};
// do not rely on static (de)init, pool might not yet exist or be destructed first
uint8_t bmpMem[sizeof(CBitmap)] = {0};

static WindowIcon windowIcon = {{}, nullptr};
CBitmap* bmp = nullptr;
SDL_Surface* surf = nullptr;
};


// LuaUnsyncedCtrl only
void SetIcon(CBitmap* bmp) {
if (SpringVersion::IsHeadless())
return;
Expand All @@ -43,13 +44,17 @@ void SetIcon(CBitmap* bmp) {


bool SetIconSurface(SDL_Window* win, CBitmap* bmp) {
static WindowIcon windowIcon;

if (windowIcon.bmp == nullptr)
windowIcon.bmp = new (windowIcon.bmpMem) CBitmap();

if (bmp == nullptr) {
// only reached on exit
SDL_FreeSurface(windowIcon.surf);
SDL_SetWindowIcon(win, windowIcon.surf = nullptr);

// do not rely on static deinit, pool might be destructed first
windowIcon.bmp = CBitmap{};
*(windowIcon.bmp) = {};
return false;
}

Expand All @@ -64,7 +69,7 @@ bool SetIconSurface(SDL_Window* win, CBitmap* bmp) {
SDL_FreeSurface(windowIcon.surf);
SDL_SetWindowIcon(win, windowIcon.surf = surf);

windowIcon.bmp = std::move(*bmp);
*(windowIcon.bmp) = std::move(*bmp);
return true;
}

Expand Down

0 comments on commit f17149d

Please sign in to comment.