supplierdeeply

help: how to debug script interrupting?

  • 224 Replies
  • 10860 Views
  • Publish
    help: how to debug script interrupting?
    « on: 01 / July / 2012, 09:31:02 »
    Advertisements
    Hi all,
    I have a lua script (quite complex)
    sometimes it interrupts by itself showing
    "PRESS SHUTTER TO CLOSE"
    nothing more, no errors code, etc...

    I'm running the script on 60 cameras and it is absolutly random,
    it happens on some cams and on some not...
    sometimes it happen after a minute
    sometimes after 20 minutes
    sometimes it doesn't happen at all...
    (different for each cam where it happens...)

    I really cant figure out how to debug this problem...
    any advice?

    thanks

  • Publish
    Re: help: how to debug script interrupting?
    « Reply #1 on: 01 / July / 2012, 10:20:19 »
    Telling us your camera model and posting a copy of the script might be a good place to start ?

  • Publish
    Re: help: how to debug script interrupting?
    « Reply #2 on: 01 / July / 2012, 10:34:51 »
    ok, sorry,

    cam is Canon SX130IS

    the script where the problem sometimes happens, sometimes not is:
    (actually the script is much longer but other parts are never reached or called)

    --[[
    @title SCRIPT_TEST
    ]]

    function waitForSetMenu()
        local x = 0
        local p = 0
        local pressTime = 0
        local pulseTime = 0
        local menuItem = 0
       
        print(" READY ")
       
       
        while x < 1 do
            sleep(100)
            if is_pressed("remote") then
                if p < 1 then
                    pressTime = r_get_tick_count()
                    p = 1
                else
                    pulseTime = r_get_tick_count()
                    if (pulseTime-pressTime > 1000) then
                        pressTime = pulseTime
                        play_sound(4)
                        menuItem = menuItem +1
                        print("")
                        print("CURRENT CFG = ",menuItem)
                        sleep(100)
                    end 
                end
            else
                if p > 0 then
                    x = 1
                end
            end
        end
    end

    local retVal = waitForSetMenu()
    print("CHOOSED CFG IS = "..retVal)


    the problem raises even if I dont do anything (no press buttons, remote, etc...)

    thanks

  • Publish
    Re: help: how to debug script interrupting?
    « Reply #3 on: 01 / July / 2012, 10:46:04 »
    Is this the entire script you are testing at this point ? 

    If you want to paste longer scripts in,  use the wiki editor # button on the tool bar - you'll get a nice scrolling text box when your script is displayed.  Like this :

    Code: [Select]
    --[[
    @title SCRIPT_TEST
    ]]

    function waitForSetMenu()
        local x = 0
        local p = 0
        local pressTime = 0
        local pulseTime = 0
        local menuItem = 0
       
        print(" READY ")
       
       
        while x < 1 do
            sleep(100)
            if is_pressed("remote") then
                if p < 1 then
                    pressTime = r_get_tick_count()
                    p = 1
                else
                    pulseTime = r_get_tick_count()
                    if (pulseTime-pressTime > 1000) then
                        pressTime = pulseTime
                        play_sound(4)
                        menuItem = menuItem +1
                        print("")
                        print("CURRENT CFG = ",menuItem)
                        sleep(100)
                    end 
                end
            else
                if p > 0 then
                    x = 1
                end
            end
        end
    end

    local retVal = waitForSetMenu()
    print("CHOOSED CFG IS = "..retVal)

    And while its probably not what's causing your issue,  you don't seem to have a "return" statement in your function yet the second to last line expects something in retVal ?



  • Publish
    Re: help: how to debug script interrupting?
    « Reply #4 on: 01 / July / 2012, 11:14:50 »
    sorry I forgot to copy last line

    -> return menuItem

    that's not the problem as you guessed.

    As the script starts it goes in the while loop
    and since I dont press anything
    it loops forever (till, sometimes, crashes without reasons).

    there are a lot of other code & functions in the actual script
    but those are never executed/reached (since I just loop forever till a crash)

    thanks for the wiki editor tip.

  • Publish
    Re: help: how to debug script interrupting?
    « Reply #5 on: 01 / July / 2012, 11:21:54 »
    sorry I forgot to copy last line

    -> return menuItem


    Ummm ... that doesn't go on the "last line".   It needs to be up in the function somewhere.

    Quote
    that's not the problem as you guessed.

    As the script starts it goes in the while loop
    and since I dont press anything
    it loops forever (till, sometimes, crashes without reasons).

    there are a lot of other code & functions in the actual script
    but those are never executed/reached (since I just loop forever till a crash)
    Understood -  as long as you never press anything,  it should loop forever.   So that code is not the problem.   

    Other possible problems ?  The script is too big and causes a random crash maybe ?  There is actually something else in the code that you are SURE never gets executed but actually does ?   Hence the question about seeing the whole script.

    What happens if you just try to run the snippet you posted as a simple script ?


  • Publish
    Re: help: how to debug script interrupting?
    « Reply #6 on: 01 / July / 2012, 12:41:14 »
    Quote
    Ummm ... that doesn't go on the "last line".   It needs to be up in the function somewhere.

    yeah, sorry I meant "last line of the function before the end...".

    However I'll adopt your suggestion and let run a simple script with just the code I wrote to see if things change.

    I'll write results as soon as available

    Thanks for support.

  • Publish
    Re: help: how to debug script interrupting?
    « Reply #7 on: 01 / July / 2012, 13:20:45 »
    ok,
    so the problem arise also in the little code snippet
    after about 7 minutes one of my camera exited from script
    saying "PRESS SHUTTER TO CLOSE" and nothing more.

    This is the complete script I've been running:

    Code: [Select]
    --[[
    @title Rtest (01.07.12)
    ]]



    function waitForSetMenu()
        local x = 0
        local p = 0
        local pressTime = 0
        local pulseTime = 0
        local menuItem = 0
     
        print("START")
       
        while x < 1 do
            sleep(100)
            if is_pressed("remote") then
                if p < 1 then
                    pressTime = r_get_tick_count()
                    p = 1
                else
                    pulseTime = r_get_tick_count()
                    if (pulseTime-pressTime > 1000) then
                        pressTime = pulseTime
                        play_sound(4)
                        menuItem = menuItem +1
                        print("")
                        print("CURRENT CFG = ",menuItem)
                        sleep(100)
                    end 
                end
            else
                if p > 0 then
                    x = 1
                end
            end
        end   
       
        return menuItem
    end



    local rv = waitForSetMenu()
    print("VALUE = "..rv)
       


    the only "place" where I can guess ther error is, is the "is_pressed" function...
    which is the only one really used in the loop

    i will try now to use
    wait_click(100)
    if is_key("remote") then ...


    instead of
    sleep(100)
    if is_pressed("remote") then ...


    thanks for any advice...
    « Last Edit: 01 / July / 2012, 13:31:15 by Alarik »


  • Publish
    Re: help: how to debug script interrupting?
    « Reply #8 on: 01 / July / 2012, 13:45:23 »
    Two questions :

    1) Will your cameras stay running if you just put them in a simple "sleep" loop

    Code: [Select]
    @title Test
    do
       sleep(1000)
    until ( 0 )

    or

    Code: [Select]
    --[[
    @title R1test
    ]]

    function waitForSetMenu()
        repeat
            sleep(1000)
        until ( false )   
        return menuItem
    end

    local rv = waitForSetMenu()
    print("VALUE = "..rv)

    The first one is obviously in uBASIC.   When I was porting the SD940, using function calls in Lua would make it crash.  I forget what finally fixed that - there were lots of weird things going on during the early days of my first porting attempt.


    2) I assume you've disable the built-in "automatic shutdown" function that Canon provides ?
    « Last Edit: 01 / July / 2012, 13:50:02 by waterwingz »

    *

    Offline reyalp

    • ******
    • 9872
  • Publish
    Re: help: how to debug script interrupting?
    « Reply #9 on: 01 / July / 2012, 14:26:16 »
    The usual way to debug this kind of thing would be to throw prints in the different conditions to see what path it is taking. If that would be to voluminous, you can use lua io to log to a file, or record your state in variables and output it in the "restore" function that's called on script terminate (if there's a real chdk bug, restore might not be called, of course)
    Don't forget what the H stands for.

     

    Related Topics