Runtime terminated in an unusual way?

I'm having a problem running a simple program I made to read Gcode.
When I try to run the program it freezes up and windows says the program terminated itself in an unusual way, while my compiler doesn't seem to detect an error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

#include <windows.h>
#include <gl/gl.h>
#include <fstream>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <cmath>
using namespace std;

/**************************
 *Gcode reader
 *
 **************************/

float xco1=0.0f;
float yco1=0.0f;
float zco1=0.0f;
float xco2=0.0f;
float yco2=0.0f;
float zco2=0.0f;

int gcodereader(){
    bool spot = false;
    xco1=xco2;
    yco1=yco2;
    zco1=zco2;
    ifstream file1;
    string gcodeline;
    string code1;
    string code2;
    string code3;
    size_t found;
    int found2;
    int clength;
    file1.open("file1.txt", ios::in | ios::binary);
    if (file1.is_open()){
                         if(mode1==true){
                                         getline(file1, gcodeline, '\n');
                                         }
                         
                         while (file1.good()){
                               xco1=xco2;
                               yco1=yco2;
                               zco1=zco2;
                               getline(file1, gcodeline);
                               
                               if (spot==false){
                                  found=gcodeline.find('y');
                                  if (found!=string::npos){
                                                           spot = true;
                                                           if(found!=0){
                                                                        found2 = found;
                                                                        while(found2 < gcodeline.length()){
                                                                                     found2 += 1;
                                                                                     code2 += gcodeline[found2];
                                                                                     }
                                                                     
                                                                     gcodeline.erase(found, (gcodeline.length()-found));
                                                                     }
                                                                     code2.erase((code2.length()-1));
                                                                     istringstream codeConversion(code2);
                                                                     codeConversion >> yco2;
                                                                     }
                                                           }
                               if (spot==false){
                                  found=gcodeline.find('x');
                                  if (found!=string::npos){
                                                           spot = true;
                                                           if(found!=0){
                                                                        found2 = found;
                                                                        while(found2 < gcodeline.length()){
                                                                                     found2 += 1;
                                                                                     code2 += gcodeline[found2];
                                                                                     }
                                                                     
                                                                     gcodeline.erase(found, (gcodeline.length()-found));
                                                                     }
                                                                     code2.erase((code2.length()-1));
                                                                     istringstream codeConversion(code2);
                                                                     codeConversion >> xco2;
                                                                     }
                                                           }
                               if (spot==false){
                                  found=gcodeline.find('z');
                                  if (found!=string::npos){
                                                           spot = true;
                                                           if(found!=0){
                                                                        found2 = found;
                                                                        while(found2 < gcodeline.length()){
                                                                                     found2 += 1;
                                                                                     code2 += gcodeline[found2];
                                                                                     }
                                                                     
                                                                     gcodeline.erase(found, (gcodeline.length()-found));
                                                                     }
                                                                     code2.erase((code2.length()-1));
                                                                     istringstream codeConversion(code2);
                                                                     codeConversion >> zco2;
                                                                     }
                                                           }
                               if (gcodeline[0]=='z'){
                                                      gcodeline.erase(0, 1);
                                                      istringstream codeConversion(gcodeline);
                                                      codeConversion >> zco2;
                                                      }
                               if (gcodeline[0]=='x'){
                                                      gcodeline.erase(0, 1);
                                                      istringstream codeConversion(gcodeline);
                                                      codeConversion >> xco2;
                                                      }
                               if (gcodeline[0]=='y'){
                                                      gcodeline.erase(0, 1);
                                                      istringstream codeConversion(gcodeline);
                                                      codeConversion >> yco2;
                                                      }
                               
                               glColor4f(0.0f, 0.0f, 1.0f, 0.6f);
                               if(zco2 == 0.0f){
                                       glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
                                       }
                               zco2 = zco2/20;
                               xco2 = xco2/20;
                               yco2 = yco2/20;
                               
                               zco2 = zco2+zco1;
                               xco2 = xco2+xco1;
                               yco2 = yco2+yco1;
                               
                               glBegin(GL_LINES);
                               glVertex3f(xco1, yco1, zco1);
                               glVertex3f(xco2, yco2, zco2);
                               glEnd();
                               }
                         file1.close();
                         }
    
    else{
         file1.close();
    }
}

This is the function that's supposed to display the Gcode in opengl.

Please help
Topic archived. No new replies allowed.