]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/preferences.cpp
radiant/preferences: fix memory issue when saving pref
[xonotic/netradiant.git] / radiant / preferences.cpp
index 732a7401338fef4210f98d240deff67d22efc338..e57380eb1f3a32e071501d901b365762cb4fb417 100644 (file)
@@ -204,13 +204,10 @@ bool Preferences_Save( PreferenceDictionary& preferences, const char* filename )
 }
 
 bool Preferences_Save_Safe( PreferenceDictionary& preferences, const char* filename ){
-       Array<char> tmpName( filename, filename + strlen( filename ) + 1 + 3 );
-       *( tmpName.end() - 4 ) = 'T';
-       *( tmpName.end() - 3 ) = 'M';
-       *( tmpName.end() - 2 ) = 'P';
-       *( tmpName.end() - 1 ) = '\0';
+       std::string tmpName( filename );
+       tmpName += "TMP";
 
-       return Preferences_Save( preferences, tmpName.data() )
+       return Preferences_Save( preferences, tmpName.c_str() )
                   && ( !file_exists( filename ) || file_remove( filename ) )
                   && file_move( tmpName.data(), filename );
 }
@@ -285,8 +282,15 @@ void CGameDialog::GameFileImport( int value ){
 
        if ( ( *iGame )->mGameFile != m_sGameFile ) {
                m_sGameFile = ( *iGame )->mGameFile;
-               PreferencesDialog_restartRequired( "Selected Game" );
+
+               // do not trigger radiant restart when switching game on startup using Global Preferences dialog
+               if ( !onStartup ) {
+                       PreferencesDialog_restartRequired( "Selected Game" );
+               }
        }
+
+       // onStartup can only be true once, when Global Preferences are displayed at startup
+       onStartup = false;
 }
 
 void CGameDialog::GameFileExport( const Callback<void(int)> & importCallback ) const {
@@ -451,12 +455,16 @@ void CGameDialog::Init(){
        }
 
        if ( gamePrompt || !currentGameDescription ) {
+               onStartup = true;
                Create();
                DoGameDialog();
                // use m_nComboSelect to identify the game to run as and set the globals
                currentGameDescription = GameDescriptionForComboItem();
                ASSERT_NOTNULL( currentGameDescription );
        }
+       else {
+               onStartup = false;
+       }
 
        g_pGameDescription = currentGameDescription;
 
@@ -696,6 +704,9 @@ ui::Window PrefsDlg::BuildDialog(){
 
        ui::Window dialog = ui::Window(create_floating_window( RADIANT_NAME " Preferences", m_parent ));
 
+       gtk_window_set_transient_for( dialog, m_parent );
+       gtk_window_set_position( dialog, GTK_WIN_POS_CENTER_ON_PARENT );
+
        {
                auto mainvbox = ui::VBox( FALSE, 5 );
                dialog.add(mainvbox);