Jump to content

Animated gif buttons - lag and flickering - is there a way to stop it


Go to solution Solved by Nine,

Recommended Posts

I'm doing some animated buttons with gif files - the problems I have is program lag + gif display lag  + gif dropped frames + gif (and other GUI controls flickering)

I have put a zip file here https://ufile.io/rpnc9gjr with the gifs in so you can see what I mean with the flickering and lag and dropped frames - any ideas on how to fix?

 

(edit - it does not happen all the time - bad random - look at the GUI frame (that is a gif) for flickering and dropped frames)

 

;----> problem = program lag + gif appearance lag + dropped gif frames + gifs flickering

#include <Sound.au3>
#include "GIFAnimation.au3" ; For the gif animations > might be the problem in here
#include <Misc.au3>
#include <GUIConstants.au3>

Global $hDLL = DllOpen("user32.dll") ; Trapping a key/mouse press
Global $InvalidRollF = 0
Local $Fart = _SoundOpen(@ScriptDir & "\Fart.wav")

Global $InvalidGui = GUICreate("Invalid", 580, 435, 30, 30, $WS_POPUP, $WS_EX_TOPMOST)
GUISetBkColor(0xdadbdd)

_GUICtrlCreateGIF(@ScriptDir & "\valframe3.gif", "", 0, 0, 580, 435)
Local $valEixtBit = _GUICtrlCreateGIF(@ScriptDir & "\cat2.gif", "", 39, 307, 106, 90)
GUICtrlCreateLabel("press escape to quit", 50, 200)

GUISetState ()

Do
    $MousePos = MouseGetPos()
    If $MousePos[0] > 38 AND $MousePos[0] < 145 Then
        If $MousePos[1] > 306 AND $MousePos[1] < 396 Then
            If _IsPressed("01") Then
                    MsgBox($MB_SYSTEMMODAL, "", "right click")
            EndIf
            If $InvalidRollF = 0 Then
                _GIF_DeleteGIF($valEixtBit)
                _SoundPlay($Fart, 0)
                Local $valEixtBit = _GUICtrlCreateGIF(@ScriptDir & "\up3.gif", "", 39, 307, 106, 90)
                $InvalidRollF = 1 ; Set the 'Invalid Note Time' rollover flag to true

            EndIf
        Else
            If $InvalidRollF = 1 Then
                $InvalidRollF = 0
                _GIF_DeleteGIF($valEixtBit)
                Local $valEixtBit = _GUICtrlCreateGIF(@ScriptDir & "\cat2.gif", "", 39, 307, 106, 90)
            EndIf
        EndIf
    Else
        If $InvalidRollF = 1 Then
            $InvalidRollF = 0
            _GIF_DeleteGIF($valEixtBit)
            sleep(10)
            Local $valEixtBit = _GUICtrlCreateGIF(@ScriptDir & "\cat2.gif", "", 39, 307, 106, 90)
        EndIf
    EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE

 

Edited by Toyley2
Link to post
Share on other sites

can you upload your zip file in another site? maybe -> Mediafire,so i can help.

Edited by ad777

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

Link to post
Share on other sites
  • Solution
Posted (edited)

Thank you much Nine - the flickering and lags seems to be solved but now there are artefacts from gif frames on one of the gifs (edit - there was no artefacts from the gif with the old animated gif include)

I have put the problem here https://www.mediafire.com/file/fju58h9oicilq5n/gifprob2.zip/file

(Oh - I see I can upload files less than 4MB - done that as well)

gifprob2.zip

Edited by Toyley2
Link to post
Share on other sites
Posted (edited)

attached is a pic of the artefacts

 

(edit) 

 

something seems to be (maybe) missing in function __GDIPlus_CachedBitmapDispose in your UDF 'Cached GIF Animation.au3'
when gif has movement that changes the boundary with in its transparent background 


Func __GDIPlus_CachedBitmapDispose($hCachedBitmap)
  Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipDeleteCachedBitmap", "handle", $hCachedBitmap)
  If @error Then Return SetError(@error, @extended, False)
  If $aResult[0] Then Return SetError(10, $aResult[0], False)
  Return True
EndFunc   ;==>__GDIPlus_CachedBitmapDispose


I'm looking at code: DllCall($__g_hGDIPDll, "int", "GdipDeleteCachedBitmap", "handle", $hCachedBitmap)

