Results 1 to 5 of 5

Thread: FIX: Unexplained Access Violation

  1. #1
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default FIX: Unexplained Access Violation

    Hey guys,

    I'm sure I'm not the only one who's had their share of access violation errors, especially the ones that Pascal Script decides not to specify exactly what the problem is. Well, I was reminded of what causes this and was asked to create a thread about it so it doesn't happen to anyone else.

    When working with custom types, most people use some sort of "get" function that will return the that custom type. As far as I know, this is the only way to create the access violation, but it may also occur on some built-in types such as TPoints. Run this in a new Simba:
    Simba Code:
    program new;

    type
      TExample = record
        name: string;
        value, count: integer;
      end;

    function getExample(): TExample;
    begin
      with result do
      begin
        name := 'example one';
        value := 0;
        count := 10;
      end;
    end;

    begin
      clearDebug();

      if (getExample().value <= 0) then
        writeln('Y');
    end.
    You should get an "Access violation" error. The issue is in line 22: you apparently can't call getExample like that. Keep in mind that this only seems to happen when you use it in a comparison.

    The solution? Simply use a variable:
    Simba Code:
    program new;

    type
      TExample = record
        name: string;
        value, count: integer;
      end;

    function getExample(): TExample;
    begin
      with result do
      begin
        name := 'example one';
        value := 0;
        count := 10;
      end;
    end;

    var
      exam: TExample;
    begin
      clearDebug();

      exam := getExample();
      if (exam.value <= 0) then
        writeln('Y');
    end.
    Hopefully this will avoid some frustration.

    Cheers,
    Cohen

    P.S. This may end up turning into a FAQ thread.
    Last edited by Coh3n; 08-12-2011 at 05:16 AM.

  2. #2
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    This has been a PS bug for a long time.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  3. #3
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    This has been a PS bug for a long time.
    Yeah, I know. Now people know what not to do. Saves the hours of frustration that I went through. >.<

  4. #4
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Yeah, I know. Now people know what not to do. Saves the hours of frustration that I went through. >.<
    Haha, yes. I did the same a long time ago. Twas quite frustrating. I also think the issue is casued with built in types too. For example, TPoints.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  5. #5
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    Haha, yes. I did the same a long time ago. Twas quite frustrating. I also think the issue is casued with built in types too. For example, TPoints.
    Updated the first post.
    Last edited by Coh3n; 08-12-2011 at 05:17 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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