Results 1 to 9 of 9

Thread: access violation with freedtm()

  1. #1
    Join Date
    Aug 2008
    Location
    !!LOL!!
    Posts
    247
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default access violation with freedtm()

    SCAR Code:
    program New;
    {.include srl/srl.scar}

    var
    salmon:integer;

    procedure LOADDTMS;
    begin
      salmon := DTMFromString('78DA639CC9C4C0F08C0105ECAFCA651001D28' +
           'C40FC1F0818A701D5DC6140038C482490EE00AA794740CD5422D4' +
           'CC07AA794C40CD42A09A1BF8D5000076370EB9');

    end;

    begin
    cleardebug;
    setupsrl;
    activateclient;
    LOADDTMS;
    wait(3000);
    ItemAmount('inv', 'dtm', salmon, []);
    salmon := salmon + ItemAmount('inv', 'dtm', salmon, []);
    writeln('salmons = ' + inttostr(salmon) + '.')
    freedtm(salmon);
    end.
    y does it keep access violating??plz help and explain ty

  2. #2
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    You cant add something onto a DTM, you have to assign count items area to a different integer.

  3. #3
    Join Date
    Aug 2008
    Location
    !!LOL!!
    Posts
    247
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    err i didnt understand it does count and it works but wenever it reaches freedtm
    it does the acc.... but if i put it in the loaddtms procedure it acc.... before it counts

  4. #4
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    You can't change the salmon variable, because it currently holds a DTM. When you change it, it causes FreeDTM to work incorrectly, resulting in an Access Violation error. To fix your problem, simply make another variable to store your count.
    Interested in C# and Electrical Engineering? This might interest you.

  5. #5
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You can't free an invalid DTM and that sometimes also happens when you try to free a DTM that is not loaded.

    SCAR Code:
    program New;
    {.include srl/srl.scar}

    var
      SalmonDTM : integer;
      SalmonCount : integer;
      DTMsLoaded : boolean;

    procedure LoadDTMs;
    begin
      if not DTMsLoaded then
      begin
        SalmonDTM := DTMFromString('78DA639CC9C4C0F08C0105ECAFCA651001D28' +
             'C40FC1F0818A701D5DC6140038C482490EE00AA794740CD5422D4' +
             'CC07AA794C40CD42A09A1BF8D5000076370EB9');
        DTMsLoaded := true;
      end;
    end;

    begin
      ClearDebug;
      SetupSRL;
      ActivateClient;
      LoadDTMs;
      Wait(3000);
      SalmonCount := SalmonCount + ItemAmount('inv', 'dtm', SalmonDTM, []);
      WriteLn('You have ' + IntToStr(SalmonCount) + ' salmons.')
      if DTMsLoaded then FreeDTM(SalmonDTM);
    end.

    Try that.

  6. #6
    Join Date
    Aug 2008
    Location
    !!LOL!!
    Posts
    247
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    aah thank you a million!!!!

  7. #7
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Your welcome .

    Btw the DTMsLoaded boolean is to ensure that it will only free the dtm if it is loaded. You don't really need it but it's what i use.

  8. #8
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    You don't really need a separate variable to check whether the DTMs are loaded; you can just check if DTMVar > 0
    Interested in C# and Electrical Engineering? This might interest you.

  9. #9
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yea but I usually use an array for my DTMs so it is shorter .

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Access violation...
    By mikevskater in forum OSR Help
    Replies: 3
    Last Post: 02-06-2008, 07:28 AM
  2. Access Violation?
    By ~alex~ in forum OSR Help
    Replies: 7
    Last Post: 03-31-2007, 05:47 PM

Posting Permissions

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