From 06b5b300c3064885c9f985da2a728af0c80f3a86 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 14 Jun 2017 15:27:50 +0100 Subject: [PATCH] When enumerating adb devices, reuse old hosts where possible. * This fixes a crash where an enumeration from application startup is still going when opening the remote manager dialog, and then all the android hosts that are being enumerated get deleted while it's still going. --- .../Code/Interface/PersistantConfig.cpp | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/qrenderdoc/Code/Interface/PersistantConfig.cpp b/qrenderdoc/Code/Interface/PersistantConfig.cpp index 0d76687e8..7ded03c40 100644 --- a/qrenderdoc/Code/Interface/PersistantConfig.cpp +++ b/qrenderdoc/Code/Interface/PersistantConfig.cpp @@ -170,10 +170,14 @@ void PersistantConfig::applyValues(const QVariantMap &values) void PersistantConfig::AddAndroidHosts() { + QMap oldHosts; for(int i = RemoteHosts.count() - 1; i >= 0; i--) { if(RemoteHosts[i]->IsHostADB()) - delete RemoteHosts.takeAt(i); + { + RemoteHost *host = RemoteHosts.takeAt(i); + oldHosts[host->Hostname] = host; + } } QString adbExePath = @@ -191,8 +195,16 @@ void PersistantConfig::AddAndroidHosts() RENDERDOC_EnumerateAndroidDevices(&androidHosts); for(const QString &hostName : ToQStr(androidHosts).split(QLatin1Char(','), QString::SkipEmptyParts)) { - RemoteHost *host = new RemoteHost(); - host->Hostname = lit("adb:") + hostName; + RemoteHost *host = NULL; + + QString fullHostname = lit("adb:") + hostName; + + if(oldHosts.contains(fullHostname)) + host = oldHosts.take(fullHostname); + else + host = new RemoteHost(); + + host->Hostname = fullHostname; rdctype::str friendly; RENDERDOC_GetAndroidFriendlyName(hostName.toUtf8().data(), friendly); host->FriendlyName = ToQStr(friendly); @@ -200,6 +212,14 @@ void PersistantConfig::AddAndroidHosts() host->RunCommand = lit("org.renderdoc.renderdoccmd"); RemoteHosts.push_back(host); } + + // delete any leftovers + QMapIterator i(oldHosts); + while(i.hasNext()) + { + i.next(); + delete i.value(); + } } PersistantConfig::~PersistantConfig()