×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    94

    Out of memory when rotating device

    Hi all,

    In my qt mobile application when I rotate the device either by code or on real it is giving me this error:

    [Qt message] QImage: out of memory returning null image

    knowing that I don't have images in my widget it is just simple controls!!!! help please!

  2. #2
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    95

    Re: Out of memory when rotating device

    Post some part of code

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    94

    Re: Out of memory when rotating device

    Quote Originally Posted by negus View Post
    Post some part of code
    hi actually its not a small code and I can't figure out which part makes that problem but it occurres just when I rotate the device you know !!! the screen goes white and it gives me that error!!!

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: Out of memory when rotating device

    you are propably leaking memory, thus check the functions called during the rotation and see what you are doing in them. i.e. any sensor code, as well as any function used for resizing.

  5. #5
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Out of memory when rotating device

    Yep, sounds like a memory leak.

    This bit of code will display heap usage:
    Code:
    #ifdef Q_OS_SYMBIAN
    #include <e32std.h>  // Link against euser.lib
    #endif
    .
    .
    .
    void HeapLeak::updateHeapStats() {
    #ifdef Q_OS_SYMBIAN
    	TInt mem, size, limit;
    	User::Heap().AllocSize(mem);
    	size = User::Heap().Size();
    	limit = User::Heap().MaxLength();
    	ui.memLabel ->setText(QString::number(mem));
    	ui.memLabel ->update();
    	ui.sizeLabel ->setText(QString::number(size));
    	ui.sizeLabel ->update();
    	ui.limitLabel ->setText(QString::number(limit));
    	ui.limitLabel ->update();
    #endif
    }
    (Create labels memLabel, sizeLabel, and limitLabel on your screen, or alternatively display the values in a QMessageBox.)

  6. #6
    Registered User
    Join Date
    Oct 2010
    Posts
    94

    Re: Out of memory when rotating device

    Quote Originally Posted by symbianyucca View Post
    you are propably leaking memory, thus check the functions called during the rotation and see what you are doing in them. i.e. any sensor code, as well as any function used for resizing.
    Hi, actually I don't call any functions I just rotate the device many times while am on the same widget how can that make a leak ??? my widget contains 4 buttons and a tree widget thats all !!!!

  7. #7
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: Out of memory when rotating device

    Are your widgets standard Qt widgets only, or have you done some customization? When you rotate the device all of their sizes will be changed - I guess something in that call path is leaking memory. I'd strongly suspect something in the tree widget as a first guess.

  8. #8
    Registered User
    Join Date
    Oct 2010
    Posts
    94

    Re: Out of memory when rotating device

    Quote Originally Posted by Sorcery-ltd View Post
    Are your widgets standard Qt widgets only, or have you done some customization? When you rotate the device all of their sizes will be changed - I guess something in that call path is leaking memory. I'd strongly suspect something in the tree widget as a first guess.
    no that happenes even with other widgets that do not contain tree widget....!!!

  9. #9
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: Out of memory when rotating device

    Well look for a component that's common to all the cases where it does happen.

  10. #10
    Registered User
    Join Date
    Oct 2010
    Posts
    94

    Re: Out of memory when rotating device

    Ok, more tests, I have included the code below and put it after the call that crashes the application, here are the numbers:
    Mem = 6804436
    Size = 8351624
    Limit = 8388608

    am I hitting the limit? I started to believe that there is a leak some where, how could I detect the leaks using Qt Creator?
    I tried increasing the TARGET.EPOCHEAPSIZE = 0x010000 0x8000000 but with no luck.
    Here is a snippet of the class that triggers the crash,I put it all, as I have no leak detection tools to determine the code responsible for the problem.

    Code:
    #include "headlinewidget.h"
    #include "ui_headlinewidget.h"
    #include <QLCDNumber>
    #include "mylabel.h"
    
    
    #ifdef Q_OS_SYMBIAN
    #include <AknAppUi.h>
    #include <e32std.h>  // Link against euser.lib
    #endif
    
    void HeadlineWidget::updateHeapStats() {
    #ifdef Q_OS_SYMBIAN
            TInt mem, size, limit;
            User::Heap().AllocSize(mem);
            size = User::Heap().Size();
            limit = User::Heap().MaxLength();
    
            QMessageBox msgBox1;
            QString tmp = "Mem = " + QString::number(mem) + "  Size = " + QString::number(size)+ "  Limit = " + QString::number(limit);
            msgBox1.setText(tmp);
            msgBox1.setDefaultButton(QMessageBox::Ok);
            int ret = msgBox1.exec();
    #endif
    }
    
    
    HeadlineWidget::HeadlineWidget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::HeadlineWidget)
    {
        Q_INIT_RESOURCE(resources);
    
    #ifdef Q_OS_SYMBIAN
         //lock orientation
        CAknAppUi* appUi = dynamic_cast<CAknAppUi*>(CEikonEnv::Static()->AppUi());
        if(appUi){
            QT_TRAP_THROWING(appUi ->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape));
       }
    #endif
    
        ui->setupUi(this);
    
        _swipeGesture=new MySwipeGesture(this);
    
        this->setStyleSheet("background-color: rgb(52, 195, 76);");
        ui->lcdNumber->display("00:00:00");
        ui->label->setText(sharedData::currentHeadline.name);
    
        connect(ui->lcdNumber,SIGNAL(beYellow()),this,SLOT(setYellow()));
        connect(ui->lcdNumber,SIGNAL(beRed()),this,SLOT(setRed()));
        connect(ui->lcdNumber,SIGNAL(jstBeGreen()),this,SLOT(jstSetGreen()));
        connect(ui->lcdNumber,SIGNAL(closeNote()),this,SLOT(isClosed()));
        connect(ui->lcdNumber,SIGNAL(setLabelText()),this,SLOT(setText()));
        connect(_swipeGesture,SIGNAL(handleSwipe(MySwipeGesture::SwipeDirection)),this,SLOT(swipe(MySwipeGesture::SwipeDirection)));
        connect(ui->lcdNumber,SIGNAL(headlineTimeChanged()),this,SLOT(setLCD_2()));
        connect(ui->exit,SIGNAL(isClicked()),SLOT(isClosed()));
    }
    void HeadlineWidget::setText()
    {
        ui->label->setText(sharedData::currentHeadline.name);
        ui->label->repaint();
    }
    
    void HeadlineWidget::setLCD_2()
    {
        ui->lcdNumber_2->display(sharedData::headlineTimeString);
    }
    
    void HeadlineWidget::showButton()
    {
    
    }
    
    void HeadlineWidget::jstSetGreen()
    {
        ui->label->setText(sharedData::currentHeadline.name);
        this->setStyleSheet("background-color: rgb(52, 195, 76);");
        this->repaint();
    }
    
    void HeadlineWidget::setYellow()
    {
        ui->label->setText(sharedData::currentHeadline.name);
        this->setStyleSheet("background-color: rgb(255, 217, 0);");
        this->repaint();
    }
    
    void HeadlineWidget::setRed()
    {
        ui->label->setText(sharedData::currentHeadline.name);
        this->setStyleSheet("background-color: rgb(255, 0, 0);");
        this->repaint();
    }
    
    void HeadlineWidget::goNext()
    {
        this->setStyleSheet("background-color: rgb(52, 195, 76);");
        this->repaint();
    
        sharedData::currentHeadline.time=sharedData::remainingList.at(sharedData::headlineIndex);
        sharedData::currentNote.headlines.takeAt(sharedData::headlineIndex);
        sharedData::currentNote.headlines.insert(sharedData::headlineIndex,sharedData::currentHeadline);
    
        //Auto calculation
        if(sharedData::autoCal && sharedData::currentHeadline.time<0)
        {
            int totalRemaining=0;
            for(int i=sharedData::headlineIndex+1;i<sharedData::remainingList.count();i++)
            {
                totalRemaining+= sharedData::remainingList.at(i);
            }
    
            for(int i=sharedData::headlineIndex+1;i<sharedData::remainingList.count();i++)
            {
               int newTime= sharedData::remainingList.at(i)- (float)(((float)sharedData::remainingList.at(i)/(float)totalRemaining)*(float)abs(sharedData::currentHeadline.time));
               sharedData::remainingList.takeAt(i);
               sharedData::remainingList.insert(i,newTime);
    
               headline newHead=sharedData::currentNote.headlines.at(i);
               newHead.time=newTime;
               sharedData::currentNote.headlines.takeAt(i);
               sharedData::currentNote.headlines.insert(i,newHead);
            }
        }
    
        if(sharedData::headlineIndex<sharedData::currentNote.headlines.count()-1)
            sharedData::headlineIndex++;
        sharedData::currentHeadline=sharedData::currentNote.headlines.at(sharedData::headlineIndex);
        sharedData::headlineStartTime=QTime::currentTime();
    
        ui->label->setText(sharedData::currentHeadline.name);
        ui->label->repaint();
    }
    
    void HeadlineWidget::isClosed()
    {
    
        QMessageBox msgBox;
        msgBox.setText("Are you sure you want to close this talk and go to talks page?");
        msgBox.setIcon(QMessageBox::Question);
        msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
        msgBox.setDefaultButton(QMessageBox::Ok);
        int ret = msgBox.exec();
    
        if(ret==QMessageBox::Ok)
        {
            #ifdef Q_OS_SYMBIAN
    
                // lock orientation
                CAknAppUi* appUi = dynamic_cast<CAknAppUi*>(CEikonEnv::Static()->AppUi());
                if(appUi){
                    QT_TRAP_THROWING(appUi ->SetOrientationL(CAknAppUi::EAppUiOrientationPortrait));
                }
            #endif
            this->close();
            updateHeapStats();
        }
    }
    
    HeadlineWidget::~HeadlineWidget()
    {
        delete ui;
    }
    
    MySwipeGesture::MySwipeGesture(QObject *parent)
        :QObject(parent),_startPoint(0,0),_endPoint(0,0)
    {}
    
    void MySwipeGesture::handleEvent( QEvent *event)
    {
        if( event->type() == QEvent::MouseButtonPress ) {
        QMouseEvent* mouseEvent = static_cast<QMouseEvent*> (event);
            _startPoint = mouseEvent->pos();
        } else if( event->type() == QEvent::MouseButtonRelease ) {
        QMouseEvent* mouseEvent = static_cast<QMouseEvent*> (event);
            _endPoint = mouseEvent->pos();
    
            //process distance and direction
            int xDiff = _startPoint.x() - _endPoint.x();
            int yDiff = _startPoint.y() - _endPoint.y();
            if( qAbs(xDiff) > qAbs(yDiff) && qAbs(xDiff)>120 ) {
                // horizontal swipe detected, now find direction
                if( _startPoint.x() > _endPoint.x() ) {
                    emit handleSwipe( Left);
                } else {
                    emit handleSwipe( Right);
                }
            } else {
                // vertical swipe detected, now find direction
                if( _startPoint.y() > _endPoint.y() && qAbs(yDiff)<10 ) {
                    emit handleSwipe( Up);
                } else {
                    emit handleSwipe( Down);
                }
            }
        } else if( event->type() == QEvent::MouseMove ) {
            //ignore event
        }
    }
    
    bool HeadlineWidget::event(QEvent *event)
    {
        _swipeGesture->handleEvent(event);
        return QWidget::event(event);
    }
    
    void HeadlineWidget::swipe(MySwipeGesture::SwipeDirection direction)
    {
        if(direction==MySwipeGesture::Left)
        {
            this->goNext();
        }
        else if(direction==MySwipeGesture::Right)
        {
            this->goPrev();
        }
        else
        {
            //click
            //showButton();
        }
    }
    
    void HeadlineWidget::goPrev()
    {
        sharedData::currentHeadline.time=sharedData::remainingList.at(sharedData::headlineIndex);
        sharedData::currentNote.headlines.takeAt(sharedData::headlineIndex);
        sharedData::currentNote.headlines.insert(sharedData::headlineIndex,sharedData::currentHeadline);
    
        if(sharedData::headlineIndex>0)
            sharedData::headlineIndex--;
        sharedData::currentHeadline=sharedData::currentNote.headlines.at(sharedData::headlineIndex);
        sharedData::headlineStartTime=QTime::currentTime();
    
        ui->label->setText(sharedData::currentHeadline.name);
        ui->label->repaint();
    }

  11. #11
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Out of memory when rotating device

    The thing to do is to output the numbers after each operation, eg, after each rotation. You can either put a button on your UI to do this manually or trigger it from an event filter that listens for the resize event on your layout.

    Then watch to see if the numbers increase steadily after each operation.

Similar Threads

  1. Rotating images
    By catalindragos in forum Mobile Java General
    Replies: 1
    Last Post: 2009-03-19, 15:04
  2. Replies: 4
    Last Post: 2008-11-15, 03:47
  3. Rotating Pieslice
    By Rafael T. in forum Symbian
    Replies: 2
    Last Post: 2008-10-16, 21:54
  4. Replies: 3
    Last Post: 2008-08-19, 22:55
  5. Replies: 2
    Last Post: 2004-05-05, 12:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×