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.
This commit is contained in:
baldurk
2017-06-14 15:27:50 +01:00
committed by Baldur Karlsson
parent c76b8298f8
commit 06b5b300c3
+23 -3
View File
@@ -170,10 +170,14 @@ void PersistantConfig::applyValues(const QVariantMap &values)
void PersistantConfig::AddAndroidHosts()
{
QMap<QString, RemoteHost *> 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<QString, RemoteHost *> i(oldHosts);
while(i.hasNext())
{
i.next();
delete i.value();
}
}
PersistantConfig::~PersistantConfig()