remove const_cast hack and memory leak in 'load doubleclicked texture's directory'

This commit is contained in:
Garux 2018-02-04 19:38:08 +03:00
parent 339d078bc6
commit f91df90d58

View File

@ -1443,21 +1443,13 @@ gboolean TextureBrowser_button_press( GtkWidget* widget, GdkEventButton* event,
} }
/* loads directory, containing active shader + focuses on it */ /* loads directory, containing active shader + focuses on it */
else if ( event->type == GDK_2BUTTON_PRESS && event->button == 1 && !TextureBrowser_showWads() ) { else if ( event->type == GDK_2BUTTON_PRESS && event->button == 1 && !TextureBrowser_showWads() ) {
CopiedString texName = textureBrowser->shader; const StringRange range( strchr( textureBrowser->shader.c_str(), '/' ) + 1, strrchr( textureBrowser->shader.c_str(), '/' ) + 1 );
char* sh = const_cast<char*>( texName.c_str() ); if( range.last - range.first != 0 ){
char* dir = strrchr( sh, '/' ); const CopiedString dir = range;
if( dir != NULL ){ ScopeDisableScreenUpdates disableScreenUpdates( dir.c_str(), "Loading Textures" );
*(dir + 1) = '\0'; TextureBrowser_ShowDirectory( *textureBrowser, dir.c_str() );
dir = strchr( sh, '/' ); TextureBrowser_Focus( *textureBrowser, textureBrowser->shader.c_str() );
if( dir != NULL ){ TextureBrowser_queueDraw( *textureBrowser );
dir++;
if( *dir != '\0'){
ScopeDisableScreenUpdates disableScreenUpdates( dir, "Loading Textures" );
TextureBrowser_ShowDirectory( *textureBrowser, dir );
TextureBrowser_Focus( *textureBrowser, textureBrowser->shader.c_str() );
TextureBrowser_queueDraw( *textureBrowser );
}
}
} }
} }
else if ( event->type == GDK_2BUTTON_PRESS && event->button == 3 ) { else if ( event->type == GDK_2BUTTON_PRESS && event->button == 3 ) {