and trying to find out how gif frame is deleted (and if there is a problem caused by boundary changes
over the gif's transparent pixels) 

anyway I'm stuck ......

 

artefacts.jpg

Edited by Toyley2
Link to post
Share on other sites

Ok, seems I have found the problem.  Your gif suppose erasable frames.  So we need to clear the previous image before showing the next.

Try this patch.Cached GIF Animation.au3

Using the line :

Local $valEixtBit = _GUICtrlCreateAnimGIF("Up3a.gif", 039, 307, 106, 90, -1, $GUI_WS_EX_PARENTDRAG, False, 0xdadbdd)

Works for me.

 

Edited by Nine
Link to post
Share on other sites
Posted (edited)

thanks Nine for looking at it and coming up with a plan

I did what you said (used the new "Cached GIF Animation.au3" and changed the line in my script to:

Local $valEixtBit = _GUICtrlCreateAnimGIF("Up3a.gif", 039, 307, 106, 90, -1, $GUI_WS_EX_PARENTDRAG, False, 0xdadbdd)

Things are much better than when I fist asked for help - now no artefacts and no widespread flickering and not much lag on the GUI - but the rollover gif (up3a.gif) flickers on its own with mouse over - I can't work out why ...

Edited by Toyley2
Link to post
Share on other sites
Posted (edited)

no - not that old - a standard Ryzen 9 5900X with 32GB ram

I'm just going to do roll-over jpg images for the button for now (otherwise I'm doing nothing and not producing anything) 

I'll do a screen cap vid later of the flickering and show you - thanks anyway :-)

 

(edited) flicker vid attached (a screen cap of the flickering gif run by the script - not the original gif)

 

flicker.gif

Edited by Toyley2
Link to post
Share on other sites

Alright, I was able to reproduce your flickering by slowing down the display of each frame.  The culprit is the erasure of each frame.  I should have thought of it sooner, sigh.

Anyway, so I need to introduce the well-know feature of back buffer with GDI+.  Now flickering completely disappears.  Could you test it ?  Thanks

Cached GIF Animation.au3

Link to post
Share on other sites

 

@Toyley2

I tested your script with help of Nine Cached GIF Animation.au3 and i got no lagg no flicker:

#include "Cached GIF Animation.au3"
#include "GIFAnimation.au3"
#include <Misc.au3>
#include <GUIConstants.au3>
;AdlibRegister('valframe3',250)
Global $hDLL = DllOpen("user32.dll") ; Trapping a key/mouse press
Global $InvalidRollF = 0

Global $InvalidGui = GUICreate("Invalid", 580, 435, 30, 30, $WS_POPUP, $WS_EX_TOPMOST)
GUISetBkColor(0xdadbdd)

Global $IMG_Ctrl1 = _GUICtrlCreateGIF(@ScriptDir & "\valframe3.gif", "", 0, 0, 580, 435)
Global $valEixtBit = _GUICtrlCreateAnimGIF("Up3a.gif", 039, 307, 106, 90, -1, $GUI_WS_EX_PARENTDRAG, False, 0xdadbdd)
GUICtrlCreateLabel("press escape to quit", 50, 200)

GUISetState()

Do
    $MousePos = MouseGetPos()
    If $MousePos[0] > 38 AND $MousePos[0] < 145 Then
        If $MousePos[1] > 306 AND $MousePos[1] < 396 Then
            If _IsPressed("01") Then
                MsgBox($MB_SYSTEMMODAL, "", "right click")
            EndIf
            If $InvalidRollF = 0 Then
                _GUICtrlDeleteAnimGIF($valEixtBit)
                Local $valEixtBit = _GUICtrlCreateAnimGIF("Up3a.gif", 039, 307, 106, 90, -1, $GUI_WS_EX_PARENTDRAG, False, 0xdadbdd)
                $InvalidRollF = 1 ; Set the 'Invalid Note Time' rollover flag to true
            EndIf
        Else
            If $InvalidRollF = 1 Then
                $InvalidRollF = 0
                _GUICtrlDeleteAnimGIF($valEixtBit)
                Local $valEixtBit = _GUICtrlCreateAnimGIF("cat2.gif", 039, 307, 106, 90, -1, $GUI_WS_EX_PARENTDRAG)
            EndIf
        EndIf
    Else
        If $InvalidRollF = 1 Then
            $InvalidRollF = 0
            _GUICtrlDeleteAnimGIF($valEixtBit)
            sleep(10)
            Local $valEixtBit = _GUICtrlCreateAnimGIF("cat2.gif", 039, 307, 106, 90, -1, $GUI_WS_EX_PARENTDRAG)
        EndIf
    EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE

 

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

Link to post
Share on other sites

Yaaaaaaaaaaay!

100% working with nothing wrong :-) - thank you Nine - you have enviable skills 

