PDA

View Full Version : Problem using Q3CanvasSprite and Q3CanvasPixmapArray



degs2k4
25th February 2008, 14:29
Hello,

I have the following problem. In this function:


void MyCanvasView::addSprite()
{
Q3CanvasItem* i = new BouncyLogo(myCanvas);
i->setZ(rand()%256);
i->show();
}


we create a new BouncyLogo item. The constructor for BouncyLogo is as follows:


BouncyLogo::BouncyLogo(Q3Canvas* canvas):
Q3CanvasSprite(0,canvas)
{

logo_rtti = 1234;
Q3CanvasPixmapArray logo(":/images/qt-trans.xpm");
setSequence(&logo);
setAnimated(TRUE);
initPos();

}

OK, the problem is that when I call the function addSprite() the application just crashes...

Can you see anything wrong with this code?

Thanks!

wysota
25th February 2008, 16:02
Could you show us the call stack from the debugger when that happens? The problem is probably in the setSequence() call - you pass a pointer to a local object that gets deleted when the constructor returns and when something tries to access this data, the application crashes because the pointer is invalid.

degs2k4
26th February 2008, 00:29
Could you show us the call stack from the debugger when that happens? The problem is probably in the setSequence() call - you pass a pointer to a local object that gets deleted when the constructor returns and when something tries to access this data, the application crashes because the pointer is invalid.

Thanks... But, How can I see the stack from the debugger? I am using QDevelop... :(

Anyway, if I change the code in this way, it doesn't work neither:


Q3CanvasPixmapArray* logo = new Q3CanvasPixmapArray (":/images/qt-trans.xpm");
setSequence(logo);

wysota
26th February 2008, 01:53
Thanks... But, How can I see the stack from the debugger? I am using QDevelop... :(

Run your program under gdb and when it crashes, issue the "bt" command and paste the printed output. Just make sure the application is built in debug mode.

degs2k4
26th February 2008, 11:48
Run your program under gdb and when it crashes, issue the "bt" command and paste the printed output. Just make sure the application is built in debug mode.

I'm running everything under windows so I don't think I have such bt command...


I'm sorry but I don't know much about Qt....:(

wysota
26th February 2008, 12:30
I'm running everything under windows so I don't think I have such bt command...
This is a command in the debugger (gdb).

degs2k4
26th February 2008, 13:34
OK, debugging the program with GDB gives me this output:


(gdb) (gdb) (gdb) (gdb) (gdb) Starting program: C:/QDevelop/myeditor/bin/myeditor.exe



Program received signal SIGSEGV, Segmentation fault.

0x00823169 in QPixmap::height (this=0x0) at image/qpixmap_raster.cpp:196

(gdb)

Reegarding the stack, I unclude it in a png file attached. Please check it.

wysota
26th February 2008, 13:46
The pixmap is null. Your Q3CanvasPixmapArray constructor is invalid. Take a look at the docs to see what the parameter does.

degs2k4
26th February 2008, 14:03
The pixmap is null. Your Q3CanvasPixmapArray constructor is invalid. Take a look at the docs to see what the parameter does.

The parameters of the constructor look good, they match the signature of the constructor:


Q3CanvasPixmapArray* logo = new Q3CanvasPixmapArray (":/images/qt-trans.xpm");


Q3CanvasPixmapArray ( const QString & datafilenamepattern, int fc = 0 )

By the way, how did you know that the problem is there just looking at the stack?

wysota
26th February 2008, 14:18
The parameters of the constructor look good, they match the signature of the constructor:
But the content doesn't make sense. If the signature didn't match, the application wouldn't compile. The fact that the program builds doesn't mean it will work.


By the way, how did you know that the problem is there just looking at the stack?

Take a look at the first line of the image. (this=0x0) means that you call a method on a null pointer.

degs2k4
26th February 2008, 14:29
But the content doesn't make sense. If the signature didn't match, the application wouldn't compile. The fact that the program builds doesn't mean it will work.

That's true. But I am only passing a string which I think makes sense. I have other resources that work, the path is OK and the xpm file is where it should to be... So I don't understand why it is not working...


Take a look at the first line of the image. (this=0x0) means that you call a method on a null pointer.

OK I see. Thanks!

wysota
26th February 2008, 14:42
That's true. But I am only passing a string which I think makes sense. I have other resources that work, the path is OK and the xpm file is where it should to be... So I don't understand why it is not working...

Check if it gets loaded. You are obviously dealing with a null pixmap array here.