mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
Error if the ImageData given to love.window.setIcon is not a 32 bit RGBA format.
--HG-- branch : minor
This commit is contained in:
@@ -842,6 +842,9 @@ bool Window::setIcon(love::image::ImageData *imgd)
|
|||||||
if (!imgd)
|
if (!imgd)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (imgd->getFormat() != PIXELFORMAT_RGBA8)
|
||||||
|
throw love::Exception("setIcon only accepts 32-bit RGBA images.");
|
||||||
|
|
||||||
icon.set(imgd);
|
icon.set(imgd);
|
||||||
|
|
||||||
if (!window)
|
if (!window)
|
||||||
@@ -862,14 +865,15 @@ bool Window::setIcon(love::image::ImageData *imgd)
|
|||||||
|
|
||||||
int w = imgd->getWidth();
|
int w = imgd->getWidth();
|
||||||
int h = imgd->getHeight();
|
int h = imgd->getHeight();
|
||||||
int pitch = imgd->getWidth() * 4;
|
int bytesperpixel = (int) getPixelFormatSize(imgd->getFormat());
|
||||||
|
int pitch = w * bytesperpixel;
|
||||||
|
|
||||||
SDL_Surface *sdlicon = nullptr;
|
SDL_Surface *sdlicon = nullptr;
|
||||||
|
|
||||||
{
|
{
|
||||||
// We don't want another thread modifying the ImageData mid-copy.
|
// We don't want another thread modifying the ImageData mid-copy.
|
||||||
love::thread::Lock lock(imgd->getMutex());
|
love::thread::Lock lock(imgd->getMutex());
|
||||||
sdlicon = SDL_CreateRGBSurfaceFrom(imgd->getData(), w, h, 32, pitch, rmask, gmask, bmask, amask);
|
sdlicon = SDL_CreateRGBSurfaceFrom(imgd->getData(), w, h, bytesperpixel * 8, pitch, rmask, gmask, bmask, amask);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sdlicon)
|
if (!sdlicon)
|
||||||
|
|||||||
@@ -365,7 +365,9 @@ int w_getPosition(lua_State *L)
|
|||||||
int w_setIcon(lua_State *L)
|
int w_setIcon(lua_State *L)
|
||||||
{
|
{
|
||||||
image::ImageData *i = luax_checktype<image::ImageData>(L, 1);
|
image::ImageData *i = luax_checktype<image::ImageData>(L, 1);
|
||||||
luax_pushboolean(L, instance()->setIcon(i));
|
bool success = false;
|
||||||
|
luax_catchexcept(L, [&]() { success = instance()->setIcon(i); });
|
||||||
|
luax_pushboolean(L, success);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user