From 1d270de33662c28df555dad325f2e8bf9a5bf4a7 Mon Sep 17 00:00:00 2001 From: gambas Date: Mon, 11 Jan 2021 01:24:20 +0100 Subject: [PATCH] Do not crash anymore when loading an Animation fails. [DEVELOPMENT ENVIRONMENT] * BUG: Don't use the deprecated MovieBox.Path property anymore. [GB.GTK] * BUG: Do not crash anymore when loading an Animation fails. [GB.GTK3] * BUG: Do not crash anymore when loading an Animation fails. [GB.QT4] * BUG: Do not crash anymore when loading an Animation fails. [GB.QT5] * BUG: Do not crash anymore when loading an Animation fails. --- app/src/gambas3/.src/Help/FHelpBrowser.form | 4 +- gb.gtk/src/canimation.cpp | 35 +++++++-------- gb.qt4/src/canimation.cpp | 47 +++++++++------------ 3 files changed, 38 insertions(+), 48 deletions(-) diff --git a/app/src/gambas3/.src/Help/FHelpBrowser.form b/app/src/gambas3/.src/Help/FHelpBrowser.form index 9c02e5ebb..af8a0b9ea 100644 --- a/app/src/gambas3/.src/Help/FHelpBrowser.form +++ b/app/src/gambas3/.src/Help/FHelpBrowser.form @@ -106,10 +106,10 @@ } } { movWaiting MovieBox - MoveScaled(31,5,9,8) + MoveScaled(58,6,9,8) Visible = False Ignore = True - Path = "img/waiting.gif" + Animation = Animation.Load("img/waiting.gif") Alignment = Align.Center } { Printer1 #Printer diff --git a/gb.gtk/src/canimation.cpp b/gb.gtk/src/canimation.cpp index 800ed4917..a84b1d862 100644 --- a/gb.gtk/src/canimation.cpp +++ b/gb.gtk/src/canimation.cpp @@ -108,34 +108,37 @@ static void free_movie(void *_object) GB.ReleaseFile(THIS->addr, THIS->len); } -static bool load_movie(void *_object, char *path, int len) +static void *load_movie(char *path, int len_path) { + void *_object; + char *addr; + int len; GdkPixbufLoader *loader; - free_movie(THIS); - - if (len <= 0) - return false; - - if (GB.LoadFile(path, len, &THIS->addr, &THIS->len)) - return true; + if (GB.LoadFile(path, len_path, &addr, &len)) + return NULL; loader = gdk_pixbuf_loader_new(); - if (!gdk_pixbuf_loader_write(loader, (guchar*)THIS->addr, (gsize)THIS->len, NULL)) + if (!gdk_pixbuf_loader_write(loader, (guchar*)addr, (gsize)len, NULL)) { g_object_unref(G_OBJECT(loader)); GB.Error("Unable to load animation"); - return true; + return NULL; } gdk_pixbuf_loader_close(loader, NULL); + _object = GB.Create(GB.FindClass("Animation"), NULL, NULL); + + THIS->addr = addr; + THIS->len = len; + THIS->animation = gdk_pixbuf_loader_get_animation(loader); g_object_ref(G_OBJECT(THIS->animation)); g_object_unref(G_OBJECT(loader)); - return false; + return THIS; } @@ -156,15 +159,7 @@ END_METHOD BEGIN_METHOD(Animation_Load, GB_STRING path) - void *anim = GB.Create(GB.FindClass("Animation"), NULL, NULL); - - if (load_movie(anim, STRING(path), LENGTH(path))) - { - GB.Unref(&anim); - return; - } - - GB.ReturnObject(anim); + GB.ReturnObject(load_movie(STRING(path), LENGTH(path))); END_METHOD diff --git a/gb.qt4/src/canimation.cpp b/gb.qt4/src/canimation.cpp index 5772a5cb3..f943dbc2d 100644 --- a/gb.qt4/src/canimation.cpp +++ b/gb.qt4/src/canimation.cpp @@ -51,24 +51,29 @@ static void free_movie(void *_object) GB.ReleaseFile(THIS->addr, THIS->len); } -static bool load_movie(void *_object, char *path, int len) +static void *load_movie(char *path, int len_path) { - free_movie(THIS); - - if (len > 0) - { - if (GB.LoadFile(path, len, &THIS->addr, &THIS->len)) - return true; + void *_object; + char *addr; + int len; - THIS->data = new QByteArray(); - *THIS->data = QByteArray::fromRawData((const char *)THIS->addr, THIS->len); - THIS->buffer = new QBuffer(THIS->data); - THIS->buffer->open(QIODevice::ReadOnly); - THIS->movie = new QMovie(THIS->buffer); - dict.insert(MOVIE, THIS); - } + if (GB.LoadFile(path, len_path, &addr, &len)) + return NULL; + + _object = GB.Create(GB.FindClass("Animation"), NULL, NULL); + + THIS->addr = addr; + THIS->len = len; + THIS->data = new QByteArray(); + *THIS->data = QByteArray::fromRawData((const char *)THIS->addr, THIS->len); + THIS->buffer = new QBuffer(THIS->data); + THIS->buffer->open(QIODevice::ReadOnly); + THIS->movie = new QMovie(THIS->buffer); + dict.insert(MOVIE, THIS); - return false; + QObject::connect(THIS->movie, SIGNAL(frameChanged(int)), &CAnimationManager::manager, SLOT(change())); + + return THIS; } @@ -89,17 +94,7 @@ END_METHOD BEGIN_METHOD(Animation_Load, GB_STRING path) - void *anim = GB.Create(GB.FindClass("Animation"), NULL, NULL); - - if (load_movie(anim, STRING(path), LENGTH(path))) - { - GB.Unref(&anim); - return; - } - - QObject::connect(((CANIMATION *)anim)->movie, SIGNAL(frameChanged(int)), &CAnimationManager::manager, SLOT(change())); - - GB.ReturnObject(anim); + GB.ReturnObject(load_movie(STRING(path), LENGTH(path))); END_METHOD