Announcement

Collapse
No announcement yet.

Runaway loops

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    Yeah that looks good.

    So basically, if it's possible to capture console commands and act on them, we could do something like:

    In MOTD: Type mapvote to vote for a map.

    In console a few options:

    Type 'maplist to list maps.
    Type name of map to vote for it.
    Type 'status' to see current votes.

    Or something like that.

    Capturing console commands would be preferable to using aliases I think.
    Last edited by slackhead; 09-05-2014, 11:04 AM.

    -r0t.uk- cOOp - Mapvote - r0t.uk:26001
    -r0t.uk- DM - Mapvote - r0t.uk:26000

    Comment


    • #32
      So after much digging about how that exact error can occur, I have another proposition. The engine has 100000 as a limit of qc commands any time the main engine runs a qc function. A qc command can be a singular line, or if statement, but typically we end up coding multiple commands per line.

      So, for the "for (i=0; i<VOTE_NUMMAPS; i++)" loop, everything in there will run 200+ times. It's nine or ten commands, which is 2000+ qc commands. Not a lot compared to 100000. But then I realized that the num_to_map function has 200+ lines in it, and, on average, 100 of them are used and counted towards this qc command limit. I guess there are only three qc functions per line, so 3 * 100 * 200 is 60000, which makes the function use about 62000 qc commands.

      Since impulse functions come from PlayerPostThink, that gives the remaining functions of PostThink 38000 commands... which should be enough since there's not much else in PostThink, but the error actually occurs during your function, so chances are that it's using more qc commands than I counted.

      I see that you wanted to use impulses, and yeah, there's about 230 unused numbers, which is not a lot for your needs. Perhaps use two or three impulses as a key? Or CAx's solution of multiple menus (same general idea, and you won't have the runaway problem). Otherwise, you'll have to somehow allow num_to_map to shortcut to later if statements for large num's.

      Comment


      • #33
        Well I didn't exactly 'want' to use impulses, but that's what the BAM code uses, that someone linked me to.

        Using a console command would be better, but it doesn't have to be a menu as such. That was just a suggestion. It could use a few commands like 'maplist' and 'vote <mapname'. That would do it too.

        -r0t.uk- cOOp - Mapvote - r0t.uk:26001
        -r0t.uk- DM - Mapvote - r0t.uk:26000

        Comment


        • #34
          This is an interesting problem.

          Zop's explanation is a possible one.

          However, since the infinite loop was definitely fixed by changing i++ to i=i+1, something else might be at work. I talked about this with LordHavoc who gave this as a possible issue (paraphrased):

          Doing float math on an integer (i is an int here for some reason, vs the more usual float) could result in it being treated as a denormal (very small number.)

          Certain compiler optimisations might treat denormals as 0.

          If this was the case here, with i being 0, i++ would still be zero and the loop would never end.

          Expressly adding 1 to i every time avoids this problem, since if you add 1 to something, it is no longer close to 0.

          QC does support these operators (at least recent compilers do) it's just that problems might occur if i is an int and also 0. Had you used a float for i (or i+=1 instead of i++) it wouldn't have happened.

          Pretty intriguing problem. LH's idea sounds pretty likely to me. I suggest just using i+=1 instead of i++ whenever you actually want to add 1 (eg for loops.)
          Scout's Journey
          Rune of Earth Magic

          Comment


          • #35
            That sounds likely. I just test with i as a float and that also crashed. Using i+=1 works fine.

            -r0t.uk- cOOp - Mapvote - r0t.uk:26001
            -r0t.uk- DM - Mapvote - r0t.uk:26000

            Comment


            • #36
              Interesting.

              if it also happens with i as a float, then it's probably down to compiler oddity. I don't claim to know exactly what's going on here. Are you using fteqcc? If so, Spike could have some insight.
              Scout's Journey
              Rune of Earth Magic

              Comment


              • #37
                frikqcc25.exe

                Don't know which is the best to use...

                -r0t.uk- cOOp - Mapvote - r0t.uk:26001
                -r0t.uk- DM - Mapvote - r0t.uk:26000

                Comment


                • #38
                  frikqcc, fteqcc or gmqcc might all work, it's just that frikqcc is no longer actively developed IIRC.

                  With fteqcc, Spike will at least fix stuff when it occurs (also, it supports things like arrays, classes and pointers, the latter only if you use FTE.)
                  Scout's Journey
                  Rune of Earth Magic

                  Comment


                  • #39
                    @Goldenboy

                    This is basically what is happening. It just never stops doing that operator for the reason you just stated. it's because "i" has only been defined once and so it has nothing to say it has changed. So it never stops. More sophisticated languages would have caught this error me thinks. Also you cannot compile that routine using FTEQCC at all using. It will error out. I suppose I should have explained my solution. :/ My bad.

                    This is another example that would work.

                    int i, n = 10;
                    for(i = 0; i < n; i++) {
                    if(i == 5)
                    i++;
                    printf("%d\n", i);
                    if(i == 8 )
                    n++;
                    }
                    This wouldn't lead to an infinite loop. Hope this kind of explains it better.

                    This is the format that has to be followed:

                    for (initialassignment ; conditionexpression ; incrementexpression)
                    {
                    statements
                    }
                    Last edited by PrimalLove; 09-05-2014, 01:56 PM.

                    Comment


                    • #40
                      kudos for being the first to supply the solution, PrimalLove.

                      Edit: I wonder why you can't compile that code with fteqcc - this next example always compiled fine for me with fteqcc (and still does with today's SVN version):

                      Code:
                      float (entity who, float what) HasItem =
                      {
                              local float i;
                      
                              for (i=0; i<who.inv_index; i++)
                              {
                                      if (who.inventory[i] == what)
                                              return TRUE;
                              }
                      
                              return FALSE;
                      };
                      And yeah, I realize I really should change this i++ to i+=1.
                      Last edited by golden_boy; 09-05-2014, 02:03 PM.
                      Scout's Journey
                      Rune of Earth Magic

                      Comment


                      • #41
                        I can't find fteqcc anywhere. Anyone have a link to either linux source, binary, or even windows binary?

                        -r0t.uk- cOOp - Mapvote - r0t.uk:26001
                        -r0t.uk- DM - Mapvote - r0t.uk:26000

                        Comment


                        • #42
                          it comes with FTE engine. HERE

                          Err... Maybe I am wrong. Maybe not come with but you can get it there.

                          Or here.

                          Comment


                          • #43
                            error out how?
                            because ints are unsupported in vanilla progs? or is it some other, less obvious thing?

                            also, most recent fteqcc builds are here. Index of /moodles/fteqcc
                            Some Game Thing

                            Comment


                            • #44

                              float (entity who, float what) HasItem =
                              {
                              local float i;

                              for (i=0; i<who.inv_index; i++)
                              {
                              if (who.inventory[i] == what)
                              return TRUE;
                              }

                              return FALSE;
                              };
                              Your code allows an out and defines i and allows for a True or false. his code allows for no out. So it never leaves the routine until it crashes. FTEQCC I believe is simply seeing this contradiction and errors out. But that is speculation.

                              Code:
                              void() list_maps=
                              {
                                  local int i, x;
                              
                                  for (i=0; i<VOTE_NUMMAPS; i++)
                                  {   
                                    [COLOR="Red"] //Does nothing here to further define i so it cannot proceed.[/COLOR]
                                      sprint (self, number_to_map(i));
                                      sprint (self, " ");
                                      x++;
                              
                                      // 10 columns
                                      if (x > 10) 
                                      {   
                                          sprint(self, "\n");
                                          x = 0;
                                      }   
                                  }   
                              };
                              EDIT: for give my less than technical explanations. I am new to programming languages myself.

                              EDIT2: Which version fteqcc you use?
                              Last edited by PrimalLove; 09-05-2014, 02:26 PM.

                              Comment


                              • #45
                                Thanks, I have ftegcc.

                                -r0t.uk- cOOp - Mapvote - r0t.uk:26001
                                -r0t.uk- DM - Mapvote - r0t.uk:26000

                                Comment

                                Working...
                                X