Codea Freezes every time

Hi, I had been working on a game and everything was going well but now Codea freeze on me. Always after the same events, a touch after some actions occured in the game and i can repeat it at will. After lots of debugging, and finding nothing i have decided to put these 2 lines :

At the start of draw()

counter = counter + 1
print("enter draw " … Counter)

At the end of draw()

counter = counter + 1
print("out of draw " … Counter)

At the start of touched(touch)

counter = counter + 1
print("enter touch " … Counter)

At the end of touched(touch)

counter = counter + 1
print("out of touch " … Counter)

The last statement appearing in the debug window before it freeze is “out of touch xxx”. So this enabled me to verify that Codea is not looping in my code. Then the question is: Why execution is not resuming at the start of the draw function ? I do not monitor any other events besides touch. Is there something i don’t understand or i am not aware of ?

Note: In my experience when ios freeze it is often do to a out of memory issue so i closed every apps on my ipad mini and rebooted before testing. It did not help. My game does not use that much.

Any help would be extremely appreciated as i had great hopes in this software. Thank You.

really, how can we help if you dont post the code?

We need to see the code.

This probably because you gave an infinite loop somewhere

We need the full code, usually a point that “causes” an error (or what you found “causes” a freeze) isn’t actually the cause of it, it just affects a different line that freezes it or crashes it.

I have 15 classes and over 2500 lines of codes, that’s pretty big to post…

The point of my question is I can assume it GOT OUT of touched(touch) since I have a print that gets executed and that is at the end of it. So what else can Codea do after that but resume execution at the start of draw() ? Witch it does not because the first line in it is an other print that never gets executed. :frowning:

Thanks for any help.

@Richelieu6 The only thing I can suggest is to keep putting in print statements and try to track it down that way. It will take time, but you’ll eventually find it.

That is pretty much what I did for the past month, and it goes smoothly everywhere, until it exit of touched(touch), then the app completely freeze to the point that even if I cancel Codea and try to restart it, iOS takes around 10 seconds to be able to do so. The app dies, the draw() function does not gets called (i have a print as the first line in it) and I am not monitoring any other events. I don’t know what to do next.

@Richelieu6 How big is your “touched” function or do you have a lot of them in different classes. Maybe you could post the one you think is causing the problem.

@Richelieu6 - one thing I do is to try to cut down the code as much as possible to isolate the error. Comment out as much of it as possible, and keep doing it until the problem disappears. Then you have some idea of where the problem is.

Good advice. Thanks. And I will post some code when i get back home (i am writing this from an Apple store). I can get to the point where it won’t freeze anymore but I need the code commented out witch is not anything special anyway. Is there known issues that makes Codea freeze ?

The only known issue that I can think of is bad coding that all of us have done from time to time. I still put Codea in infinite loops.

dave1707 +1

My touch function is quite simple:

function touched(touch)

    msgn = msgn + 1
    print("touch in "..msgn)
    
    math.randomseed(touch.id)  -- Use the touch id as the random seed
    
    if not interface:touched(touch) then 
        if game then game.world:touched(touch) end     
    end
    
    print("touch out "..msgn)
end

Before freezing "touch out " gets printed, that is the last statement that does. Since I do not monitor any other events, the only code that could get executed after that is the draw function or the touched function again but neither does because a new print would occur and it does not. The touched function redirect the touches to the interface or game world but as far as I know, any touch to the screen should go through that function first.

The draw:


function draw()

    msgn = msgn + 1 
    print("draw in"..msgn)
    
    background(187, 159, 159, 255)

    if game then game.world:draw() end
    
    -- Display interface if game or not.
    interface:draw()
    
    -- Main Game Loop
    if game then
        if game.currentPlayer then
            if game.currentPlayer.human then
                -- do nothing
            else
                game.currentPlayer.ai:playTurn()
                game.currentPlayer:endTurn()
            end
        else
            game:endTurn()
        end
    end
    
    print("draw out "..msgn)
end

@Richelieu6 - it does look odd, but my experience is it will probably turn out to be something small that is obvious in retrospect! I have found Codea to be very stable and I don’t think it has ever frozen for me unless either I created an infinite loop, overloaded the graphics cache, or did something extremely exotic. So it’s likely to be a bug, I think.

Seeing as a touch freezes your program, I would try commenting out the if tests in your touched function (so the function does nothing). If that helps, then the problem is in those if tests, and you can drill down into them. If it doesn’t help, you will have to look to the rest of your code for the problem.

We can try to help, but only by seeing code. You can put it on github or somewhere similar if you are prepared to share (to copy all your code tabs at once, go out to the main Codea menu, press on your project icon until some options pop up, then touch “copy”).

@Richelieu6 One thing I see you’re doing wrong is “print” statements in the draw routine. You will print 120 lines per second. That in itself will crash Codea after awhile.

@Richelieu6 When you post code to the forum, put 3~ on a line before and after your code to format it correctly. I added them before and after you’re code above.

@dave1707 - I don’t think two print statements in draw is causing the problem, I do that regularly without problems

@Ignatz You’re right, It’s late and I’m not sure what I was thinking about.

@Richelieu6 anyway try suppressing this print in the draw to check the result. You can print in the draw, but not every frame!