Fix hang on sleep/wakeup

This patch fixes the followings:
- call "it.value()" only on valid iterators
- destroySurface() doesn't remove the surfaceId from m_surfaces
- the surfaceId is removed from m_surfaces when the QtSurface is really
destroyed

Task-number: QTBUG-59185
Change-Id: Iee37dde16fee16f19906812c55c1f0b0279b033c
Reviewed-by: Mathias Hasselmann <mathias.hasselmann@kdab.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
BogDan Vatra 2017-03-01 17:39:25 +02:00
parent 329385a5d5
commit da4b91e2b2

View File

@ -402,11 +402,6 @@ namespace QtAndroid
if (surfaceId == -1)
return;
QMutexLocker lock(&m_surfacesMutex);
const auto &it = m_surfaces.find(surfaceId);
if (it != m_surfaces.end())
m_surfaces.remove(surfaceId);
QJNIEnvironmentPrivate env;
if (!env)
return;
@ -583,14 +578,18 @@ static void setSurface(JNIEnv *env, jobject /*thiz*/, jint id, jobject jSurface,
{
QMutexLocker lock(&m_surfacesMutex);
const auto &it = m_surfaces.find(id);
if (it.value() == nullptr) // This should never happen...
return;
if (it == m_surfaces.end()) {
qWarning()<<"Can't find surface" << id;
return;
}
it.value()->surfaceChanged(env, jSurface, w, h);
auto surfaceClient = it.value();
if (!surfaceClient) // This should never happen...
return;
surfaceClient->surfaceChanged(env, jSurface, w, h);
if (!jSurface)
m_surfaces.erase(it);
}
static void setDisplayMetrics(JNIEnv */*env*/, jclass /*clazz*/,