From 98de2b68055019d20b172d162032e23be2dfbb12 Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Fri, 19 Dec 2003 02:09:01 +0000 Subject: [PATCH] Always let (deprecated) FindColour() return a new instance of a found colour, because otherwise multiple calls to FindColour() will share the same wxColour; Added a wxLogDebug message when FindColour() is used because it shouldn't be used without modifying user-code probably (Returned wxColours must now be released). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24920 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/gdicmn.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/common/gdicmn.cpp b/src/common/gdicmn.cpp index cdff69b2fd..ac407e93d9 100644 --- a/src/common/gdicmn.cpp +++ b/src/common/gdicmn.cpp @@ -473,6 +473,15 @@ wxString wxColourDatabase::FindName(const wxColour& colour) const wxColour *wxColourDatabase::FindColour(const wxString& name) { + // This function is deprecated, use Find() instead. + // Formerly this function sometimes would return a deletable pointer and + // sometimes a non-deletable one (when returning a colour from the database). + // Trying to delete the latter anyway results in problems, so probably + // nobody ever freed the pointers. Currently it always returns a new + // instance, which means there will be memory leaks. + wxLogDebug(wxT("wxColourDataBase::FindColour():") + wxT(" Please use wxColourDataBase::Find() instead")); + // using a static variable here is not the most elegant solution but unless // we want to make wxStringToColourHashMap public (i.e. move it to the // header) so that we could have a member function returning @@ -481,13 +490,14 @@ wxColour *wxColourDatabase::FindColour(const wxString& name) // // and knowing that this function is going to disappear in the next release // anyhow I don't want to waste time on this + static wxColour s_col; s_col = Find(name); if ( !s_col.Ok() ) return NULL; - return &s_col; + return new wxColour(s_col); } // ============================================================================ -- 2.45.2