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.
This commit is contained in:
parent
8c4fc6d10c
commit
1d270de336
3 changed files with 38 additions and 48 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue