Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: List Index Out Of Bounds

  1. #1

    List Index Out Of Bounds

    This relates to DelphiX.
    I've been trying to make a remake of 1942(the top-down scrolling shooter) and my code for shooting bullets looks as follows:

    The Bullet Class:

    Code:
    TBullet = class(TImageSprite)
     Public
      Procedure DoMove(MoveCount: Integer); override;
      Procedure DoCollision(Sprite: TSprite; var Done: Boolean); override;
     End;
    The Shooting Code In The Timer:

    Code:
    Dec(Shot_Rate);
     If (Shot_Rate < 0) And (GetKeyState(32) and 128 = 128){<-- The player has pressed Spacebar(32)}
      Then
      Begin
      Shot_Rate := 10;// So as not to shoot continuously
      With TBullet.Create(Engine.Engine) Do
       Begin
         Image := Sprites.Items.Find('Bullet');
         X := Hero.X + (Hero.Width DIV 2 - 15);
         Y := Hero.Y;
         Z := 14;
         Width := Image.Width;
         Height := Image.Height;
        End;//With
      End;//If
    The DoMove Looks as follows:
    Code:
    procedure TBullet.DoMove(MoveCount: Integer);
    begin
     inherited;
     Collision;
     Y := Y - 5;
     If Y < (0 - Height)
      Then Free;
    The Problem is:
    If I shoot 1 bullet and let it leave the screen, everything works fine.
    However, If I shoot a bullet and then shoot another one BEFORE the first bullet leaves the screen I get the error: "Project Plane_Project Raised Exception Class EListError with message 'List index out of bounds(10)'. Use Step Or Run To Continue"

    Without the Free; the program works fine however, If I shoot continuously for a long time, the framerate decreases

    Any Ideas?

  2. #2
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,234
    Blog Entries
    2

    Re: List Index Out Of Bounds

    First up... you need to paste the line (and the code) around the error. There is no list manipulation in the code you've given, so without the area around the error, it's going to be pretty difficult to assist.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  3. #3

    Re: List Index Out Of Bounds

    The .exe(and source) of the first version can be found at: https://sourceforge.net/projects/delphixdemo/
    I hope it helps

  4. #4

    Re: List Index Out Of Bounds

    First, what's up with this?

    Code:
    GetKeyState(32) and 128 = 128
    Last time I checked 128 equals 128

    Now I don't use DelphiX but it seems to me, that you add the bullets to an engine. But when you free the bullets you don't remove them from the engine. I don't know if this is done automatically, but if not this may cause some errors.

    Hope it helps a bit.
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  5. #5
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,234
    Blog Entries
    2

    Re: List Index Out Of Bounds

    Quote Originally Posted by Cer3brus
    The .exe(and source) of the first version can be found at: https://sourceforge.net/projects/delphixdemo/
    I hope it helps
    It does, quite substantially... I've just found that unDelphiX includes a unit with the same name as one in the DevExpress component suite, so I've just mailed the maintainer of unDelphiX.

    Anyhow... back on topic ;-)

    I've just downloaded your code, and the latest version of unDelphiX and having fixed the problem with the conflict between unDelphiX and DevExpress, I've compiled your code. I'm sorry (well... kind of sorry) to say that I can't reproduce the problem. I'm kind of sorry because it implies it's either an unDelphiX bug which could potentially be fixed by the latest version or its a compiler bug.

    So, which version of Delphi and unDelphiX are you using? If it's not the latest version of unDelphiX, download that and try recompiling to see if that fixes the problem.

    Hope this helps.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  6. #6

    Re: List Index Out Of Bounds

    I think I might have a solution to your problem. Compiled in Delphi 6 and I changed the following:

    In your bullet.move procedure instead of calling free, call dead and then in your onTimer event call engine.dead.

    Let me know if this works

    But...even though the error is fixed your game seems to run slower after a while so something is not freed properly....
    Wake up from the dream and live your life to the full

  7. #7

    Re: List Index Out Of Bounds

    Only thing that comes to mind after reading comments, is maybe small debug you can try.

    (just for testing all is ok and freed)
    1. Add to interface section a new variable to main unit for example SprCount: integer;
    2. before Engine.Move; put command SprCount:=0;
    3. after Engine.Move; place some code that prints SprCount. This could be form.caption, label or canvas.
    4. place inc(SprCount); code to onMove event of every object that spriteengine uses. Place it as first line before any if/for or other statements.

    Result:
    If SprCount keeps growing up you will know something is not freed. At that point you can remove step 4 code from objects you don't suspect and test again.
    If SprCount is stable and steady, then the problem may lie deep in DelphiX or something else.

  8. #8

    Re: List Index Out Of Bounds

    probably freeing the sprite removes it from the Owner list, this probably is the cause of the problem,

    the solution was already pointed by Wizard

    let us know if it worked
    From brazil (:

    Pascal pownz!

  9. #9

    Re: List Index Out Of Bounds

    Thanks!!
    I'll try out the solutions and see what I find and post it up.
    I'm actually using an old version of DelphiX, so I think it's probably a version bug.
    I think I might get a tutorial going here....

  10. #10

    Re: List Index Out Of Bounds

    The new unDelphiX(http://www.micrel.cz/Dx/) refuses point blank to install nicely
    Maybe I made a mess of the installation? Are there any tutorials around?

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL