Skip to content

Commit 9a75a1f

Browse files
author
aothms
committed
IfcGeomServer, small fixes: refrain from using auto type and restore std::cout rdbuf on exit so implicit flush doesn't segfault
1 parent 64f88cb commit 9a75a1f

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/ifcgeomserver/IfcGeomServer.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class Entity : public Command {
206206
swrite(s, std::string((char*) indices.data(), indices.size() * sizeof(int32_t))); }
207207
{ std::vector<float> diffuse_color_array;
208208
for (std::vector<IfcGeomObjects::Material>::const_iterator it = geom->mesh().materials().begin(); it != geom->mesh().materials().end(); ++it) {
209-
const auto& m = *it;
209+
const IfcGeomObjects::Material& m = *it;
210210
if (m.hasDiffuse()) {
211211
const double* color = m.diffuse();
212212
diffuse_color_array.push_back(static_cast<float>(color[0]));
@@ -272,6 +272,8 @@ int main (int argc, char** argv) {
272272
bool has_more = false;
273273

274274
Hello().write(std::cout);
275+
276+
int exit_code = 0;
275277
while (1) {
276278
const int32_t msg_type = sread<int32_t>(std::cin);
277279
switch (msg_type) {
@@ -288,14 +290,17 @@ int main (int argc, char** argv) {
288290

289291
has_more = IfcGeomObjects::Init(data, len);
290292
More(has_more).write(std::cout);
291-
break;
293+
continue;
292294
}
293295
case GET: {
294296
Get g; g.read(std::cin);
295-
if (!has_more) return 1;
297+
if (!has_more) {
298+
exit_code = 1;
299+
break;
300+
}
296301
const IfcGeomObjects::IfcGeomObject* geom = IfcGeomObjects::Get();
297302
Entity(geom).write(std::cout);
298-
break;
303+
continue;
299304
}
300305
case NEXT: {
301306
Next n; n.read(std::cin);
@@ -304,18 +309,24 @@ int main (int argc, char** argv) {
304309
IfcGeomObjects::CleanUp();
305310
}
306311
More(has_more).write(std::cout);
307-
break;
312+
continue;
308313
}
309314
case GET_LOG: {
310315
GetLog gl; gl.read(std::cin);
311316
WriteLog(IfcGeomObjects::GetLog()).write(std::cout);
312-
break;
317+
continue;
313318
}
314319
case BYE: {
315320
Bye().write(std::cout);
316-
return 0;
321+
exit_code = 0;
322+
break;
317323
}
318-
default: return 1;
324+
default:
325+
exit_code = 1;
326+
break;
319327
}
328+
break;
320329
}
330+
std::cout.rdbuf(stdout_orig);
331+
return exit_code;
321332
}

0 commit comments

Comments
 (0)