[Interest] App crashing because of ImageProvider when exiting

Nuno Santos nunosantos at imaginando.pt
Wed Jul 25 13:35:56 CEST 2018


Sérgio,

Thanks for your reply.

I have tried the following:

ImageProvider imageProvider;

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    Controller controller;

    QQmlApplicationEngine engine;

    engine.rootContext()->setContextProperty("controller", &controller);
    engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
    engine.addImageProvider("pictures", &imageProvider);

    return app.exec();
}

No success, still crashing at exit.

malloc: *** error for object 0x10b69efd8: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

The crash goes away if I comment engine.addImageProvider("pictures", &imageProvider);

What am I missing here?

Thanks!

Nuno

> On 25 Jul 2018, at 12:20, Sérgio Martins <sergio.martins at kdab.com> wrote:
> 
> Hi Nuno,
> 
> 
> The docs for QQmlEngine::addImageProvider() say: "The QQmlEngine takes ownership of provider".
> 
> So QQmlEngine::removeImageProvider() is calling free() on stack variable, hence it complains that address wasn't heap allocated.
> 
> Create it on the heap as suggested by Jean-Michaël.
> 
> 
> Regards,
> -- 
> Sérgio Martins | sergio.martins at kdab.com <mailto:sergio.martins at kdab.com> | Senior Software Engineer
> Klarälvdalens Datakonsult AB, a KDAB Group company
> Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
> KDAB - The Qt, C++ and OpenGL Experts
> 
> 
> 
> On 2018-07-25 11:59, Nuno Santos wrote:
>> Jean,
>> This is the main context. It will not get out until app.exec() terminates.
>> That’s why I’m connecting to aboutToQuit signal in order to remove the
>> provider from the Qml engine.
>> I had the provider instantiated inside the controller but I was having
>> this problem already, therefore my efforts in getting it fixed.
>> QQmlApplicationEngine *e;
>> int main(int argc, char *argv[])
>> {
>>    QGuiApplication app(argc, argv);
>>    Controller controller;
>>    QQmlApplicationEngine engine;
>>    e = &engine;
>>    engine.rootContext()->setContextProperty("controller", &controller);
>>    engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
>>    ImageProvider imageProvider;
>>    engine.addImageProvider("pictures", &imageProvider);
>>    QObject::connect(&app, &QGuiApplication::aboutToQuit, [=]()
>>    {
>>        e->removeImageProvider("pictures");
>>    });
>>    return app.exec();
>> }
>> Any ideas?
>> Regards,
>> Nuno
>>> On 25 Jul 2018, at 11:30, Jean-Michaël Celerier <jeanmichael.celerier at gmail.com> wrote:
>>> Shouldn't you allocate your ImageProvider on the heap or at least ensure that it survives during the whole execution ? here it will be deleted by the end of your function
>>> -------
>>> Jean-Michaël Celerier
>>> http://www.jcelerier.name <http://www.jcelerier.name/> <http://www.jcelerier.name/ <http://www.jcelerier.name/>>
>>> On Wed, Jul 25, 2018 at 11:24 AM, Nuno Santos <nunosantos at imaginando.pt <mailto:nunosantos at imaginando.pt> <mailto:nunosantos at imaginando.pt <mailto:nunosantos at imaginando.pt>>> wrote:
>>> Hi,
>>> Yesterday I have used for the first time a QQuickImageProvider but I’m having problems because now the app crashes when I terminate it.
>>> Tried to do the following in order to avoid the crash but it is crashing anyway:
>>> ImageProvider imageProvider;
>>> engine.addImageProvider("pictures", &imageProvider);
>>> QObject::connect(&app, &QGuiApplication::aboutToQuit, [=]()
>>> {
>>>    e->removeImageProvider("pictures");
>>> });
>>> The crash is always something like this:
>>> malloc: *** error for object 0x7ffeef34e900: pointer being freed was not allocated
>>> Does anyone knows how to fix this?
>>> Thanks!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180725/504eb742/attachment.html>


More information about the Interest mailing list