From c89dc4fdd2770ba3ad52303a2f4cb0c6403a2ecd Mon Sep 17 00:00:00 2001 From: Rafael Roquetto Date: Wed, 24 Oct 2012 16:27:24 -0200 Subject: [PATCH] QNX: Query dynamic buffer count at runtime While unlikely, there are cases in which QQnxWindow::renderBuffer() is called before the window buffers have been created. Without this check, the program will abort on QQnxBuffer constructor, since the value that will be passed to it will be of an invalid buffer. Change-Id: I9ad5926dca856570032dcf10b6975e8f3364c284 Reviewed-by: Thomas McGuire Reviewed-by: Sean Harmer --- src/plugins/platforms/qnx/qqnxrasterbackingstore.cpp | 5 ++++- src/plugins/platforms/qnx/qqnxwindow.cpp | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/qnx/qqnxrasterbackingstore.cpp b/src/plugins/platforms/qnx/qqnxrasterbackingstore.cpp index b8ec91d..11babe3 100644 --- a/src/plugins/platforms/qnx/qqnxrasterbackingstore.cpp +++ b/src/plugins/platforms/qnx/qqnxrasterbackingstore.cpp @@ -71,7 +71,10 @@ QQnxRasterBackingStore::~QQnxRasterBackingStore() QPaintDevice *QQnxRasterBackingStore::paintDevice() { - return m_platformWindow->renderBuffer().image(); + if (m_platformWindow->hasBuffers()) + return m_platformWindow->renderBuffer().image(); + + return 0; } void QQnxRasterBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) diff --git a/src/plugins/platforms/qnx/qqnxwindow.cpp b/src/plugins/platforms/qnx/qqnxwindow.cpp index 097b578..c668a88 100644 --- a/src/plugins/platforms/qnx/qqnxwindow.cpp +++ b/src/plugins/platforms/qnx/qqnxwindow.cpp @@ -374,10 +374,22 @@ QQnxBuffer &QQnxWindow::renderBuffer() // Check if render buffer is invalid if (m_currentBufferIndex == -1) { + // check if there are any buffers available + int bufferCount = 0; + int result = screen_get_window_property_iv(m_window, SCREEN_PROPERTY_RENDER_BUFFER_COUNT, &bufferCount); + + if (result != 0) { + qFatal("QQnxWindow: failed to query window buffer count, errno=%d", errno); + } + + if (bufferCount != MAX_BUFFER_COUNT) { + qFatal("QQnxWindow: invalid buffer count. Expected = %d, got = %d", MAX_BUFFER_COUNT, bufferCount); + } + // Get all buffers available for rendering errno = 0; screen_buffer_t buffers[MAX_BUFFER_COUNT]; - int result = screen_get_window_property_pv(m_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)buffers); + result = screen_get_window_property_pv(m_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)buffers); if (result != 0) { qFatal("QQnxWindow: failed to query window buffers, errno=%d", errno); } -- 2.7.4