From 0e8c95f27eb71bd89164c071e516a3861eb9414a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Mon, 20 Nov 2017 16:16:53 +0100 Subject: [PATCH] Overrides - Fixed segfault in initialisation Override definitions were being moved, so there was no pointer left to access the override on the next initialisation. --- sync.cc | 2 +- sync.hh | 3 ++ syncoverrides.cc | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ syncoverrides.hh | 46 +++++++++++++++++++++---- 4 files changed, 132 insertions(+), 7 deletions(-) diff --git a/sync.cc b/sync.cc index 47052aa..43046d8 100644 --- a/sync.cc +++ b/sync.cc @@ -440,7 +440,7 @@ void T_SyncOverrideSection::merge( section( os->title ).merge( *os ); } for ( auto& ov : other.overrides ) { - overrides.add( std::move( ov ) ); + overrides.add( ov->clone( ) ); } } diff --git a/sync.hh b/sync.hh index 5a5658e..7b084a6 100644 --- a/sync.hh +++ b/sync.hh @@ -222,6 +222,9 @@ class A_SyncOverride virtual void makeUI( uint32_t& counter , T_StringBuilder& sb ) noexcept; + + // Create a clone of the current override. + virtual T_OwnPtr< A_SyncOverride > clone( ) const noexcept = 0; }; // Overrides section diff --git a/syncoverrides.cc b/syncoverrides.cc index b532da4..0ed92be 100644 --- a/syncoverrides.cc +++ b/syncoverrides.cc @@ -659,6 +659,13 @@ void T_Float::makeEditWidgets( } } +P_SyncOverride T_Float::clone( ) const noexcept +{ + auto c{ NewOwned< T_Float >( inputs_[ 0 ] , &title_[ 0 ] ) }; + copyTo( *c ); + return c; +} + /*= T_Float2 ===================================================================*/ @@ -694,6 +701,13 @@ void T_Float2::makeEditWidgets( } } +P_SyncOverride T_Float2::clone( ) const noexcept +{ + auto c{ NewOwned< T_Float2 >( inputs_[ 0 ] , inputs_[ 1 ] , &title_[ 0 ] ) }; + copyTo( *c ); + return c; +} + /*= T_Float3 ===================================================================*/ @@ -731,6 +745,14 @@ void T_Float3::makeEditWidgets( } } +P_SyncOverride T_Float3::clone( ) const noexcept +{ + auto c{ NewOwned< T_Float3 >( inputs_[ 0 ] , inputs_[ 1 ] , + inputs_[ 2 ] , &title_[ 0 ] ) }; + copyTo( *c ); + return c; +} + /*= T_Float4 ===================================================================*/ @@ -770,6 +792,14 @@ void T_Float4::makeEditWidgets( } } +P_SyncOverride T_Float4::clone( ) const noexcept +{ + auto c{ NewOwned< T_Float4 >( inputs_[ 0 ] , inputs_[ 1 ] , + inputs_[ 2 ] , inputs_[ 3 ] , &title_[ 0 ] ) }; + copyTo( *c ); + return c; +} + /*= A_Integer ==================================================================*/ @@ -826,6 +856,13 @@ void T_Integer::makeEditWidgets( } } +P_SyncOverride T_Integer::clone( ) const noexcept +{ + auto c{ NewOwned< T_Integer >( inputs_[ 0 ] , &title_[ 0 ] ) }; + copyTo( *c ); + return c; +} + /*= T_Integer2 =================================================================*/ @@ -861,6 +898,13 @@ void T_Integer2::makeEditWidgets( } } +P_SyncOverride T_Integer2::clone( ) const noexcept +{ + auto c{ NewOwned< T_Integer2 >( inputs_[ 0 ] , inputs_[ 1 ] , &title_[ 0 ] ) }; + copyTo( *c ); + return c; +} + /*= T_Integer3 =================================================================*/ @@ -898,6 +942,14 @@ void T_Integer3::makeEditWidgets( } } +P_SyncOverride T_Integer3::clone( ) const noexcept +{ + auto c{ NewOwned< T_Integer3 >( inputs_[ 0 ] , inputs_[ 1 ] , + inputs_[ 2 ] , &title_[ 0 ] ) }; + copyTo( *c ); + return c; +} + /*= T_Integer4 =================================================================*/ @@ -937,6 +989,14 @@ void T_Integer4::makeEditWidgets( } } +P_SyncOverride T_Integer4::clone( ) const noexcept +{ + auto c{ NewOwned< T_Integer4 >( inputs_[ 0 ] , inputs_[ 1 ] , + inputs_[ 2 ] , inputs_[ 3 ] , &title_[ 0 ] ) }; + copyTo( *c ); + return c; +} + /*= T_ColorGrading =============================================================*/ @@ -989,6 +1049,16 @@ bool T_ColorGrading::setUnit( M_SETOPT_( unit_ , v ); } +P_SyncOverride T_ColorGrading::clone( ) const noexcept +{ + auto c{ NewOwned< T_ColorGrading >( inputs_[ 0 ] , + inputs_[ 1 ] , inputs_[ 2 ] , &title_[ 0 ] ) }; + c->location( ) = location( ); + c->base_ = base_; + c->unit_ = unit_; + return c; +} + /*= T_CamOverride ==============================================================*/ @@ -998,6 +1068,24 @@ T_CamOverride::T_CamOverride( camMode_( CM_INVALID ) {} +P_SyncOverride T_CamOverride::clone( ) const noexcept +{ + auto c{ NewOwned< T_CamOverride >( &title_[ 0 ] ) }; + c->location( ) = location( ); + const auto n{ inputs_.size( ) }; + for ( auto i = 0u ; i < n ; i ++ ) { + c->inputs_.add( inputs_[ i ] ); + } + c->fovConfig_ = fovConfig_; + c->target_ = target_; + c->upVector_ = upVector_; + c->position_ = position_; + c->angles_ = angles_; + c->distance_ = distance_; + c->camMode_ = camMode_; + return c; +} + /*------------------------------------------------------------------------------*/ T_CamOverride::E_SetState T_CamOverride::setFieldOfView( diff --git a/syncoverrides.hh b/syncoverrides.hh index 27c6095..d982008 100644 --- a/syncoverrides.hh +++ b/syncoverrides.hh @@ -23,10 +23,18 @@ class A_Float : public A_SyncOverride : A_SyncOverride( type , title ) {} - public: - A_Float( T_String const& input , - T_String const& title ) noexcept; + void copyTo( A_Float& other ) const noexcept + { + other.min_ = min_; + other.max_ = max_; + other.step_ = step_; + other.decimals_ = decimals_; + other.power_ = power_; + other.slider_ = slider_; + other.location( ) = location( ); + } + public: bool setMin( const float v ) noexcept; bool setMax( const float v ) noexcept; bool setStep( const float v ) noexcept; @@ -52,6 +60,8 @@ class T_Float : public A_Float public: T_Float( T_String const& input , T_String const& title ) noexcept; + + P_SyncOverride clone( ) const noexcept override; }; // 2 float values @@ -65,6 +75,8 @@ class T_Float2 : public A_Float T_Float2( T_String const& input0 , T_String const& input1 , T_String const& title ) noexcept; + + P_SyncOverride clone( ) const noexcept override; }; // 3 float values @@ -79,6 +91,8 @@ class T_Float3 : public A_Float T_String const& input1 , T_String const& input2 , T_String const& title ) noexcept; + + P_SyncOverride clone( ) const noexcept override; }; // 4 float values @@ -94,6 +108,8 @@ class T_Float4 : public A_Float T_String const& input2 , T_String const& input3 , T_String const& title ) noexcept; + + P_SyncOverride clone( ) const noexcept override; }; @@ -114,10 +130,16 @@ class A_Integer : public A_SyncOverride : A_SyncOverride( type , title ) {} - public: - A_Integer( T_String const& input , - T_String const& title ) noexcept; + void copyTo( A_Integer& other ) const noexcept + { + other.min_ = min_; + other.max_ = max_; + other.step_ = step_; + other.slider_ = slider_; + other.location( ) = location( ); + } + public: bool setMin( const int32_t v ) noexcept; bool setMax( const int32_t v ) noexcept; bool setStep( const float v ) noexcept; @@ -140,6 +162,8 @@ class T_Integer : public A_Integer public: T_Integer( T_String const& input , T_String const& title ) noexcept; + + P_SyncOverride clone( ) const noexcept override; }; // 2 integers @@ -153,6 +177,8 @@ class T_Integer2 : public A_Integer T_Integer2( T_String const& input0 , T_String const& input1 , T_String const& title ) noexcept; + + P_SyncOverride clone( ) const noexcept override; }; // 3 integers @@ -167,6 +193,8 @@ class T_Integer3 : public A_Integer T_String const& input1 , T_String const& input2 , T_String const& title ) noexcept; + + P_SyncOverride clone( ) const noexcept override; }; // 4 integers @@ -182,6 +210,8 @@ class T_Integer4 : public A_Integer T_String const& input2 , T_String const& input3 , T_String const& title ) noexcept; + + P_SyncOverride clone( ) const noexcept override; }; @@ -209,6 +239,8 @@ class T_ColorGrading : public A_SyncOverride float base( ) const noexcept { return base_ ? *base_ : 0.f; } float unit( ) const noexcept { return unit_ ? *unit_ : 1.f; } + + P_SyncOverride clone( ) const noexcept override; }; @@ -272,6 +304,8 @@ class T_CamOverride : public A_SyncOverride , public virtual A_MouseCtrl public: T_CamOverride( T_String const& title ) noexcept; + P_SyncOverride clone( ) const noexcept override; + E_SetState setFieldOfView( T_String const& input ) noexcept; E_SetState setNearPlane(