From 3af4e889b9b8c1f10637a0f209301af4246089bb Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 15 Nov 2022 15:45:18 +0000 Subject: [PATCH] Unobfuscate wxAnyToVariant registration and remove global var hack. Note that I don't have any data that the global var hack was causing the bug, so this may or may not fix it. But it seems as good a candidate as any. Fixes https://gitlab.com/kicad/code/kicad/issues/12871 --- common/properties/eda_angle_variant.cpp | 1 - common/properties/pg_properties.cpp | 40 +++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/common/properties/eda_angle_variant.cpp b/common/properties/eda_angle_variant.cpp index 52c21cb1d9..277880f8b4 100644 --- a/common/properties/eda_angle_variant.cpp +++ b/common/properties/eda_angle_variant.cpp @@ -84,4 +84,3 @@ wxVariantData* EDA_ANGLE_VARIANT_DATA::VariantDataFactory( const wxAny& aAny ) } -REGISTER_WXANY_CONVERSION( EDA_ANGLE, EDA_ANGLE_VARIANT_DATA ) diff --git a/common/properties/pg_properties.cpp b/common/properties/pg_properties.cpp index 4e9c3c65ce..3c9fc92167 100644 --- a/common/properties/pg_properties.cpp +++ b/common/properties/pg_properties.cpp @@ -37,8 +37,44 @@ static const wxChar REGEX_SIGNED_DISTANCE[] = wxT( "([-+]?[0-9]+[\\.?[0-9]*) *(mm|in|mils)*" ); static const wxChar REGEX_UNSIGNED_DISTANCE[] = wxT( "([0-9]+[\\.?[0-9]*) *(mm|in|mils)*" ); -// Force at least one to exist, otherwise wxWidgets won't register it -static const EDA_ANGLE_VARIANT_DATA g_AngleVariantData; + +class wxAnyToEDA_ANGLE_VARIANTRegistrationImpl : public wxAnyToVariantRegistration +{ +public: + wxAnyToEDA_ANGLE_VARIANTRegistrationImpl( wxVariantDataFactory factory ) + : wxAnyToVariantRegistration( factory ) + { + } + +public: + static bool IsSameClass(const wxAnyValueType* otherType) + { + return AreSameClasses( *s_instance.get(), *otherType ); + } + + static wxAnyValueType* GetInstance() + { + return s_instance.get(); + } + + virtual wxAnyValueType* GetAssociatedType() wxOVERRIDE + { + return wxAnyToEDA_ANGLE_VARIANTRegistrationImpl::GetInstance(); + } +private: + static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b) + { + return wxTypeId(a) == wxTypeId(b); + } + + static wxAnyValueTypeScopedPtr s_instance; +}; + + +wxAnyValueTypeScopedPtr wxAnyToEDA_ANGLE_VARIANTRegistrationImpl::s_instance( new wxAnyValueTypeImpl() ); + +static wxAnyToEDA_ANGLE_VARIANTRegistrationImpl s_wxAnyToEDA_ANGLE_VARIANTRegistration( &EDA_ANGLE_VARIANT_DATA::VariantDataFactory ); + wxPGProperty* PGPropertyFactory( const PROPERTY_BASE* aProperty ) {