Results 1 to 8 of 8

Thread: What's a SIGSEGV exception?

  1. #1

    What's a SIGSEGV exception?

    System : Windows XP
    Compiler: Lazarus (most recent version)
    Libraries: OpenGL

    Hello, I have written a very simple program in Lazarus using OpenGL and the LazOpenGLbox that someone posted here on PGD a while ago, but every time I try to compile+run it, it comes up with a message box saying something about an External SIGSEGV error...

    What should I do? Where does it come from?

    thanks for your help!

  2. #2

    What's a SIGSEGV exception?

    SIGSEGV = Segmentation Fault = Access Violation under Win

    most probably you are accessing invalid memory location....

  3. #3
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    What's a SIGSEGV exception?

    Common causes are;

    :arrow: miscalculating array ranges in your loops,
    :arrow: accessing objects when not created,
    :arrow: or just plain and simple trying to access memory that was not allocated for use. (ie. a texture that didn't load --though in OpenGL this will hang your app. :?)
    Jason McMillen
    Pascal Game Development
    Co-Founder





  4. #4

    What's a SIGSEGV exception?

    Ok, I understand where my mistake is now.

    However, as Im learning the very basics of Object Orientated Pascal with all the classes and stuff, I've been learning from other programs that I found online and I try to understand how it works.

    I obviously haven't managed to initialize my object properly since the error occurs everytime I try to access a variable from that class.
    Here is a copy of my program:
    http://files-upload.com/347054/DrawerNtWkng.rar.html
    Could someone have a look (the unit having problems is 'Background') and tell me what I'm not doing properly, please?
    Is it the way I do my properties? What's the proper way of doing it? Or is it just the way I initialize my variables?

    Thanks a lot!

  5. #5
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    What's a SIGSEGV exception?

    Hi ILP,

    Object Pascal does take a second set of understanding on top of knowing Pascal it's self. But the good news is that it'll be worth it once you've 'gotten it' and it'll be just like riding a bicycle.

    Some cardinal rules of thumb are:

    1) always allocate your objects before you try to use them.
    2) free (or deallocate) EVERYTHING you create (or allocate) or you'll have memory leaks in your program each time you don't.
    3) if you want to access procedures, functions, properties, methods or variables from OUTSIDE your object, be sure to make them public.

    #3 is done by default though so if you don't specify public or private in your object class OR anything you put above where you put private will automatically be public. This is mostly for design time and organizational purposes, it means nothing to the end user.

    [size=9px]Checking your source... (btw, it is sometimes best if you can post your code in the forums. Provided that it's not too big or it's directly relevant to the direct problem. And again, sometimes not. )[/size]
    Jason McMillen
    Pascal Game Development
    Co-Founder





  6. #6
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    What's a SIGSEGV exception?

    Ok, had a quick look.

    The first problem I see is that you seem to have copied over your lpr file. :? It looks just like the Background.pas unit.

    Background.pas doesn't show me anything useful. Heres why:

    1) I cannot see how you are creating or freeing your objects.

    Your constructor and destructor are fine. You could alternately do the following...
    [pascal]type
    TMyClass = class(TObject)
    end;[/pascal]
    ...and your Create and Free constructors would already exist due to the fact that it's a descendant of the base class 'TObject', which is handy as it has that basic functionality already.

    The truth is it doesn't really matter what you do inside of those two though. You can have a 'Hello world!' program in there, once it's done executing it'll create or destroy the object.

    Creating your own constructor or destructor is only useful if you have something extra to do such as assigning some basic values to variables or freeing allocated memory from within your object. Those are common uses, but there may be more obviously.

    The best that I can do at this point is show you in short how to properly create and free an object you have already declared.

    [pascal]
    // Declare
    type
    TSimpleObject = class(TObject)
    end;
    var
    MyObject: TSimpleObject;

    begin
    // Create
    MyObject := TSimpleObject.Create;

    // Destroy
    MyObject.Free;
    [/pascal]

    That all there is to it really.

    Why can't you just call 'MyObject.Create'? Well because MyObject is just a pointer not the actual object so you have to tell it what it belongs to before it can do anything. Since TSimpleObject is where all the function code is, only after you have pointed MyObject to it will it be able to properly execute the code.

    On that same principle 'MyObject.Free' will work just fine because it already is pointing to where it needs and is fully allocated.


    Hope this helps. If not then let us know and we'll do our best to clear up any fuzzy spots.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  7. #7

    What's a SIGSEGV exception?

    Hey! Thank you so much for this very comprehensive reply!
    Now I know what I was doing wrong. I wasn't doing
    background := TBackground.Create
    but simply
    background.Create
    !
    Thanks again, great reply!

  8. #8
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    What's a SIGSEGV exception?

    np
    Jason McMillen
    Pascal Game Development
    Co-Founder





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
  •