Results 1 to 7 of 7

Thread: Riddle me this one

  1. #1

    Riddle me this one

    I had a few bugs pop up in my code and after a bit of tracking down I discovered the weirdest thing. I put two pieces of code either side of a problematic chunk. Both were the same thing :
    Code:
        ShowMessage(Ships[0].Script.Name);
    I then kept moving the two lines closer together and waited until they both matched up then I would know where the value was getting corrupted. I eventually got them with just one unimportant line of code (it was my log file updater ) separating them. and still the results were different. So I removed the line completely and lo and behold the results were still very different.

    Code:
        ShowMessage(Ships[0].Script.Name);
        ShowMessage(Ships[0].Script.Name);
    This code results in two different returns. How the hell is that possible. I am not using threading so unless by virtue of me simply asking what the value held within the variable is changing it then I can't see why the result should be any different.
    Isometric game development blog http://isoenginedev.blogspot.com/

  2. #2

    Riddle me this one

    That's an odd one. Would Script or Name perhaps be properties that use a read method to return the value? Perhaps the read method is modifying the value?

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

    Riddle me this one

    What kind of array is Ships? If it's dynamic this could be a clue as to whats going on. Dynamic arrays are a royal pain to manage sometimes.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  4. #4

    Riddle me this one

    i would guess that you haven't set the length of ships or haven't created some class or something like that..
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  5. #5

    Riddle me this one

    You are correct about it being a dynamic array Will. Although I have used SetLength before calling all of this. What I think may be going on is that I am using SetLength to set it to a length of one index i.e SetLength(Ships,1). Then I am doing some other stuff and extending the length of the array so when I use SetLength again it wipes out what was in the array originally (Shouldn't happen according to Delphi Help but still) but the data still remains in memory so the first time I check on it it gives out the correct info (correct but not locked in place because the reference count has been zeroed when I used SetLength) and when I check it again the computer has since realised it is unused erased the previous data. Does this make any sense, Delphi says that when dynamic arrays are resized the original data stays intact but this doesn't seem to be the case.
    Isometric game development blog http://isoenginedev.blogspot.com/

  6. #6

    Riddle me this one

    if you increase the size of your dinamic array then your prior data IS NOT LOST, if you decrease the size of your dinamic array then you lost those elements decreased.

    if you say two consecutives showmessages are given two different result then it mean your are accesing a nonallocated element in your array, normally you will recive a "Acces violation" error when that happen...except when the element is "0" where for some reason somtimes you dont.




    tp.

  7. #7

    Riddle me this one

    Hmm, that would explain it. Although I've since found a workaround and fixed it but knowing this I'm tempted to go back and see if I can get it to work this time. Thanks for the info, will be handy to know for future reference.
    Isometric game development blog http://isoenginedev.blogspot.com/

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
  •