From 46b89686df06102af64454bc7b2e722c1ff16927 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Mon, 15 Jun 2020 19:05:34 +0200 Subject: Allow using an Fl_SVG_Image object as window icon. Fix for issue #90: Setting an svg image as a window icon causes a segfault. --- src/Fl_SVG_Image.cxx | 6 ++++++ src/Fl_cocoa.mm | 1 + src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx | 4 +++- src/drivers/X11/Fl_X11_Window_Driver.cxx | 4 +++- 4 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Fl_SVG_Image.cxx b/src/Fl_SVG_Image.cxx index c4c593d0a..c76bc962b 100644 --- a/src/Fl_SVG_Image.cxx +++ b/src/Fl_SVG_Image.cxx @@ -266,6 +266,12 @@ void Fl_SVG_Image::color_average(Fl_Color c, float i) { Fl_RGB_Image::color_average(c, i); } +/** Makes sure the object is fully initialized. + This function rasterizes the SVG image if that was not done before. */ +void Fl_SVG_Image::normalize() { + if (!array) resize(w(), h()); +} + #endif // FLTK_USE_NANOSVG // diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 31f5bd08e..8d09c8759 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -4516,6 +4516,7 @@ void Fl_Cocoa_Window_Driver::icons(const Fl_RGB_Image *icons[], int count) { [icon_image release]; icon_image = nil; if (count >= 1 && pWindow->border() && pWindow->label() && strlen(pWindow->label())) { + ((Fl_RGB_Image*)icons[0])->normalize(); icon_image = rgb_to_nsimage(icons[0]); } } diff --git a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx index fb449754e..09b677fff 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx @@ -379,8 +379,10 @@ void Fl_WinAPI_Window_Driver::icons(const Fl_RGB_Image *icons[], int count) { icon_->icons = new Fl_RGB_Image*[count]; icon_->count = count; // FIXME: Fl_RGB_Image lacks const modifiers on methods - for (int i = 0;i < count;i++) + for (int i = 0;i < count;i++) { icon_->icons[i] = (Fl_RGB_Image*)((Fl_RGB_Image*)icons[i])->copy(); + icon_->icons[i]->normalize(); + } } if (Fl_X::i(pWindow)) diff --git a/src/drivers/X11/Fl_X11_Window_Driver.cxx b/src/drivers/X11/Fl_X11_Window_Driver.cxx index 4996b3e0f..50a013ba6 100644 --- a/src/drivers/X11/Fl_X11_Window_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Window_Driver.cxx @@ -356,8 +356,10 @@ void Fl_X11_Window_Driver::icons(const Fl_RGB_Image *icons[], int count) { icon_->icons = new Fl_RGB_Image*[count]; icon_->count = count; // FIXME: Fl_RGB_Image lacks const modifiers on methods - for (int i = 0;i < count;i++) + for (int i = 0;i < count;i++) { icon_->icons[i] = (Fl_RGB_Image*)((Fl_RGB_Image*)icons[i])->copy(); + icon_->icons[i]->normalize(); + } } if (Fl_X::i(pWindow)) -- cgit v1.2.3