From 2d487381e8537024bbb10b03d324cea6b6060185 Mon Sep 17 00:00:00 2001 From: Rafael Roquetto Date: Wed, 24 Oct 2012 16:03:28 -0200 Subject: BlackBerry: Query dynamic buffer count at runtime While unlikely, there are cases in which QBBWindow::renderBuffer() is called before the window buffers have been created. Without this check, the program will abort on QBBBuffer constructor, since the value that will be passed to it will be of an invalid buffer. cherry-picked from qt5 c89dc4fdd2770ba3ad52303a2f4cb0c6403a2ecd Change-Id: I1f1cde76a364480f3bc77eaaa59ca3cfba2eb618 Reviewed-by: Thomas McGuire Reviewed-by: Kevin Krammer --- src/plugins/platforms/blackberry/qbbrasterwindowsurface.cpp | 5 ++++- src/plugins/platforms/blackberry/qbbwindow.cpp | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/blackberry/qbbrasterwindowsurface.cpp b/src/plugins/platforms/blackberry/qbbrasterwindowsurface.cpp index 11f2cb6..bab2aca 100644 --- a/src/plugins/platforms/blackberry/qbbrasterwindowsurface.cpp +++ b/src/plugins/platforms/blackberry/qbbrasterwindowsurface.cpp @@ -72,7 +72,10 @@ QBBRasterWindowSurface::~QBBRasterWindowSurface() QPaintDevice *QBBRasterWindowSurface::paintDevice() { - return mPlatformWindow->renderBuffer().image(); + if (mPlatformWindow->hasBuffers()) + return mPlatformWindow->renderBuffer().image(); + + return 0; } void QBBRasterWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) diff --git a/src/plugins/platforms/blackberry/qbbwindow.cpp b/src/plugins/platforms/blackberry/qbbwindow.cpp index 5d6a1c1..650601d 100644 --- a/src/plugins/platforms/blackberry/qbbwindow.cpp +++ b/src/plugins/platforms/blackberry/qbbwindow.cpp @@ -338,11 +338,22 @@ QBBBuffer &QBBWindow::renderBuffer() // check if render buffer is invalid if (mCurrentBufferIndex == -1) { + // check if there are any buffers available + int bufferCount = 0; + int result = screen_get_window_property_iv(mWindow, SCREEN_PROPERTY_RENDER_BUFFER_COUNT, &bufferCount); + + if (result != 0) { + qFatal("QBBWindow: failed to query window buffer count, errno=%d", errno); + } + + if (bufferCount != MAX_BUFFER_COUNT) { + qFatal("QBBWindow: 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(mWindow, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)buffers); + result = screen_get_window_property_pv(mWindow, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)buffers); if (result != 0) { qFatal("QBBWindow: failed to query window buffers, errno=%d", errno); } -- cgit v0.12