Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 587
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

ListItemProvider Segfault

I'm getting a segfault when I press the "Back" button on a page that has a ListView.

 

The stack trace is shows the crash happening in ListItemProvider's destructor. (I'm subclassing ListItemProvider)

 

... but I didn't write ListItemProvider's destructor, so I'm a bit unclear on why it would be crashing.  Some of the stack trace mentioned "deleteChildren", so perhaps it's trying to free the object allocated by the:

 

VisualNode* PhotoGridListItemProvider::createItem(ListView* list, const QString& type)

 

... function?

 

As for why it would have an issue doing that, I have no idea.

 

Here's my createItem function, if that's useful.

 

VisualNode* PhotoGridListItemProvider::createItem(ListView* list, const QString& type)
{
    ImageView* imageView = ImageView::create();

    imageView->setScalingMethod(ScalingMethod::AspectFill);

    return imageView;
}

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: ListItemProvider Segfault

Make sure you are removing all objects not parented and leaving those parented for the parent to remove.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 587
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: ListItemProvider Segfault

I'm not removing any objects in the destructor at all... so if anything, I would expect a memory leak, but not a sefault!

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: ListItemProvider Segfault

What I would do in your situation is set some breakpoints around the area and try and narrow down the line that is causing the crash.

If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 587
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: ListItemProvider Segfault

The crash is happening when the "Back" button is pressed, which destroys the Page.  So there isn't really a "line of code" that's causing the crash, in the sense of there being a line of my code.  It's simply the Page being destroyed.  And as mentioned, the crash itself isn't in my code, it's just the ListItemProvider getting destroyed.  If I had the source code of ListItemProvider, I could theoretically figure out what line of code is going poof, but I don't have that. (that I know of)

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: ListItemProvider Segfault

99% of the time it will definitely be a line in your code whether that be QML, JavaScript or C++. :-)

Post your ListtemProvider subclass perhaps it's something in there we can spot.

If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 587
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: ListItemProvider Segfault

Here it is. (and I think we're on the same page -- I have no doubt it's an issue with my app. I thought you were suggesting I could figure out what the issue was by finding the line that was directly segfaulting)

 

/*
 * PhotoGridListItemProvider.cpp
 *
 *  Created on: Mar 29, 2014
 *      Author: Daniel
 */

#include "PhotoGridListItemProvider.hpp"

QMap<ImageView*, QString> PhotoGridListItemProvider::imageViewMap = QMap<ImageView*, QString>();

PhotoGridListItemProvider::PhotoGridListItemProvider()
{
}

PhotoGridListItemProvider::~PhotoGridListItemProvider()
{
}

VisualNode* PhotoGridListItemProvider::createItem(ListView* list, const QString& type)
{
    ImageView* imageView = ImageView::create();

    imageView->setScalingMethod(ScalingMethod::AspectFill);

    return imageView;
}

void PhotoGridListItemProvider::updateItem(ListView* list, VisualNode* listItem, const QString& type, const QVariantList& indexPath, const QVariant& data)
{
    //qDebug() << "PhotoGridListItemProvider::updateItem";

    QVariantMap item = data.value<QVariantMap>();
    ImageView *imageView = static_cast<ImageView*>(listItem);

    QString filePath = item["image"].toString();

    // These thumbnails are too often missing, and are too low quality. We'll create our own.
    //QImage qimage = JpegThumbnailFetcher::fetchThumbnail(filePath);
    //qDebug() << "Thumbnail width: " << qimage.width();
    //qDebug() << "Thumbnail height: " << qimage.height();
    //bb::ImageData imageData = bb::ImageData&colon;:fromPixels(qimage.rgbSwapped().bits(), bb::PixelFormat::RGBX, qimage.width(), qimage.height(), qimage.bytesPerLine());
    //bb::cascades::Image image = imageData;

    ThumbnailResponse* thumbnailResponse = ThumbnailService::getInstance()->getThumbnail(filePath);

    QString thumbnailFile = thumbnailResponse->getThumbnailFilename();
    if (thumbnailFile.isNull())
    {
        qDebug() << "Thumbnail doesn't yet exist.";

        // Keep track of which file has been assigned to which ImageView, so that
        // we can check after the thumbnail has been generated that our ImageView
        // wasn't assigned to some other picture in the ListView. (reused when
        // scrolling)
        imageViewMap[imageView] = filePath;

        thumbnailResponse->setImageView(imageView);

        bool connectRes = connect(thumbnailResponse, SIGNAL(thumbnailReady()), (PhotoGridListItemProvider*)this, SLOT(thumbnailReady()));
        Q_ASSERT(connectRes);

        thumbnailResponse->buildThumbnail();
    }
    else
    {
        //qDebug() << "Thumbnail already exists: " << thumbnailFile;

        QString filePath = QFileInfo(thumbnailFile).absoluteFilePath();

        //qDebug() << "  full path: " << filePath;

        imageView->setImageSource(QUrl("file://" + filePath));
    }
}

void PhotoGridListItemProvider::thumbnailReady()
{
    ThumbnailResponse* thumbnailResponse = qobject_cast<ThumbnailResponse*>(sender());

    qDebug() << "thumbnailReady(); thumbnailResponse: " << thumbnailResponse;

    QString photoFilename = thumbnailResponse->getPhotoFilename();

    ImageView* imageView = thumbnailResponse->getImageView();

    // UNDOME: Relaxing this for testing.
    // Make sure this ListItem is still owned by this photo. (maybe it got re-used for some other photo)
    if (imageViewMap[imageView] == photoFilename)
    {
        QString thumbnailFilename = thumbnailResponse->getThumbnailFilename();

        qDebug() << "thumbnailFilename: " << thumbnailFilename;

        QString filePath = QFileInfo(thumbnailFilename).absoluteFilePath();

        qDebug() << "  full path: " << filePath;

        imageView->setImageSource(QUrl("file://" + filePath));
    }
    else
    {
        qDebug() << "Looks like this PhotoGridListItemProvider got reclaimed.";
        qDebug() << "  " << imageViewMap[imageView] << " vs " << photoFilename;
    }

    // I think we need to free the memory here. Hopefully.
    free(thumbnailResponse);
}

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: ListItemProvider Segfault

Yes, unlike Android where you can dip in to the source code, very useful at times, you cannot with BlackBerry.

Hmm, okay it's not as simple as I hoped it would be, with the ThumbnailResponse.

Not sure you need to free the memory at the end and doing it this way on an asynchronous call strikes me as risky.
And as I understand free it should only be used on memory allocators, use delete for objects.

Also have you checked for multiple calls?

If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Highlighted
Developer
Posts: 587
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: ListItemProvider Segfault

Sorry for the delayed response.  Thanks for the reminder about delete VS free.  What were you referring to specially by "multiple calls"?  Multiple calls to what?