2015-12-27 4 views
0

Après la réécriture du code (application de formulaires Windows) de VS 2005 à VS 2015, une erreur "STATUS_STACK_BUFFER_OVERRUN a été détectée" se produit. Dans le programme VS2005 fonctionne très bien. Je ne sais pas vraiment ce qui ne va pas. Le code a été écrit dans XP OS. Maintenant, je suis en train de le démarrer sur win7 64 bits VS2015. Ce programme est un exemple de ma classe de programmation. Besoin de le réutiliser à d'autres fins.STATUS_STACK_BUFFER_OVERRUN a rencontré VS 2015

#pragma once 



namespace Fal_end { 
#include <math.h> 

    using namespace System; 
    using namespace System::ComponentModel; 
    using namespace System::Collections; 
    using namespace System::Windows::Forms; 
    using namespace System::Data; 
    using namespace System::Drawing; 

    /// <summary> 
    /// Summary for Form1 
    /// 
    /// WARNING: If you change the name of this class, you will need to change the 
    ///   'Resource File Name' property for the managed resource compiler tool 
    ///   associated with all .resx files this class depends on. Otherwise, 
    ///   the designers will not be able to interact properly with localized 
    ///   resources associated with this form. 
    /// </summary> 
    public ref class Form1 : public System::Windows::Forms::Form 
    { 
    public: 
     Form1(void) 
     { 
      InitializeComponent(); 
      // 
      //TODO: Add the constructor code here 
      // 
     } 

    protected: 
     /// <summary> 
     /// Clean up any resources being used. 
     /// </summary> 
     ~Form1() 
     { 
      if (components) 
      { 
       delete components; 
      } 
     } 
    private: System::Windows::Forms::Label^ label13; 
    protected: 
    private: System::Windows::Forms::Label^ label12; 
    private: System::Windows::Forms::Button^ button1; 
    private: System::Windows::Forms::Label^ label11; 
    private: System::Windows::Forms::Label^ label10; 
    private: System::Windows::Forms::Label^ label9; 
    private: System::Windows::Forms::TextBox^ pred_zadana; 
    private: System::Windows::Forms::Label^ label8; 
    private: System::Windows::Forms::Label^ label7; 
    private: System::Windows::Forms::TextBox^ bieguny; 
    private: System::Windows::Forms::Label^ label6; 
    private: System::Windows::Forms::TextBox^ czestotliwosc; 
    private: System::Windows::Forms::Label^ label5; 
    private: System::Windows::Forms::TextBox^ predkosc; 
    private: System::Windows::Forms::Label^ label4; 
    private: System::Windows::Forms::TextBox^ napiecie; 
    private: System::Windows::Forms::Label^ label3; 
    private: System::Windows::Forms::TextBox^ textBox1; 
    private: System::Windows::Forms::Label^ label2; 
    private: System::Windows::Forms::Label^ label1; 




    private: System::Windows::Forms::Label^ label17; 
    private: System::Windows::Forms::Label^ label18; 
    private: System::Windows::Forms::TextBox^ okres_amp; 

    private: System::Windows::Forms::Label^ label15; 
    private: System::Windows::Forms::Label^ label16; 
    private: System::Windows::Forms::Label^ label14; 


    protected: 



















    private: 
     /// <summary> 
     /// Required designer variable. 
     /// </summary> 
     System::ComponentModel::Container ^components; 

#pragma region Windows Form Designer generated code 
     /// <summary> 
     /// Required method for Designer support - do not modify 
     /// the contents of this method with the code editor. 
     /// </summary> 
     void InitializeComponent(void) 
     { 
      this->label13 = (gcnew System::Windows::Forms::Label()); 
      this->label12 = (gcnew System::Windows::Forms::Label()); 
      this->button1 = (gcnew System::Windows::Forms::Button()); 
      this->label11 = (gcnew System::Windows::Forms::Label()); 
      this->label10 = (gcnew System::Windows::Forms::Label()); 
      this->label9 = (gcnew System::Windows::Forms::Label()); 
      this->pred_zadana = (gcnew System::Windows::Forms::TextBox()); 
      this->label8 = (gcnew System::Windows::Forms::Label()); 
      this->label7 = (gcnew System::Windows::Forms::Label()); 
      this->bieguny = (gcnew System::Windows::Forms::TextBox()); 
      this->label6 = (gcnew System::Windows::Forms::Label()); 
      this->czestotliwosc = (gcnew System::Windows::Forms::TextBox()); 
      this->label5 = (gcnew System::Windows::Forms::Label()); 
      this->predkosc = (gcnew System::Windows::Forms::TextBox()); 
      this->label4 = (gcnew System::Windows::Forms::Label()); 
      this->napiecie = (gcnew System::Windows::Forms::TextBox()); 
      this->label3 = (gcnew System::Windows::Forms::Label()); 
      this->textBox1 = (gcnew System::Windows::Forms::TextBox()); 
      this->label2 = (gcnew System::Windows::Forms::Label()); 
      this->label1 = (gcnew System::Windows::Forms::Label()); 
      this->label17 = (gcnew System::Windows::Forms::Label()); 
      this->label18 = (gcnew System::Windows::Forms::Label()); 
      this->okres_amp = (gcnew System::Windows::Forms::TextBox()); 
      this->label15 = (gcnew System::Windows::Forms::Label()); 
      this->label16 = (gcnew System::Windows::Forms::Label()); 
      this->label14 = (gcnew System::Windows::Forms::Label()); 
      this->SuspendLayout(); 
      // 
      // label13 
      // 
      this->label13->AutoSize = true; 
      this->label13->Location = System::Drawing::Point(430, 223); 
      this->label13->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label13->Name = L"label13"; 
      this->label13->Size = System::Drawing::Size(49, 20); 
      this->label13->TabIndex = 42; 
      this->label13->Text = L".........."; 
      // 
      // label12 
      // 
      this->label12->AutoSize = true; 
      this->label12->Location = System::Drawing::Point(430, 185); 
      this->label12->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label12->Name = L"label12"; 
      this->label12->Size = System::Drawing::Size(49, 20); 
      this->label12->TabIndex = 41; 
      this->label12->Text = L".........."; 
      // 
      // button1 
      // 
      this->button1->Location = System::Drawing::Point(468, 397); 
      this->button1->Margin = System::Windows::Forms::Padding(4, 5, 4, 5); 
      this->button1->Name = L"button1"; 
      this->button1->Size = System::Drawing::Size(128, 62); 
      this->button1->TabIndex = 40; 
      this->button1->Text = L"SYMULACJA"; 
      this->button1->UseVisualStyleBackColor = true; 
      this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); 
      // 
      // label11 
      // 
      this->label11->AutoSize = true; 
      this->label11->Location = System::Drawing::Point(268, 223); 
      this->label11->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label11->Name = L"label11"; 
      this->label11->Size = System::Drawing::Size(142, 20); 
      this->label11->TabIndex = 39; 
      this->label11->Text = L"Czestotliwość [Hz]:"; 
      // 
      // label10 
      // 
      this->label10->AutoSize = true; 
      this->label10->Location = System::Drawing::Point(268, 186); 
      this->label10->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label10->Name = L"label10"; 
      this->label10->Size = System::Drawing::Size(97, 20); 
      this->label10->TabIndex = 38; 
      this->label10->Text = L"Napięcie [V]:"; 
      // 
      // label9 
      // 
      this->label9->AutoSize = true; 
      this->label9->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
       static_cast<System::Byte>(238))); 
      this->label9->Location = System::Drawing::Point(267, 142); 
      this->label9->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label9->Name = L"label9"; 
      this->label9->Size = System::Drawing::Size(138, 29); 
      this->label9->TabIndex = 37; 
      this->label9->Text = L"Parametry:"; 
      this->label9->TextAlign = System::Drawing::ContentAlignment::MiddleLeft; 
      // 
      // pred_zadana 
      // 
      this->pred_zadana->Location = System::Drawing::Point(273, 91); 
      this->pred_zadana->Margin = System::Windows::Forms::Padding(4, 5, 4, 5); 
      this->pred_zadana->Name = L"pred_zadana"; 
      this->pred_zadana->Size = System::Drawing::Size(148, 26); 
      this->pred_zadana->TabIndex = 36; 
      this->pred_zadana->Text = L"1000"; 
      // 
      // label8 
      // 
      this->label8->AutoSize = true; 
      this->label8->Location = System::Drawing::Point(268, 65); 
      this->label8->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label8->Name = L"label8"; 
      this->label8->Size = System::Drawing::Size(138, 20); 
      this->label8->TabIndex = 35; 
      this->label8->Text = L"predkość [obr/min]"; 
      // 
      // label7 
      // 
      this->label7->AutoSize = true; 
      this->label7->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
       static_cast<System::Byte>(238))); 
      this->label7->Location = System::Drawing::Point(267, 15); 
      this->label7->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label7->Name = L"label7"; 
      this->label7->Size = System::Drawing::Size(119, 29); 
      this->label7->TabIndex = 34; 
      this->label7->Text = L"Zadajnik:"; 
      this->label7->TextAlign = System::Drawing::ContentAlignment::MiddleLeft; 
      // 
      // bieguny 
      // 
      this->bieguny->Location = System::Drawing::Point(21, 378); 
      this->bieguny->Margin = System::Windows::Forms::Padding(4, 5, 4, 5); 
      this->bieguny->Name = L"bieguny"; 
      this->bieguny->Size = System::Drawing::Size(148, 26); 
      this->bieguny->TabIndex = 33; 
      this->bieguny->Text = L"2"; 
      // 
      // label6 
      // 
      this->label6->AutoSize = true; 
      this->label6->Location = System::Drawing::Point(16, 352); 
      this->label6->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label6->Name = L"label6"; 
      this->label6->Size = System::Drawing::Size(27, 20); 
      this->label6->TabIndex = 32; 
      this->label6->Text = L"pb"; 
      // 
      // czestotliwosc 
      // 
      this->czestotliwosc->Location = System::Drawing::Point(21, 306); 
      this->czestotliwosc->Margin = System::Windows::Forms::Padding(4, 5, 4, 5); 
      this->czestotliwosc->Name = L"czestotliwosc"; 
      this->czestotliwosc->Size = System::Drawing::Size(148, 26); 
      this->czestotliwosc->TabIndex = 31; 
      this->czestotliwosc->Text = L"50"; 
      // 
      // label5 
      // 
      this->label5->AutoSize = true; 
      this->label5->Location = System::Drawing::Point(16, 280); 
      this->label5->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label5->Name = L"label5"; 
      this->label5->Size = System::Drawing::Size(54, 20); 
      this->label5->TabIndex = 30; 
      this->label5->Text = L"fs [Hz]"; 
      // 
      // predkosc 
      // 
      this->predkosc->Location = System::Drawing::Point(21, 232); 
      this->predkosc->Margin = System::Windows::Forms::Padding(4, 5, 4, 5); 
      this->predkosc->Name = L"predkosc"; 
      this->predkosc->Size = System::Drawing::Size(148, 26); 
      this->predkosc->TabIndex = 29; 
      this->predkosc->Text = L"1475"; 
      this->predkosc->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged); 
      // 
      // label4 
      // 
      this->label4->AutoSize = true; 
      this->label4->Location = System::Drawing::Point(16, 206); 
      this->label4->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label4->Name = L"label4"; 
      this->label4->Size = System::Drawing::Size(82, 20); 
      this->label4->TabIndex = 28; 
      this->label4->Text = L"n [obr/min]"; 
      // 
      // napiecie 
      // 
      this->napiecie->Location = System::Drawing::Point(21, 162); 
      this->napiecie->Margin = System::Windows::Forms::Padding(4, 5, 4, 5); 
      this->napiecie->Name = L"napiecie"; 
      this->napiecie->Size = System::Drawing::Size(148, 26); 
      this->napiecie->TabIndex = 27; 
      this->napiecie->Text = L"380"; 
      // 
      // label3 
      // 
      this->label3->AutoSize = true; 
      this->label3->Location = System::Drawing::Point(16, 135); 
      this->label3->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label3->Name = L"label3"; 
      this->label3->Size = System::Drawing::Size(53, 20); 
      this->label3->TabIndex = 26; 
      this->label3->Text = L"Un [V]"; 
      // 
      // textBox1 
      // 
      this->textBox1->Location = System::Drawing::Point(21, 91); 
      this->textBox1->Margin = System::Windows::Forms::Padding(4, 5, 4, 5); 
      this->textBox1->Name = L"textBox1"; 
      this->textBox1->Size = System::Drawing::Size(148, 26); 
      this->textBox1->TabIndex = 25; 
      this->textBox1->Text = L"15000"; 
      this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged); 
      // 
      // label2 
      // 
      this->label2->AutoSize = true; 
      this->label2->Location = System::Drawing::Point(16, 65); 
      this->label2->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label2->Name = L"label2"; 
      this->label2->Size = System::Drawing::Size(55, 20); 
      this->label2->TabIndex = 24; 
      this->label2->Text = L"Pn [W]"; 
      // 
      // label1 
      // 
      this->label1->AutoSize = true; 
      this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
       static_cast<System::Byte>(238))); 
      this->label1->Location = System::Drawing::Point(15, 15); 
      this->label1->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label1->Name = L"label1"; 
      this->label1->Size = System::Drawing::Size(223, 29); 
      this->label1->TabIndex = 23; 
      this->label1->Text = L"Par. Znamionowe:"; 
      this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleLeft; 
      // 
      // label17 
      // 
      this->label17->AutoSize = true; 
      this->label17->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
       static_cast<System::Byte>(238))); 
      this->label17->Location = System::Drawing::Point(267, 303); 
      this->label17->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label17->Name = L"label17"; 
      this->label17->Size = System::Drawing::Size(139, 29); 
      this->label17->TabIndex = 47; 
      this->label17->Text = L"Symulacja:"; 
      this->label17->TextAlign = System::Drawing::ContentAlignment::MiddleLeft; 
      // 
      // label18 
      // 
      this->label18->AutoSize = true; 
      this->label18->Location = System::Drawing::Point(268, 340); 
      this->label18->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label18->Name = L"label18"; 
      this->label18->Size = System::Drawing::Size(174, 20); 
      this->label18->TabIndex = 48; 
      this->label18->Text = L"ilość okresów amplitudy"; 
      // 
      // okres_amp 
      // 
      this->okres_amp->Location = System::Drawing::Point(273, 378); 
      this->okres_amp->Margin = System::Windows::Forms::Padding(4, 5, 4, 5); 
      this->okres_amp->Name = L"okres_amp"; 
      this->okres_amp->Size = System::Drawing::Size(148, 26); 
      this->okres_amp->TabIndex = 49; 
      this->okres_amp->Text = L"2"; 
      // 
      // label15 
      // 
      this->label15->AutoSize = true; 
      this->label15->Location = System::Drawing::Point(852, 135); 
      this->label15->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label15->Name = L"label15"; 
      this->label15->Size = System::Drawing::Size(0, 20); 
      this->label15->TabIndex = 51; 
      // 
      // label16 
      // 
      this->label16->AutoSize = true; 
      this->label16->Location = System::Drawing::Point(828, 135); 
      this->label16->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label16->Name = L"label16"; 
      this->label16->Size = System::Drawing::Size(0, 20); 
      this->label16->TabIndex = 52; 
      // 
      // label14 
      // 
      this->label14->AutoSize = true; 
      this->label14->Location = System::Drawing::Point(888, 135); 
      this->label14->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 
      this->label14->Name = L"label14"; 
      this->label14->Size = System::Drawing::Size(0, 20); 
      this->label14->TabIndex = 53; 
      // 
      // Form1 
      // 
      this->AutoScaleDimensions = System::Drawing::SizeF(9, 20); 
      this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; 
      this->ClientSize = System::Drawing::Size(1132, 463); 
      this->Controls->Add(this->label14); 
      this->Controls->Add(this->label16); 
      this->Controls->Add(this->label15); 
      this->Controls->Add(this->okres_amp); 
      this->Controls->Add(this->label18); 
      this->Controls->Add(this->label17); 
      this->Controls->Add(this->label13); 
      this->Controls->Add(this->label12); 
      this->Controls->Add(this->button1); 
      this->Controls->Add(this->label11); 
      this->Controls->Add(this->label10); 
      this->Controls->Add(this->label9); 
      this->Controls->Add(this->pred_zadana); 
      this->Controls->Add(this->label8); 
      this->Controls->Add(this->label7); 
      this->Controls->Add(this->bieguny); 
      this->Controls->Add(this->label6); 
      this->Controls->Add(this->czestotliwosc); 
      this->Controls->Add(this->label5); 
      this->Controls->Add(this->predkosc); 
      this->Controls->Add(this->label4); 
      this->Controls->Add(this->napiecie); 
      this->Controls->Add(this->label3); 
      this->Controls->Add(this->textBox1); 
      this->Controls->Add(this->label2); 
      this->Controls->Add(this->label1); 
      this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::Fixed3D; 
      this->Margin = System::Windows::Forms::Padding(4, 5, 4, 5); 
      this->Name = L"Form1"; 
      this->Text = L"Falownik Napięcia z modulacją szerokości impulsów MSI"; 
      this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); 
      this->ResumeLayout(false); 
      this->PerformLayout(); 

     } 
