Page 1 of 3 123 LastLast
Results 1 to 10 of 30

Thread: Yet another segfault (a.k.a. Darkhog is a total noob)

  1. #1

    Yet another segfault (a.k.a. Darkhog is a total noob)

    In current version of my game, I've set up debug room (accessed via right control+left shift+d on main menu) so I can test things in safe environment. And now I'm happy I've did that. Why? Because I've got weird segfault related to collisions. Collision function is 100 ok (masked_collision,collide(TSprite,TSprite)), problem lies either in how animated sprites are collising or in some weird clashing TGameObject stuff. Can someone help me? Code is available on github: https://github.com/darkhog/SuperHeliLand

  2. #2
    Isn't this an infinitely recursive loop? (could be wrong, difficult to trace types without downloading whole project)
    Code:
    function TGameObject.isColliding(Sprite: TSprite): Boolean;
    begin
      Result:=false; //setting result, just in case
      case ObjectMode of
        omAnim:   begin
                    if Animations.Items[CurrentAnim]<>nil then //safety check so we won't get segfault
                      //setting result
                      Result:=Animations.Items[CurrentAnim].IsColliding(Sprite);
                    end;
        omSprite: begin
                    if Sprites.Items[CurrentSprite]<>nil then //safety check so we won't get segfault
                      //setting result
                      Result:=Sprites.Items[CurrentSprite].IsColliding(Sprite);
                  end;
      end;
    end;
    Seems that it might not recurse. But in that code you could debug if CurrentAnim could go out of list boundaries.
    Last edited by User137; 18-07-2013 at 12:19 AM.

  3. #3
    No, function that is used is TGameObject.isColliding(GO:TGameObject). But thanks for suggestion, will try to check that.

  4. #4
    Nope, checked if it is in range and still segfaults.

  5. #5
    Are you sure CurrentSprite is a valid index?

    You should not do this, , but try this, it will avoid anything wrong :

    Code:
    function TGameObject.isColliding(Sprite: TSprite): Boolean;
    begin
      Result:=false; //setting result, just in case
    
      if (not Assigned(self)) or (not Assigned(Sprite)) then Exit;
    
      case ObjectMode of
        omAnim:   begin
                    if (CurrentAnim>0) and (CurrentAnim<=Animations.Items.Count-1) then
                    if Assigned(Animations.Items[CurrentAnim]) then //safety check so we won't get segfault
                      //setting result
                      Result:=Animations.Items[CurrentAnim].IsColliding(Sprite);
                    end;
        omSprite: begin
                    if (CurrentSprite>0) and (CurrentSprite<=Animations.Items.Count-1) then
                    if Sprites.Items[CurrentSprite]<>nil then //safety check so we won't get segfault
                      //setting result
                      Result:=Sprites.Items[CurrentSprite].IsColliding(Sprite);
                  end;
      end;
    end;

  6. #6
    I'm telling you this is not the right function, you're looking at! It
    Quote Originally Posted by Darkhog View Post
    is TGameObject.isColliding(GO:TGameObject).
    But I've used this code and it still crashes.

  7. #7
    Had another quick look on the github. Are you calling right constructor for TAnimatedSprite?
    Code:
    constructor TGameObject.Create(mode: TObjectMode);
    begin
      if mode=omAnim then Animations:=TAnimatedSpriteList.create;
    the .Create is TObject.Create, it seems. The .Create without parameters is not written to either TAnimatedSprite or TSprite.
    Last edited by User137; 18-07-2013 at 03:49 PM.

  8. #8
    *TAnimatedSpriteList. And for a while I've thought you're right, but TAnimatedSpriteList.create is defined on line 186 of Sprites.pas.

    Anyway, it then would crash as soon as I'd enter TDebugState since collision is checked constantly and thus Animations is accessed constantly and it only crashes if I make both game objects touch each other.

    It may be something with TAnimatedSprite class though.

  9. #9
    Any help? I can't pinpoint the issue at all!

  10. #10
    Where can I get al_ogg.pas file. I cant compile your project without it.

Page 1 of 3 123 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
  •