Results 1 to 12 of 12

Thread: Function Pointer Access Violation

  1. #1
    Join Date
    May 2012
    Posts
    10
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default Function Pointer Access Violation

    Trying to write a function that waits for the result of a function().

    Simba Code:
    function ConditionWait(condition: function: Boolean;  ms: Integer): Boolean;
    var
      timeout: TCountDown;
    begin
      timeout.SetTime(ms);;
      repeat
        if (timeout.IsFinished()) then
          Exit(False);
      until(condition()); // Access Violation Here
      Exit(True);
    end;

    This is how I am calling it. I am getting an access violation.
    Simba Code:
    if (ConditionWait(@TDialogue.HasDialogue(), 5000)) then
      begin
        // ...
      end

  2. #2
    Join Date
    Dec 2013
    Location
    Pitcairn Island
    Posts
    288
    Mentioned
    20 Post(s)
    Quoted
    166 Post(s)

    Default

    Quote Originally Posted by gmkizzle View Post
    Trying to write a function that waits for the result of a function().

    Simba Code:
    function ConditionWait(condition: function: Boolean;  ms: Integer): Boolean;
    var
      timeout: TCountDown;
    begin
      timeout.SetTime(ms);;
      repeat
        if (timeout.IsFinished()) then
          Exit(False);
      until(condition()); // Access Violation Here
      Exit(True);
    end;

    This is how I am calling it. I am getting an access violation.
    Simba Code:
    if (ConditionWait(@TDialogue.HasDialogue(), 5000)) then
      begin
        // ...
      end
    Good luck figuring out any ogLib code - the most un-user-friendly thing ever to be written on these forums.

    Anyway, just use waitTypeFunc() from SRL-6. Should be what you need.

    https://github.com/SRL/SRL-6/blob/ma...ime.simba#L331

  3. #3
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Remove parenthesis.

  4. #4
    Join Date
    Apr 2013
    Posts
    680
    Mentioned
    13 Post(s)
    Quoted
    341 Post(s)

    Default

    Quote Originally Posted by Laquisha View Post
    Good luck figuring out any ogLib code - the most un-user-friendly thing ever to be written on these forums.

    Anyway, just use waitTypeFunc() from SRL-6. Should be what you need.

    https://github.com/SRL/SRL-6/blob/ma...ime.simba#L331
    LOLed!

    <------------------>



  5. #5
    Join Date
    Nov 2016
    Posts
    3
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Good luck figuring out any ogLib code

  6. #6
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    First off, you are trying to call a type function without using a reference to an actual instance of that type.
    Second, you are trying to pass in a different type than is expected. When using a type function you have to append "of object" to the return type of the parameter:

    Simba Code:
    program new;

    type foo = record
      bar: integer;
    end;

    function foo.baz(): boolean;
    begin
      exit(true);
    end;

    // what you have
    function waitforcondition(callback: function: boolean; timeout: integer): boolean;
    var
      start: longword;
    begin
      start := getsystemtime;
      while (start + timeout) >= getsystemtime do
      begin
        if callback then exit(true);
        wait(5);
      end;
    end;

    // what you need
    function waitforcondition(callback: function: boolean of object; timeout: integer): boolean; overload;
    var
      start: longword;
    begin
      start := getsystemtime;
      while (start + timeout) >= getsystemtime do
      begin
        if callback then exit(true);
        wait(5);
      end;
    end;

    var
      f: foo;
    begin
      // create an instance of foo
      f := [1];
      // use that instance's function reference, not the type reference
      writeln(waitforcondition(@f.baz, 3000));
    end.

  7. #7
    Join Date
    Sep 2014
    Location
    C:\Simba\
    Posts
    565
    Mentioned
    9 Post(s)
    Quoted
    71 Post(s)

    Default

    This thread was dead since a long time but the spambot grave dug it...
    Feel free to ask me any questions, I will do my best to answer them!

    Previously known as YouPee.

  8. #8
    Join Date
    Mar 2013
    Posts
    1,010
    Mentioned
    35 Post(s)
    Quoted
    620 Post(s)

    Default

    Quote Originally Posted by Joopi View Post
    This thread was dead since a long time but the spambot grave dug it...
    So? tls gave a decent answer which explained stuff which wasn't in earlier posts and it wasn't grave dug according to the current rules.
    #slack4admin2016
    <slacky> I will build a wall
    <slacky> I will ban reflection and OGL hooking until we know what the hell is going on

  9. #9
    Join Date
    Oct 2012
    Posts
    1,258
    Mentioned
    40 Post(s)
    Quoted
    588 Post(s)

    Default

    Quote Originally Posted by Harrier View Post
    So? tls gave a decent answer which explained stuff which wasn't in earlier posts and it wasn't grave dug according to the current rules.
    @Joopi; was just practicing not quoting/@mentioning anybody in a post. Exceptional work this time around fam, keep it up.

  10. #10
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by acow View Post
    @Joopi; was just practicing not quoting/@mentioning anybody in a post. Exceptional work this time around fam, keep it up.
    yeah exceptional backseat modding by Joopi as always LOL


    why did the derep button have to go

  11. #11
    Join Date
    Sep 2014
    Location
    C:\Simba\
    Posts
    565
    Mentioned
    9 Post(s)
    Quoted
    71 Post(s)

    Default

    My point being that whoever asked this question has long since stopped caring and hasnt even been logged in for several weeks. @Harrier;

    But sure someone, at some point, might need it in 10 years or so. But not worth the effort.
    Feel free to ask me any questions, I will do my best to answer them!

    Previously known as YouPee.

  12. #12
    Join Date
    Mar 2013
    Posts
    1,010
    Mentioned
    35 Post(s)
    Quoted
    620 Post(s)

    Default

    Quote Originally Posted by Joopi View Post
    My point being that whoever asked this question has long since stopped caring and hasnt even been logged in for several weeks. @Harrier;

    But sure someone, at some point, might need it in 10 years or so. But not worth the effort.
    Just because someone hasn't logged in for two weeks means you shouldn't answer it and explain it? My God and tls put the effort in so who cares? It's there is someone needs it in the future.
    Last edited by Harrier; 11-24-2016 at 05:46 PM.
    #slack4admin2016
    <slacky> I will build a wall
    <slacky> I will ban reflection and OGL hooking until we know what the hell is going on

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
  •