View Full Version : Qt 4.7 SSE2 causing my app to crash

25th September 2010, 18:39

I just upgraded my build system to Qt 4.7 and recompiled one of my apps that uses QGraphicsItems.

One of the first things the app does is create an offscreen QPixmap and renders into it. I'm not doing anything extraordinary - just loading 32bit pngs and rendering them into an offscreen buffer. I'm not using direct pixel buffer access anywhere.

When compiled with Qt 4.6.3 (mingw), no problems - the app runs fine.

When compiled with Qt 4.7 (also mingw), I get a memory access exception when I call QPainter::drawPixmap()

The crash happens in the function qt_blend_argb32_on_argb32_sse2, when the macro BLEND_SOURCE_OVER_ARGB32_SSE2 is executed.

I've created minimal apps using snippets of the code from my larger app, and none of these crash.

So right now I'm stuck trying to workout what else can cause the crash.

An example of the code is below (this does not crash).

int main(int argc, char *argv[])
QApplication a(argc, argv);
QPixmap srcImage( ":/topLeft.png" );// this image is 15x15x32bit
QPixmap destImage(640, 480);
QPainter p( &destImage );
p.drawPixmap( 0, 0, 15, 15, srcImage );
return 0;

However if this code is called elsewhere in the application, it triggers the crash.
This function crashes if called after QGraphicsScene and QGraphicsView initialization.
It does not crash if I call it before doing the initialization.

void function()
QPixmap srcImage( ":/topLeft.png" ); // this image is 15x15x32bit
QPixmap destImage(640, 480);
QPainter p( &destImage );
p.drawPixmap( 0, 0, 15, 15, srcImage ); // crash

Does anyone have any insight into what typically can cause problems when using the SSE instruction set?

25th September 2010, 19:45
At the moment I can not reproduce this crash.
I don't even find any bug report or any question about the mentioned qt_blend_argb32_on_argb32_sse2 function.

Maybe I did understand something wrong.
I saved a png of size 15x15 but in 24 bit. So one of my questions is, can you please post a 32bit 15x15 png I can use for testing?

But before that... the crash only happened in your program? Or also in your test code?
Because that is not very clear.

If it does not crash in your test code, can you try to completely clean your build? As in removing your build dir or removing the Makefile and object files. Then rerun qmake and make again. Does this solve the problem?

If not, then there might be something wrong elsewhere.
Can you put in some breakpoints and try some debugging?

25th September 2010, 21:24
I'll try to clarify. This is the history:

1. Dual install 4.6.3 and 4.7
2. Clean rebuild my app in 4.6.3 : no crash.
3. Clean rebuild my app in 4.7 : crash.
4. Repeated 1 and 2 a couple of times to be sure.
5. Uninstall 4.7
6. Clean rebuild my app in 4.6.3 : no crash.
7. Uninstall 4.6.3
8. Install 4.7
9. Clean rebuild my app in 4.7 : crash.
10. Repeated 9 twice more cos I thought I was losing my mind!
11. Created minimal function that triggers the crash.
12. Called the minimal function from a test program built in 4.7 : no crash.
13. Called the minimal function from my application's main function (built in 4.7) : no crash.
14. Call the minimal function from code deeper into my application (built in 4.7) : crash.

The image is here http://imgur.com/7ki3g.png

I'm currently trying to narrow down the exact series of function calls that are required to cause the crash.
Basically putting the function call in a number of places and seeing which one triggers the crash.
However my application has a pretty huge code base, so this will take a while for the result. I'm looking for guidance on SSE related gotcha's that might speed up my hunt.

Also, searched http://bugreports.qt.nokia.com/ for "QRasterPaintEnginePrivate drawImage sse2". Nothing relevant came up.

- Thanks!

26th September 2010, 02:24
Narrowed it down somewhat but it's still very odd.
Basically, the function does not crash my application if I call it before my QMainWindow object is instantiated.

Anytime after instantiating the QMainWindow object, and from anywhere in the application, the function will crash (even when the QMainWindow object goes out of scope).

That doesn't help much because the critical path (99% of my executed code) is executed via QMainWindow.

I think I'm going to need to rewrite my app bit-by-bit to discover what the root cause is :(

26th September 2010, 07:45
I think I'm going to need to rewrite my app bit-by-bit to discover what the root cause is :(

That should not be necessary. Can you explain how you debug your application? Maybe someone can give you some tips on finding the problem without rewriting everything.

26th September 2010, 12:11
i did port my app yesterday.
My mistake was: i did import the old qwt 4.5 build settings.\\
So: Do not import them, run qmake + clean all and rebuild all\\
this fixed my first error..

second error see was:

QString Dir = G_cWorkSpace.fiModelsDirectory.absoluteFilePath(); //caused the error
QString Dir;
Dir = G_cWorkSpace.fiModelsDirectory.absoluteFilePath(); //fixed the error

maybe try:

QPixmap srcImage;
srcImage.Set with the correct function.... ( ":/topLeft.png" );

QPixmap destImage;
destImage.Set with the correct function... (640, 480);

greetz A.

26th September 2010, 15:58
Debugging - I just use GDB via the Creator GUI.

I've just finished recreating my mainwindow.cpp (where my class derived from QMainWindow is implemented).
I recreated the file by pasting chunks of functional code from the original mainwindow.cpp into a new file.
Each time I added code, I rebuilt (commenting out any code that casued compiler/linker errors) and tested for the crash.

Now I have 100% of the functionality back and no crashes at all!???
Then I diff'd the original file against this new one and the only change is the positioning of functions within the file.

Next I backed up this new file and restored the original one....no crash!!?

No I am very confused. In my earlier post where I said I performed a clean rebuild, I right-clicked the project and selected "Clean", then right-click "Run qmake", then right-click "build".
I also on more than one occasion rebuilt the project into a completely different shadow directory and still saw the crash.
So I'm wonderng if "Clean" only cleaned out the compiler and linker outputs from the shadow build dir did not clean everything (I'm thinking of moc files etc...)

I wonder if, instead, I had performed a clean checkout of my sources this problem would not have happened?

26th September 2010, 17:26
What you are saying is similar i had done.
But than i re-installed every qt version i had - 4.5, 4.5.2, 4.5.3, 4.6 4.7 to see if it is a qt problem or if it has to do with my files.

At last Qt asked me during importing the project files: "Do you wish to import build settings.." or something..
i said no, did a qmake + rebuild and everything was fine.

greetz A.

26th September 2010, 19:53
That sounds the most likely reason!