#pragma endregion 
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { 
     // deklaracja zmiennych   
     double n1, ns, fs, sn, f, pred_z, nap_U, x, U; 
     double t, tt = 0, y_sin, roz_t; 
     double pi = 3.14159265359; 
     int i = 0, x0; 
     double y0; 
     double T = 0; // okres przebiegu 
     int pb; // liczba par biegunów 


        //label14->Text = ("|"); 

     fs = Convert::ToDouble(czestotliwosc->Text); 
     pb = Convert::ToInt16(bieguny->Text); 
     n1 = (60 * fs)/pb; 
     ns = Convert::ToDouble(predkosc->Text); 
     sn = (n1 - ns)/n1; 
     sn = (int)(sn * 1000)/1000.0; // Odcinanie cyfr po przecinku 

     pred_z = Convert::ToDouble(pred_zadana->Text); 
     f = (pred_z*pb)/(60 * (1 - sn)); 
     T = (1/f) * 1000; 
     f = (int)(f * 10)/10.0; // Odcinanie cyfr po przecinku 

     T = (int)(T * 10)/10.0; // Odcinanie cyfr po przecinku 

     label16->Text = ("T="); 
     label14->Text = ("ms"); 
     label15->Text = Convert::ToString(T); 

     nap_U = Convert::ToDouble(napiecie->Text); 
     x = nap_U/fs; 
     U = x*f; 
     U = (int)(U * 10)/10.0; // Odcinanie cyfr po przecinku 

     double wsp_nap; 
     wsp_nap = U/nap_U; // amplituda sinusoidy 

     label12->Text = Convert::ToString(U); 
     label13->Text = Convert::ToString(f); 
     //label16->Text = Convert::ToString(wsp_nap); 

     Graphics^ g1 = this->CreateGraphics(); 
     g1->Clear(Color::White);     // Czyszczenie obrazu 
     Pen^ pioro1 = gcnew Pen(System::Drawing::Color::Black); 
     Pen^ pioro2 = gcnew Pen(System::Drawing::Color::Black); 
     Pen^ pioro3 = gcnew Pen(System::Drawing::Color::Red); 
     pioro1->Width = 2; 
     pioro2->Width = 1; 
     pioro3->Width = 2; 

     g1->DrawLine(pioro1, 405, 0, 750, 0); // ramka górna 
     g1->DrawLine(pioro1, 750, 0, 750, 160); 
     g1->DrawLine(pioro1, 750, 160, 405, 160); 
     g1->DrawLine(pioro1, 405, 160, 405, 0); 

     g1->DrawLine(pioro2, 405, 80, 750, 80); //oś górna x 
     g1->DrawLine(pioro2, 405, 235, 750, 235); //oś górna x 

     g1->DrawLine(pioro1, 405, 165, 750, 165); // ramka dolna 
     g1->DrawLine(pioro1, 750, 165, 750, 305); 
     g1->DrawLine(pioro1, 750, 305, 405, 305); 
     g1->DrawLine(pioro1, 405, 305, 405, 165); 

     int okres; 
     int sinus_tab[345]; 


     okres = Convert::ToInt32(okres_amp->Text); 

     t = okres/f;   // czas 2 okresów sinusoidy o czestotliwosci f 

     roz_t = t/345;  //Rozdzielczość czasu na osi x, 345 piksele 



     while (tt <= t)   // pętla rysująca sinusoidę 
     { 

      if (tt == 0)    // pierwszy punkt 
      { 
       y_sin = wsp_nap * sin(2 * pi*f*tt) * 70; 
      } 
      else 
      { 
       y_sin = wsp_nap * sin(2 * pi*f*tt) * 70; 

       g1->DrawLine(pioro3, x0 + 405, 80 - Convert::ToInt32(y0), i + 405, 80 - Convert::ToInt32(y_sin)); 

      } 
      y0 = y_sin; 
      x0 = i; 

      sinus_tab[i] = 80 - Convert::ToInt32(y0); // tablica elementów sinusa 

      tt = tt + roz_t; 
      i = i + 1; 

     } 

     //Rysowanie trójkąta 
     i = 0; 
     int tr = 0, tr0 = 0; 
     int troj_tab[345]; 

     while (i <= 345) 
     { 
      if (i == 0) 
      { 
       tr0 = 80; 
       troj_tab[i] = tr0; 
      } 

      if (i <= 10 && i > 0) 
      { 
       tr = 80 - 8 * i; 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 

      if (i > 10 && i <= 30) 
      { 
       tr = 0 + 8 * (i - 10); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 
      if (i > 30 && i <= 50) 
      { 
       tr = 160 - 8 * (i - 30); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 
      if (i > 50 && i <= 70) 
      { 
       tr = 0 + 8 * (i - 50); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 

      if (i > 70 && i <= 90) 
      { 
       tr = 160 - 8 * (i - 70); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 
      if (i > 90 && i <= 110) 
      { 
       tr = 0 + 8 * (i - 90); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 

      if (i > 110 && i <= 130) 
      { 
       tr = 160 - 8 * (i - 110); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 
      if (i > 130 && i <= 150) 
      { 
       tr = 0 + 8 * (i - 130); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 

      if (i > 150 && i <= 170) 
      { 
       tr = 160 - 8 * (i - 150); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 
      if (i > 170 && i <= 190) 
      { 
       tr = 0 + 8 * (i - 170); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 

      if (i > 190 && i <= 210) 
      { 
       tr = 160 - 8 * (i - 190); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 
      if (i > 210 && i <= 230) 
      { 
       tr = 0 + 8 * (i - 210); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 

      if (i > 230 && i <= 250) 
      { 
       tr = 160 - 8 * (i - 230); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 
      if (i > 250 && i <= 270) 
      { 
       tr = 0 + 8 * (i - 250); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 

      if (i > 270 && i <= 290) 
      { 
       tr = 160 - 8 * (i - 270); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 
      if (i > 290 && i <= 310) 
      { 
       tr = 0 + 8 * (i - 290); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 
      if (i > 310 && i <= 330) 
      { 
       tr = 160 - 8 * (i - 310); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 
      if (i > 330 && i <= 345) 
      { 
       tr = 0 + 8 * (i - 330); 
       g1->DrawLine(pioro2, 405 + i, tr0, 405 + i + 1, tr); 
       tr0 = tr; 
       troj_tab[i] = tr0; 
      } 

      i = i + 1; 
     } 


     i = 0; 
     int fal = 0; 
     int fal0 = 0; 
     while (i <= 345) 
     { 
      if (i == 0) 
      { 
       if (sinus_tab[i] <= troj_tab[i]) 
       { 
        fal0 = 185; 
       } 
       else 
       { 
        fal0 = 285; 
       } 
      } 
      else 
      { 
       if (sinus_tab[i] <= troj_tab[i]) 
       { 
        fal = 185; 

       } 
       else 
       { 
        fal = 285; 

       } 
       g1->DrawLine(pioro3, 405 + i - 1, fal0, 405 + i, fal); 
       fal0 = fal; 
      } 

      i = i + 1; 
     } 

    } 



    private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) { 
    } 
    private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { 
    } 

    }; 
} 
+0

À partir du Guide des programmeurs HuntErr d'Urfin Jus, «Les erreurs sont bonnes - Elles nous aident à trouver des bogues». VS 2015 vous a aidé à trouver un «bug latent» en améliorant la vérification des erreurs dans les versions de débogage. –

Répondre

2
int sinus_tab[345]; 
    while (i <= 345) { 
     sinus_tab[i] = 80 - Convert::ToInt32(y0); // tablica elementów sinusa 
    } 

Mise en évidence les lignes de code qui provoquent cette erreur d'exécution. Vous avez un bug hors-un dans votre code. Le dernier index valide dans sinus_tab [] est 344. Mais vous écrivez sinus_tab [345], la condition while-loop devrait probablement être i < 345. C'est un bug de débordement de tampon, il corrompt aléatoirement le cadre de la pile. Ce type de corruption de la mémoire peut ne pas être détecté.

Vous avez exactement le même bug dans troj_tab [].

Les bugs de débordement de tampon comme celui-ci sont un vecteur d'attaque de virus notoire, il permet de manipuler le programme avec des données. Dans ce cas particulier, vous n'avez vu aucun effet néfaste, mais vous pourriez par exemple écraser l'adresse de retour. Faire sauter le programme à un emplacement arbitraire.

Microsoft a mis en place des contre-mesures pour arrêter ce type d'attaques depuis .NET 4.0 (VS2010). Votre bug déclenche ce mécanisme de détection de dépassement de tampon, il écrase le canari de la pile et votre programme s'interrompt correctement.

Utilisez un tableau géré à la place afin que vous puissiez détecter les bogues comme ceci tôt, vous obtenez une exception IndexOutOfRangeException. Correction:

array<int>^ sinus_tab = gcnew array<int>(345);