Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Allocation Error
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
prdukt




PostPosted: Mon May 23, 2005 7:20 pm   Post subject: Allocation Error

code:

include "global/view.t" % loads needed information


% ---------------------------------------------------------
% character class (motion, draw, shooting)
% main class for game
class char_

    export draw

    var c_x, c_y : int := 0
    var c_state : string (1)
    var walkright_frames : array 1 .. 5 of int
    var ani_num : int := 1

    procedure load_images

        % loads walkright_frames (walking - right direction)
        walkright_frames (1) := Pic.FileNew ("animations/vasava/walkright_1.bmp")
        Pic.SetTransparentColor (walkright_frames (1), white)
        walkright_frames (2) := Pic.FileNew ("animations/vasava/walkright_2.bmp")
        Pic.SetTransparentColor (walkright_frames (2), white)
        walkright_frames (3) := Pic.FileNew ("animations/vasava/walkright_3.bmp")
        Pic.SetTransparentColor (walkright_frames (3), white)
        walkright_frames (4) := Pic.FileNew ("animations/vasava/walkright_4.bmp")
        Pic.SetTransparentColor (walkright_frames (4), white)
        walkright_frames (5) := Pic.FileNew ("animations/vasava/walkright_4.bmp")
        Pic.SetTransparentColor (walkright_frames (5), white)


    end load_images

    procedure draw
        load_images


        % draws character
        Pic.Draw (walkright_frames (ani_num), c_x, c_y, picCopy)

    end draw

end char_


var CHAR : pointer to char_
new char_, CHAR

class bg

    export draw

    procedure draw

        Pic.ScreenLoad ("1.bmp", 0, 0, picMerge)

    end draw

end bg


var BG : pointer to bg
new bg, BG

loop
    BG -> draw
    CHAR -> draw
end loop


Just starting to work on some extra credit work.

I have a character who walks in a 5 image pattern (Not employing this yet). When I run this it times out after roughly 3 seconds because "Cannot Allocate Item. Out of id numbers (max 1000)". This is highlighted in:

code:
walkright_frames (1) := Pic.FileNew ("animations/vasava/walkright_1.bmp")


Anyone have any idea how i can fix this up? (Global.t is just my View.Set information)
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Mon May 23, 2005 7:59 pm   Post subject: (No subject)

That's because you're not freeing the picture. Whenever you make a variable equal to a different picture, you need to free it. It can only change pictures about 171 times (don't ask why or how I know this).

But it also doesn't make sense why you're constantly making that variable equal to that pic. It's running constantly in the loop. Just take out those vars and put them at the top of your code, don't keep them in the loop unless you plan on changing them constantly.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: