Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Utilities

edited March 31 in Code Sharing Posts: 815
All,

Picking up on the problem kirl had with Codea crashing out, has anyone put together a small library of trace routines
etc so debugging is easier? All I use is the FPS and memory displays that I posted. But I seem to remeber writing trapped data to a tab. Any other utils?

Comments

  • dave1707dave1707 Mod
    Posts: 6,828

    I normally use print statements or to comment out code. Sometimes writing to tabs or project/global data works too. How you debug code take practice, so the more buggy code you write, the better you get a debugging.

  • Posts: 815

    @dave1707 - thanks for that, I don’t think there is much more than that. I also started a list of iPad system specs so that I could recognise what system my code was running on - iPad, iPhone, iPad mini etc but never finished it. That could be a useful developer utility.

  • dave1707dave1707 Mod
    Posts: 6,828

    Here’s something that might work. Add the dBug function to your code and the first 3 lines in setup. Leave the first 2 commented for now. Then in each function you want to check, add as the first line dBug(“function name”). Each time that function is executed, it calls the dBug function and adds the function name to the start of the string str. The first 200 characters of str is then saved as global data. Function names will be added and saved until the code crashes. Then before you restart the code, uncomment the first 2 lines and run the code again. The first line will print the functions that were executed in reverse order. The second line stop() is an invalid function so the code will stop and let you see the list of functions printed. The testName function is just an example to show how to do the dBug call.

    function setup()
        --print(readGlobalData("dbugData"))
        --stop()
        str=""
    end
    
    function draw()
        background(40, 40, 50)
    end
    
    function testName()
        dBug("testName")
    end
    
    function dBug(s)
        str=s.."\n"..str
        if #str>200 then
            str=string.sub(str,1,200)
        end
        saveGlobalData("dbugData",str)
    end
    
  • Posts: 815

    @dave1707 - excellent, thanks for that, it gives some traceability which I haven't been able to do to date. These techniques should be widely published so that anyone with a problem knows how to approach it.

  • dave1707dave1707 Mod
    Posts: 6,828

    Here’s an updated version of the dBug(s) function. Apparently string.sub doesnt care if the length of str isn’t 200 bytes to start. Therefore, the if code isn’t required. That should speed it up a little.

    function dBug(s)
        str=s.."\n"..str
        str=string.sub(str,1,200)
        saveGlobalData("dbugData",str)
    end
    
Sign In or Register to comment.