Fix assert for m_objectInstanceHash

The hash was not cleaned up in any case and sometimes a new object
gets allocated at the exact same address.
To avoid leaking hashes in m_objectInstanceHash and to avoid the assert,
we remove any deleted QObject from the hash.

Change-Id: I2697ab2b2430ad47932841fb9c0ef88ffa4cbbb1
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Thomas Hartmann
2015-02-23 11:28:23 +01:00
committed by Thomas Hartmann
parent 54ce123a26
commit a2aaf0f6eb
3 changed files with 20 additions and 0 deletions

View File

@@ -1217,6 +1217,17 @@ void NodeInstanceServer::sendDebugOutput(DebugOutputCommand::Type type, const QS
nodeInstanceClient()->debugOutput(command);
}
void NodeInstanceServer::removeInstanceRelationsipForDeletedObject(QObject *object)
{
if (m_objectInstanceHash.contains(object)) {
ServerNodeInstance instance = instanceForObject(object);
m_objectInstanceHash.remove(object);
if (m_idInstanceHash.contains(instance.instanceId()))
m_idInstanceHash.remove(instance.instanceId());
}
}
QStringList NodeInstanceServer::dummyDataDirectories(const QString& directoryPath)
{
QStringList dummyDataDirectoryList;

View File

@@ -131,6 +131,7 @@ public:
void sendDebugOutput(DebugOutputCommand::Type type, const QString &message, qint32 instanceId);
void sendDebugOutput(DebugOutputCommand::Type type, const QString &message, const QVector<qint32> &instanceIds);
void removeInstanceRelationsipForDeletedObject(QObject *object);
public slots:
void refreshLocalFileProperty(const QString &path);
void refreshDummyData(const QString &path);

View File

@@ -111,7 +111,15 @@ ObjectNodeInstance::ObjectNodeInstance(QObject *object)
m_deleteHeldInstance(true),
m_isInLayoutable(false)
{
if (object)
QObject::connect(m_object.data(), &QObject::destroyed, [=] {
/*This lambda is save because m_nodeInstanceServer
is a smartpointer and object is a dangling pointer anyway.*/
if (m_nodeInstanceServer)
m_nodeInstanceServer->removeInstanceRelationsipForDeletedObject(object);
});
}
ObjectNodeInstance::~ObjectNodeInstance()