I was trying to do my own simple primitive gif cache like this (after saving each frame as a gif with transparent pixels - it didn't work properly

#include "Cached GIF Animation.au3"
#include <GUIConstants.au3>
#include "GIFAnimation.au3"

Global $InvalidGui = GUICreate("Invalid", 580, 435, 330, 30, $WS_POPUP)

_GUICtrlCreateAnimGIF("valframe3.gif", 0, 0, 580, 435)


#cs
    $G1 = _GUICtrlCreateAnimGIF("Gif\test1.gif", 40, 40, 215, 308, -1, $GUI_WS_EX_PARENTDRAG); too much flickering
    $G2 = _GUICtrlCreateAnimGIF("Gif\test2.gif", 40, 40, 215, 308, -1, $GUI_WS_EX_PARENTDRAG)
    $G3 = _GUICtrlCreateAnimGIF("gif\test3.gif", 40, 40, 215, 308, -1, $GUI_WS_EX_PARENTDRAG)
    $G4 = _GUICtrlCreateAnimGIF("gif\test4.gif", 40, 40, 215, 308, -1, $GUI_WS_EX_PARENTDRAG)
    $G5 = _GUICtrlCreateAnimGIF("gif\test5.gif", 40, 40, 215, 308, -1, $GUI_WS_EX_PARENTDRAG)
    $G6 = _GUICtrlCreateAnimGIF("gif\test6.gif", 40, 40, 215, 308, -1, $GUI_WS_EX_PARENTDRAG)
    $G7 = _GUICtrlCreateAnimGIF("gif\test7.gif", 40, 40, 215, 308, -1, $GUI_WS_EX_PARENTDRAG)
    $G8 = _GUICtrlCreateAnimGIF("gif\test8.gif", 40, 40, 215, 308, -1, $GUI_WS_EX_PARENTDRAG)
    $G9 = _GUICtrlCreateAnimGIF("gif\test9.gif", 40, 40, 215, 308, -1, $GUI_WS_EX_PARENTDRAG)
    $G10 = _GUICtrlCreateAnimGIF("gif\test10.gif", 40, 40, 215, 308, -1, $GUI_WS_EX_PARENTDRAG)
#ce

    $G1 = _GUICtrlCreateGIF("Gif\test1.gif", "", 40, 40, 215, 308) ; some random flickering
    $G2 = _GUICtrlCreateGIF("Gif\test2.gif", "",40, 40, 215, 308)
    $G3 = _GUICtrlCreateGIF("gif\test3.gif", "",40, 40, 215, 308)
    $G4 = _GUICtrlCreateGIF("gif\test4.gif", "",40, 40, 215, 308)
    $G5 = _GUICtrlCreateGIF("gif\test5.gif", "",40, 40, 215, 308)
    $G6 = _GUICtrlCreateGIF("gif\test6.gif", "",40, 40, 215, 308)
    $G7 = _GUICtrlCreateGIF("gif\test7.gif", "",40, 40, 215, 308)
    $G8 = _GUICtrlCreateGIF("gif\test8.gif", "",40, 40, 215, 308)
    $G9 = _GUICtrlCreateGIF("gif\test9.gif", "",40, 40, 215, 308)
    $G10 = _GUICtrlCreateGIF("gif\test10.gif", "",40, 40, 215, 308)

GUICtrlSetState($G1, $GUI_HIDE)
GUICtrlSetState($G2, $GUI_HIDE)
GUICtrlSetState($G3, $GUI_HIDE)
GUICtrlSetState($G4, $GUI_HIDE)
GUICtrlSetState($G5, $GUI_HIDE)
GUICtrlSetState($G6, $GUI_HIDE)
GUICtrlSetState($G7, $GUI_HIDE)
GUICtrlSetState($G8, $GUI_HIDE)
GUICtrlSetState($G9, $GUI_HIDE)
GUICtrlSetState($G10, $GUI_HIDE)

GUISetState ()

Do
    GUICtrlSetState($G10, $GUI_Hide)
    GUICtrlSetState($G1, $GUI_SHOW)
    sleep(100)
    GUICtrlSetState($G1, $GUI_Hide)
    GUICtrlSetState($G2, $GUI_SHOW)
    sleep(100)
    GUICtrlSetState($G2, $GUI_Hide)
    GUICtrlSetState($G3, $GUI_SHOW)
    sleep(100)
    GUICtrlSetState($G3, $GUI_Hide)
    GUICtrlSetState($G4, $GUI_SHOW)
    sleep(100)
    GUICtrlSetState($G4, $GUI_Hide)
    GUICtrlSetState($G5, $GUI_SHOW)
    sleep(100)
    GUICtrlSetState($G5, $GUI_Hide)
    GUICtrlSetState($G6, $GUI_SHOW)
    sleep(100)
    GUICtrlSetState($G6, $GUI_Hide)
    GUICtrlSetState($G7, $GUI_SHOW)
    sleep(100)
    GUICtrlSetState($G7, $GUI_Hide)
    GUICtrlSetState($G8, $GUI_SHOW)
    sleep(100)
    GUICtrlSetState($G8, $GUI_Hide)
    GUICtrlSetState($G9, $GUI_SHOW)
    sleep(100)
    GUICtrlSetState($G9, $GUI_Hide)
    GUICtrlSetState($G10, $GUI_SHOW)
    sleep(100)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

):

 

 

Link to post
Share on other sites

Glad it finally worked out for your :)

But thanks for bringing me a GIF that was creating a bug in my UDF.

BTW, you should DL my latest version of the UDF as I made a few other changes. (see signature)

Edited by Nine
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...