Page 1 of 2 12 LastLast
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
    Quote Originally Posted by phibermon View Post
    User137 is correct, you don't have 'Create' defined in the TAnimatedSprite interface but you do have it in the implementation section. As a result you're not calling that 'Create' in your Gameobject creation, instead it'll be calling whatever 'Create()' it next finds, probably TObject.
    Is he?

    Quote Originally Posted by User137 View Post
    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.
    Let's repeat code part, shall we?
    Code:
    constructor TGameObject.Create(mode: TObjectMode);
    begin
      if mode=omAnim then Animations:=TAnimatedSpriteList.create;
    Yup, just as I thought. I'm not creating TAnimatedSprite, but TAnimatedSpriteList. Slight difference, you know? And guess what, it does have parameter-less constructor.

    Also where did you get that BAADF00D from? It doesn't appear anywhere during compilation, debugging or in my posts...

    And thanks for optimization tip, I've just turned it off.

    //edit: Sorry that I might sound a bit rude, but I have today my birthday. No one gave me wishes except some automatic from websites and I didn't even get a cake. And yes, I can also exclude "surprise birthday party" as day is almost ending (23:22 or 11:22PM).
    Last edited by Darkhog; 27-07-2013 at 09:23 PM.

  2. #2
    No, i wasn't correct on my guess last time. Can you perhaps zip the source+media files, and attach to forum post? Would be easier to test with compiler...

  3. #3
    You can clone my git repo... It's pretty current one.

  4. #4
    Yeah found the download link Either you commented the bugs away, or fixed it, but i don't see problems in menu.
    PS. phibermon edited his post with fixes.

  5. #5
    Quote Originally Posted by User137 View Post
    Yeah found the download link Either you commented the bugs away, or fixed it, but i don't see problems in menu.
    PS. phibermon edited his post with fixes.
    No, you need to access debug screen. It's right ctrl+left shift+d in main menu. Then, after you touch "other" mario with submarine, game'll crash.

  6. #6
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    Happy birthday

    It's your update() method in the main unit that's running in a separate thread via an Allegro timer, if you call that in your main thread loop instead then that'll fix your problem.

    You are correct about the create defintion, so my apologies However if me and 137 made exactly the same mistake then it might suggest your code could benefit from some formatting.

    I'm only teasing I'm glad we found the issue, it's a great project and please keep the updates on progress coming!
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  7. #7
    Just to echo something that was said earlier...

    Whenever you use the condition:

    If SomePointerReference <> Nil Then

    it is much better (more portable, readable, etc) if you use this instead:

    If Assigned(SomePointerReference) Then

    It is an inline function/macro, so it shouldn't be less efficient.

  8. #8
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    Quote Originally Posted by Murmandamus View Post
    Just to echo something that was said earlier...

    Whenever you use the condition:

    If SomePointerReference <> Nil Then

    it is much better (more portable, readable, etc) if you use this instead:

    If Assigned(SomePointerReference) Then

    It is an inline function/macro, so it shouldn't be less efficient.
    Assigned() was created to allow coders to make clear distinctions between checking to see if a func pointer is nil and checking if the result of an assigned function is nil. so without Assigned : MyFunc=nil and MyFunc()=Nil and with assigned : Assigned(MyFunc) and MyFunc()=nil.

    Probably best to use Assigned for readability, It's most likely an inline function however It's also an overloaded function so I believe there's run-time type checking going on, don't really know but probably is. If so it'd be technically faster to stick with nil comparisons. Maybe, I'm only assuming that type checking for overloaded functions is run-time for all types, I think it is for class types. Or maybe not, class instance reference being a pointer, maybe you can't have overloaded functions for different class types with the same calling conventions, meaning that overloading might be a compile time thing. Perhaps the compiler will optimize when the program only ever uses one version of the overloaded function. Maybe.

    I'm probably giving this too much thought. I'm a bit bored today. In fact it'd probably just be quicker to fire up Lazarus and try overloading a function with different class types.

    EDIT : yes you can overload with identical calling convention for different class types so it's Run Time type checking and nil comparisions are faster (At least in ObjFPC mode with FPC) for class references and pointers. Assuming of course that a nil comparison isn't also subject to run-time checks, which it probably isn't as it wouldn't get past the compile time checks.

    I should imagine overloaded functions with different conventions are sorted out at compile time though.
    Last edited by phibermon; 28-07-2013 at 05:22 PM.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  9. #9
    Quote Originally Posted by phibermon View Post
    Assigned() was created to allow coders to make clear distinctions between checking to see if a func pointer is nil and checking if the result of an assigned function is nil. so without Assigned : MyFunc=nil and MyFunc()=Nil and with assigned : Assigned(MyFunc) and MyFunc()=nil.
    The distinction is important when you do not explicitly use the Nil constant value. Assigned may have been originally intended for that, it became used generally for opaque pointer references, to maintain that opacity.

    Probably best to use Assigned for readability, It's most likely an inline function however It's also an overloaded function so I believe there's run-time type checking going on, don't really know but probably is. If so it'd be technically faster to stick with nil comparisons. Maybe, I'm only assuming that type checking for overloaded functions is run-time for all types, I think it is for class types. Or maybe not, class instance reference being a pointer, maybe you can't have overloaded functions for different class types with the same calling conventions, meaning that overloading might be a compile time thing. Perhaps the compiler will optimize when the program only ever uses one version of the overloaded function. Maybe.
    Assigned() is a built-in function handled by the compiler. I don't think it is overloaded, as there are no definitions to overload. It only works on types which ultimate derive from, or are identical to, the Pointer type. It shouldn't be any slower than a comparison to Nil, since that is what it is replaced with at compile-time, at least on the Windows platform.

    I'm probably giving this too much thought. I'm a bit bored today. In fact it'd probably just be quicker to fire up Lazarus and try overloading a function with different class types.

    EDIT : yes you can overload with identical calling convention for different class types so it's Run Time type checking and nil comparisions are faster (At least in ObjFPC mode with FPC) for class references and pointers. Assuming of course that a nil comparison isn't also subject to run-time checks, which it probably isn't as it wouldn't get past the compile time checks.

    I should imagine overloaded functions with different conventions are sorted out at compile time though.

    I have no idea what you are referring to with respect to Assigned. It is simply a built-in function which the compiler hard-codes to a Nil check. If you're not explicitly using Nil as a data value, or are dealing with opaque (pointer) types, it is more "proper" to use Assigned.

  10. #10
    Quote Originally Posted by phibermon View Post
    Happy birthday

    It's your update() method in the main unit that's running in a separate thread via an Allegro timer, if you call that in your main thread loop instead then that'll fix your problem.

    You are correct about the create defintion, so my apologies However if me and 137 made exactly the same mistake then it might suggest your code could benefit from some formatting.

    I'm only teasing I'm glad we found the issue, it's a great project and please keep the updates on progress coming!
    Well, I'd put it into main loop, if only I wouldn't need to call update EXACTLY 60 times per second, so game won't run too fast on more powerful machines than my own.

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
  •