store.c store_maint function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PaulBlay
    Knight
    • Jan 2009
    • 657

    store.c store_maint function

    I noticed the following line in store_maint

    Code:
    while (st_ptr->stock_num < stock) store_create_random(which);
    This does not allow a way for store_create_random to fail in a helpful manner and can lead to an endless loop freeze. (If somebody like me has been mucking about with the game code ;-)

    How about something with a for loop and a maximum number of tries?

    Could also return values from store_create_random and/or store_maint to show if the process has gone as planned or not.
    Last edited by PaulBlay; April 1, 2009, 10:52.
    Currently turning (Angband) Japanese.
  • PaulBlay
    Knight
    • Jan 2009
    • 657

    #2
    I wrote some suggested alternative code, but there's something wrong with it So more debugging for me.
    Currently turning (Angband) Japanese.

    Comment

    • takkaria
      Veteran
      • Apr 2007
      • 1951

      #3
      Originally posted by PaulBlay
      I noticed the following line in store_maint

      Code:
      while (st_ptr->stock_num < stock) store_create_random(which);
      This does not allow a way for store_create_random to fail in a helpful manner and can lead to an endless loop freeze. (If somebody like me has been mucking about with the game code ;-)

      How about something with a for look and a maximum number of tries?

      Could also return values from store_create_random and/or store_maint to show if the process has gone as planned or not.
      A simple change would be to do:

      Code:
      while ((st_ptr->stock_num < stock) && store_create_random(which)) ;
      and make store_create_random() return FALSE when it fails, TRUE otherwise.
      takkaria whispers something about options. -more-

      Comment

      • PaulBlay
        Knight
        • Jan 2009
        • 657

        #4
        Originally posted by takkaria
        make store_create_random() return FALSE when it fails, TRUE otherwise.
        Waddya know. store_create_random already does return FALSE when it fails, TRUE otherwise.

        However I suspect it is possible for the functions called by store_create_random to fail (like store_carry) which leaves you with a created object (success) that hasn't increased the stock number. That's another way that you can end up with a potential for infinite loop. Failing on a failed store_carry also would be dubious as just because one object doesn't fit may not mean that the next one won't go in just fine.

        I shall obviously have to consider this a little more.
        Currently turning (Angband) Japanese.

        Comment

        Working...
        😀
        😂
        🥰
        😘
        🤢
        😎
        😞
        😡
        👍
        👎