
-----------------------------------
sarm2005
Wed Mar 05, 2008 9:58 am

Bugs in code
-----------------------------------
For some reason the Pic.FileNew command stops working after I press a key a few times. could someone help me fix it.


setscreen ("graphics:800,600")
View.Set ("offscreenonly")
var fishx, fishy, angle, fishpic, fishangle : int := 0
var value, count : int := 1
var ch : string (1)
var chars : array char of boolean
randint (fishx, 1, maxx - 64)
randint (fishy, 1, maxy - 35)
fishpic := Pic.FileNew ("Fish_" + intstr (count) + "_G.bmp")
Pic.Draw (fishpic, fishx, fishy, picMerge)
loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        fishpic := Pic.FileNew ("Fish_" + intstr (count) + "_G.bmp")
        Pic.Draw (fishpic, fishx, fishy, picMerge)
        if count > 0 and count < 10 then
            count := count + 1 * value
            fishy := fishy + 10
            delay (75)
            View.Update
            cls
        elsif count > 9 then
            value := -1
            count := 8
        elsif count < 1 then
            value := 1
            count := 2
        end if
    elsif chars (KEY_RIGHT_ARROW) then
        fishpic := Pic.FileNew ("Fish_" + intstr (count) + "_G.bmp")
        fishangle := Pic.Rotate (fishpic, angle, -1, -1)
        Pic.Draw (fishangle, fishx, fishy, picCopy)
        Pic.Free (fishpic)
        Pic.Free (fishangle)
        angle := angle - 10
        if count > 0 and count < 10 then
            count := count + 1 * value
            delay (75)
            View.Update
            cls
        elsif count > 9 then
            value := -1
            count := 8
        elsif count < 1 then
            value := 1
            count := 2
        end if
    elsif chars (KEY_LEFT_ARROW) then
        fishpic := Pic.FileNew ("Fish_" + intstr (count) + "_G.bmp")
        fishangle := Pic.Rotate (fishpic, angle, -1, -1)
        Pic.Draw (fishangle, fishx, fishy, picMerge)
        angle := angle + 10
        if count > 0 and count < 10 then
            count := count + 1 * value
            delay (75)
            View.Update
            cls
        elsif count > 9 then
            value := -1
            count := 8
        elsif count < 1 then
            value := 1
            count := 2
        end if
    end if
end loop


-----------------------------------
Tony
Wed Mar 05, 2008 10:42 am

RE:Bugs in code
-----------------------------------
You are not using Pic.Free -- your code should stop working after 1000 or so Pic.New calls.

-----------------------------------
riveryu
Wed Mar 05, 2008 8:50 pm

RE:Bugs in code
-----------------------------------
Just adding a tiny bit to Tony, there should be as many Pic.Free as there is Pic.FileNew. U should use them as if they are brackets.
