Lua playing up?

Started by garry23, March 17, 2019, 08:22:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

garry23

@a1ex

I've reached a point where I believe there may (sic) be a Lua issue, ie rather than my bad programing ;-)

Here is the code:

--[[
Cycler
Version 0.1
Garry George April  2019
http://photography.grayheron.net/
--]]

config = 1
max_config = 5
-- Change the Cycler button to your choice, for example
-- B1 = PLAY and B2 = INFO on an 5D3, and B1 = INFO and B2 = PLAY on a EOSM
button_1 = KEY.INFO -- imode switch and set
button_2 = KEY.PLAY -- used to go forwards in imode
button_3 = KEY.MENU -- used to go backwards in imode
cycled = true
timer = dryos.ms_clock
timer_running = false

menu.set("Expo","Auto ETTR",0)
menu.set("Shoot","Advanced Bracket",0)
menu.set("Overlay","Waveform",0)
menu.set("Overlay","Magic Zoom",0)

function reset(k)
    if cycled then
        if config == 1 then
            -- normal play function, so reset everything
            menu.set("Expo","Auto ETTR",0)
            menu.set("Shoot","Advanced Bracket",0)
            menu.set("Overlay","Waveform",0)
            menu.set("Overlay","Magic Zoom",0)
        elseif config == 2 then -- switch on ETTR
            menu.set("Expo","Auto ETTR",1)
        elseif config == 3 then -- switch on bracketing
            menu.set("Expo","Auto ETTR",0)
            menu.set("Shoot","Advanced Bracket",1)
        elseif config == 4 then -- switch on Magic Zoom
            menu.set("Shoot","Advanced Bracket",0)
            menu.set("Overlay","Magic Zoom",1)
        elseif config == 5 then -- switch on Waveform
            menu.set("Shoot","Advanced Bracket",0)
            menu.set("Overlay","Waveform",1)
        end
        cycled = false
    else
        -- do nothing
    end
end

function test4reset(k)
    if k == button_2 then
        if timer_running then
            if dryos.ms_clock - timer < 500 then -- normal button action
                timer_running = false
                cycled = true
                return true
            else
                config = config + 1
                if config > max_config then config = 1 end
                cycled = true
                timer_running = false
                return false
            end
        else
            timer = dryos.ms_clock
            timer_running = true
            cycled = false
            return false
        end
       
    end
    cycled = false
    return true
end

event.shoot_task = reset
event.keypress = test4reset

lv.info
{
    name = "Cycler State",
    value = "",
    priority = 100,
    update = function(this)
    this.background = COLOR.WHITE
    this.foreground = COLOR.BLACK
        if config == 1 then
            this.value = "PLAY"
        elseif config == 2 then
            this.value = "ETTR"
        elseif config == 3 then
            this.value = "Auto"
        elseif config == 4 then
            this.value = "Zoom"
        elseif config == 5 then
            this.value = "Wave"
        end
    end
}


The problem occurs when you cycle through the options and reach the waveform option.

All this state does is switch off the previous ML state, ie Magic Zoom, and switch on waveform.

All other state changes work fine.

At the waveform state change, the cam (EOSM) freezes.

As I say, it may be my programing, but I don't believe so.

Cheers

Garry

a1ex

Reproduced only once; afterwards, it worked fine (i.e. without crash) every single time. Not sure how to trigger it.

Operation is far from intuitive, btw.

garry23

@a1ex

Yes that was my experience, ie sometimes it worked, but mostly it didn't.

BTW the script is now published on GitHub (without the waveform change): https://gist.github.com/pigeonhill/7974b876c4fbf6de1b7ab1c3f64e77e6

The idea behind the script, which I will write about, is to provide a simple means to cycle through various ML menu states.

The latest version cycles when you quickly press PLAY twice (but you can choose another button if you wish). If you press this button with a delay between the two presses it will function the button normally.

I'll carry on tweaking the script and have another look at the 'waveform problem' tonight: off to work now.

Cheers

Garry

garry23

@a1ex

I tried various approaches, but the Waveform fails to work in my cycler script: strange.

I inserted display.clear and in desperation tried lv.resume, before trying to switch on the waveform.

Sometimes OK, but usually not, ie cam just freezes.

All other menu changes using the script work fine.

Oh well...such is life ;-)

Cheers

Garry

a1ex

Solved. It wasn't really Lua's fault, but a race condition in waveform code. The crash could only happen when enabling the waveform outside ML menu.

TODO: rewrite ML in Rust to avoid this kind of errors?

garry23

@a1ex

Great news, ie cause known.

Do you believe there is a 'work around' in scripting, eg a delay etc?

Cheers

Garry

a1ex

Workaround (for this particular issue, for older builds only): open ML menu, change options, close it. Or, change the options outside LiveView.

Recommended way: just update to latest lua_fix build.

garry23

@a1ex

Hadn't spotted the Lua fix update  ;)

Cheers

Garry

garry23

@a1ex

Just tried out the latest Lua fix and calling Waveform.

Seems to work now as expected.

The only observation I would make is if one switches off Waveform, via menu.set("Overlay","Waveform",0), the waveform remains displayed.

Work around is to call display.clear().

As I say, just an observation.

Cheers

Garry