Results 1 to 7 of 7

Thread: Stupid bugs and strange code

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Quote Originally Posted by SilverWarior View Post
    There is one similar topic but it is located in different sectiomn of the forum Actually it has been started recently by Will (nearly the same time as 2nd PGD mini competition). You can find it here: http://www.pascalgamedevelopment.com...-we-used-to-do
    As you will see there were several posts from various pepole, even me, about our coding mistakes or simply usage of unnecessary or wrong approaches.
    I think the post from Will is more focused on stupid things we did, instead on stupid bugs. You know, a persistent bug eventually becomes a feature!

  2. #2
    Quote Originally Posted by pitfiend View Post
    I think the post from Will is more focused on stupid things we did, instead on stupid bugs. You know, a persistent bug eventually becomes a feature!
    Stupid bugs are results of strange code and silly things we used to do atleast until we realized that and fixed it as it should be. So I belive both topics cover roughly the same area.

  3. #3
    It isn't exactly a bug but once i tried to set a TShape.checked property. Of course the code wouldn't compile and I didn't get why. When I got the answer on the lazarus forums I was like: "Damn I am stupid".

    I think this must be one of the stupidest programming related things that ever happened to me although there are more of these gems.

    Yay, I even found the code:
    Code:
    unit Unit1; 
    
    {$mode objfpc}{$H+}
    
    interface
    
    uses
      Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
      ExtCtrls, StdCtrls;
    
    type
    
      { TForm1 }
    
      TForm1 = class(TForm)
        Button1: TButton;
        Image1: TImage;
        Image2: TImage;
        Image3: TImage;
        Image4: TImage;
        Image5: TImage;
        Image6: TImage;
        Image7: TImage;
        Image8: TImage;
        Image9: TImage;
        RadioGroup1: TRadioGroup;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure Image1Click(Sender: TObject);
        procedure MyRBClick(Sender: TObject);
      private
        { private declarations }
      public
        { public declarations }
      end; 
    
    var
      Form1: TForm1; 
      S: array [1..25] of TShape;  //Siedler.
      G: array [1..25] of integer; //Goal.
      RB: array [1..25] of TRadioButton;
      X: integer;
      Chosen: integer;
    implementation
    
    { TForm1 }
    
    procedure TForm1.MyRBClick(Sender: TObject);
    var
      Y: integer;
    begin
      Y:=1;
      Repeat
        If S[Chosen].checked = True Then
          Chosen:=Y;
        Y:=Y+1;
      Until Y > X;
    
    end;
    
    
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      X:=1;
    end;
    
    procedure TForm1.Image1Click(Sender: TObject);
    begin
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      begin
        S[X]              := TShape.Create(Application);
        S[X].Left         := 0;
        S[X].Top          := 0;
        S[X].Width        := 50;
        S[X].Height       := 50;
        S[X].Parent       := Form1;
        S[X].Name         := ('MyShape' + IntToStr(X));
        S[X].Shape        := stCircle;
        S[X].Brush.Color  := clBlue;
      end;
      begin
        RB[X]         :=TRadioButton.create(Application);
        RB[X].Left    := 5;
        RB[X].Top     := 5;
        RB[X].Parent  := Radiogroup1;
        RB[X].Name    := ('Settler' + IntToStr(X));
        RB[X].Caption := ('Siedler nr. ' + IntToStr(X));
        RB[X].OnClick := @Form1.MyRBClick;
       end;
      X:=X+1;
    end;
    
    
    initialization
      {$I unit1.lrs}
    
    end.
    In my defense, I was kinda new to programming that time.

    Cheers!

  4. #4
    Junior Member Delphius's Avatar
    Join Date
    Jul 2013
    Location
    Salta, Argentina
    Posts
    9
    So far I think the most stupid mistake I made was to confuse the iteration of a matrix row by row with as column by column.

    Was a few months. It had to implement the Jacobi algorithm to compute eigenvalues ​​and eigenvectors of symmetric matrices.
    To verify that the calculations were done correctly I assessed that satisfy A * V = Lambda * V and V is orthonormal.

    I Had two algorithms: one as a control and the other with some improvements but in essence were almost identical. For some reason the control worked perfectly, but the other told me that no tests passed and the results differed in some decimals.

    I examined the code of Jacobi line by line looking for the culprit and everything was in order . I had even come to think that I was altering some compiler directive or changed the data type ... And nothing ... everything was OK.


    I was two weeks sitting in front of the monitor ... The error was that when submitting data did eigenvectors of rows and columns as it should not. All for a variable and a cycle.
    Since then I have stuck a post-it on my monitor that reminds me not confuse rows and columns.

    Regards,
    P.S: Sorry for my poor English.

  5. #5
    Not pascal related but anyway just few days ago when working on my script compiler in C++ i had to write some stuff into compiled script. When i solve programming problems i often make small test apps and test the piece of code before copying to big project.

    The test app wrote the data to file without problems, just the way i needed.
    Then i just copy/pasted the code to my compiler source, which already has tons of .h / .cpp files and hundreds / thousands of lines, it just wrote the data partially, only first 2 bytes. The total was around 6000 bytes.

    I tested many times this in my test app, with minimal code, looked what im doing etc, everything was correct. It was just very very weird. I couldnt understand how that can be. Just copy paste, small piece of code. Works in test app, but in compiler just 2 bytes.
    This piece of code was almost at the end of main.cpp where all the writing is done.

    And then i accidentally scrolled down near to the end of main.cpp and found that i had a piece of code in there (just a for loop) that filled all these 6000 bytes with 0. Except the 2 bytes, that was "header".

    Removed that and all started to work. Because my old laptop screen is pretty small and i work with 1024x768, i dont see all of the code, i have to scroll a lot. Same with my PC monitor, very old and small.

    So this code was outside of the view and did his job, directly i wrote the filled structs to file, it just replaced all data in them with 0.

    Im planning to buy some 21" LCD, i never had such one but i would like to have it.

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
  •