Results 1 to 10 of 30

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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.

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
  •