• 4269阅读
  • 2回复

delete QCanvasPixmap 后程序崩溃!! [复制链接]

上一主题 下一主题
离线xuyantao
 
只看楼主 倒序阅读 楼主  发表于: 2008-06-04
— 本帖被 XChinux 执行加亮操作(2008-06-04) —
pixmapArray 是一个new的QCanvasPixmapArray的指针。

if(pixmap != NULL){
    delete pixmap;
    pixmap = NULL;
}
pixmap = new QCanvasPixmap(*pImage);

pixmapArray -> setImage(0, pixmap);

if(sprite != NULL){
    delete sprite ;
    sprite = NULL;
}
sprite = new QCanvasSprite(pixmapArray, canvas);
sprite -> setFrame(0);
sprite -> setVelocity(2, 2);
sprite -> show();
canvas -> update();


上面的代码第二次调用的时候,运行至sprite -> show();程序崩溃。但是注释掉

if(pixmap != NULL){
    delete pixmap;
    pixmap = NULL;
}
就没有问题。不知道原因,请帮忙分析一下!!!
离线steinlee

只看该作者 1楼 发表于: 2008-06-05
If you know how to run valgrind(on Linux), it may be easier for you to solve the problem.
One suggestion would be that you check if *pimage is damaged when pixmap is deleted.
It is a very good habit to set pointers to be NULL after they are deleted.

引用楼主xuyantao于2008-06-04 19:48发表的 delete QCanvasPixmap 后程序崩溃!! :
pixmapArray 是一个new的QCanvasPixmapArray的指针。
if(pixmap != NULL){
? ? delete pixmap;
? ? pixmap = NULL;
.......
Looking for remote C/C++ and Qt 兼职
离线xuyantao
只看该作者 2楼 发表于: 2008-06-05
引用第1楼steinlee于2008-06-05 02:34发表的  :
If you know how to run valgrind(on Linux), it may be easier for you to solve the problem.
One suggestion would be that you check if *pimage is damaged when pixmap is deleted.
It is a very good habit to set pointers to be NULL after they are deleted.


Thanks for your attention! I will check *pimage  and study valgrind to seek ask for the problem.
快速回复
限100 字节
 
上一个 下一个