diff --git a/SpaceCadetPinball/SpaceCadetPinball.cpp b/SpaceCadetPinball/SpaceCadetPinball.cpp index e639ce8..71f57e5 100644 --- a/SpaceCadetPinball/SpaceCadetPinball.cpp +++ b/SpaceCadetPinball/SpaceCadetPinball.cpp @@ -27,7 +27,7 @@ int main(int argc, char* argv[]) } #if _WIN32 -#include +#include // Windows subsystem main int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) diff --git a/SpaceCadetPinball/TBall.cpp b/SpaceCadetPinball/TBall.cpp index 25dd48f..3d591b8 100644 --- a/SpaceCadetPinball/TBall.cpp +++ b/SpaceCadetPinball/TBall.cpp @@ -40,10 +40,10 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false) Offset = *loader::query_float_attribute(groupIndex, 0, 500); auto visualCount = loader::query_visual_states(groupIndex); - auto index = 0; if (visualCount > 0) { auto visualZPtr = VisualZArray; + int index = 0; do { loader::query_visual(groupIndex, index, &visual); diff --git a/SpaceCadetPinball/TEdgeSegment.cpp b/SpaceCadetPinball/TEdgeSegment.cpp index 53a7675..605ae10 100644 --- a/SpaceCadetPinball/TEdgeSegment.cpp +++ b/SpaceCadetPinball/TEdgeSegment.cpp @@ -20,7 +20,7 @@ void TEdgeSegment::port_draw() TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* collComp, char* activeFlagPtr, unsigned int collisionGroup, float offset, size_t wallValue) { - vector_type center{}, start{}, end{}, prevCenter{}, vec1{}, vec2{}, dstVec{}; + vector_type center{}, start{}, end{}, vec1{}, vec2{}, dstVec{}; TEdgeSegment* edge = nullptr; wall_type wallType = static_cast(static_cast(floor(*floatArr) - 1.0f)); @@ -31,7 +31,14 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c center.X = floatArr[1]; center.Y = floatArr[2]; auto radius = offset + floatArr[3]; - auto circle = new TCircle(collComp, activeFlagPtr, collisionGroup, ¢er, radius); + TCircle* circle = nullptr; + try + { + circle = new TCircle(collComp, activeFlagPtr, collisionGroup, ¢er, radius); + } + catch (...) + { + } edge = circle; if (circle) @@ -49,7 +56,14 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c start.Y = floatArr[2]; end.X = floatArr[3]; end.Y = floatArr[4]; - auto line = new TLine(collComp, activeFlagPtr, collisionGroup, &start, &end); + TLine* line = nullptr; + try + { + line = new TLine(collComp, activeFlagPtr, collisionGroup, &start, &end); + } + catch (...) + { + } edge = line; if (line) @@ -65,6 +79,7 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c { int wallTypeI = static_cast(wallType); auto floatArrPtr = floatArr + 1; + vector_type prevCenter{}; prevCenter.X = floatArr[2 * wallTypeI - 1]; prevCenter.Y = floatArr[2 * wallTypeI]; @@ -97,7 +112,14 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c dstVec.Z < 0.0f && offset < 0.0f) { float radius = offset * 1.001f; - auto circle = new TCircle(collComp, activeFlagPtr, collisionGroup, ¢er, radius); + TCircle* circle = nullptr; + try + { + circle = new TCircle(collComp, activeFlagPtr, collisionGroup, ¢er, radius); + } + catch (...) + { + } if (circle) { @@ -112,7 +134,14 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c start.Y = floatArrPtr[1]; end.X = floatArrPtr[2]; end.Y = floatArrPtr[3]; - auto line = new TLine(collComp, activeFlagPtr, collisionGroup, &start, &end); + TLine* line = nullptr; + try + { + line = new TLine(collComp, activeFlagPtr, collisionGroup, &start, &end); + } + catch (...) + { + } edge = line; if (line) diff --git a/SpaceCadetPinball/TFlagSpinner.cpp b/SpaceCadetPinball/TFlagSpinner.cpp index 7286c1c..53c4f67 100644 --- a/SpaceCadetPinball/TFlagSpinner.cpp +++ b/SpaceCadetPinball/TFlagSpinner.cpp @@ -21,14 +21,28 @@ TFlagSpinner::TFlagSpinner(TPinballTable* table, int groupIndex) : TCollisionCom end.Y = visual.FloatArr[1]; start.X = visual.FloatArr[2]; start.Y = visual.FloatArr[3]; - auto line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &start, &end); + TLine* line = nullptr; + try + { + line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &start, &end); + } + catch (...) + { + } if (line) { line->place_in_grid(); EdgeList.push_back(line); } - line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &end, &start); + line = nullptr; + try + { + line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &end, &start); + } + catch (...) + { + } PrevCollider = line; if (line) { diff --git a/SpaceCadetPinball/TFlipper.cpp b/SpaceCadetPinball/TFlipper.cpp index 94999e5..54f4ebd 100644 --- a/SpaceCadetPinball/TFlipper.cpp +++ b/SpaceCadetPinball/TFlipper.cpp @@ -34,20 +34,26 @@ TFlipper::TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent(t auto vecT2 = reinterpret_cast(loader::query_float_attribute(groupIndex, 0, 802)); auto vecT1 = reinterpret_cast(loader::query_float_attribute(groupIndex, 0, 801)); auto origin = reinterpret_cast(loader::query_float_attribute(groupIndex, 0, 800)); - auto flipperEdge = new TFlipperEdge( - this, - &ActiveFlag, - visual.CollisionGroup, - table, - origin, - vecT1, - vecT2, - extendTime, - retractTime, - collMult, - Elasticity, - Smoothness); - + TFlipperEdge* flipperEdge = nullptr; + try + { + flipperEdge = new TFlipperEdge( + this, + &ActiveFlag, + visual.CollisionGroup, + table, + origin, + vecT1, + vecT2, + extendTime, + retractTime, + collMult, + Elasticity, + Smoothness); + } + catch (...) + { + } FlipperEdge = flipperEdge; if (flipperEdge) { @@ -65,7 +71,7 @@ TFlipper::~TFlipper() int TFlipper::Message(int code, float value) { - if (code == 1 || code == 2 || code > 1008 && code <= 1011 || code == 1022) + if (code == 1 || code == 2 || (code > 1008 && code <= 1011) || code == 1022) { float timerTime; int command = code; diff --git a/SpaceCadetPinball/TFlipperEdge.cpp b/SpaceCadetPinball/TFlipperEdge.cpp index 151dc50..0a7562c 100644 --- a/SpaceCadetPinball/TFlipperEdge.cpp +++ b/SpaceCadetPinball/TFlipperEdge.cpp @@ -109,7 +109,6 @@ float TFlipperEdge::FindCollisionDistance(ray_type* ray) { if (FlipperFlag == 0) { - EdgeCollisionFlag = 0; CollisionFlag1 = 0; CollisionFlag2 = 0; set_control_points(ogRay->TimeNow); @@ -436,7 +435,6 @@ float TFlipperEdge::flipper_angle(float timeNow) int TFlipperEdge::is_ball_inside(float x, float y) { - vector_type testPoint{}; float dx = RotOrigin.X - x; float dy = RotOrigin.Y - y; if ((A2.X - A1.X) * (y - A1.Y) - (A2.Y - A1.Y) * (x - A1.X) >= 0.0f && @@ -447,6 +445,7 @@ int TFlipperEdge::is_ball_inside(float x, float y) (T1.Y - y) * (T1.Y - y) + (T1.X - x) * (T1.X - x) < CircleT1RadiusSq) { float flipperLR = AngleMax < 0.0f ? -1.0f : 1.0f; + vector_type testPoint{}; if (FlipperFlag == 1) testPoint = AngleMax < 0.0f ? B1 : B2; else if (FlipperFlag == 2) diff --git a/SpaceCadetPinball/THole.cpp b/SpaceCadetPinball/THole.cpp index 53bab24..c0397a2 100644 --- a/SpaceCadetPinball/THole.cpp +++ b/SpaceCadetPinball/THole.cpp @@ -30,9 +30,16 @@ THole::THole(TPinballTable* table, int groupIndex) : TCollisionComponent(table, if (Circle.RadiusSq == 0.0f) Circle.RadiusSq = 0.001f; - auto tCircle = new TCircle(this, &ActiveFlag, visual.CollisionGroup, - reinterpret_cast(visual.FloatArr), - Circle.RadiusSq); + TCircle* tCircle = nullptr; + try + { + tCircle = new TCircle(this, &ActiveFlag, visual.CollisionGroup, + reinterpret_cast(visual.FloatArr), + Circle.RadiusSq); + } + catch (...) + { + } if (tCircle) { tCircle->place_in_grid(); diff --git a/SpaceCadetPinball/TKickout.cpp b/SpaceCadetPinball/TKickout.cpp index c4fcd6b..15a1b52 100644 --- a/SpaceCadetPinball/TKickout.cpp +++ b/SpaceCadetPinball/TKickout.cpp @@ -35,8 +35,15 @@ TKickout::TKickout(TPinballTable* table, int groupIndex, bool someFlag): TCollis Circle.RadiusSq = *loader::query_float_attribute(groupIndex, 0, 306) * visual.FloatArr[2]; if (Circle.RadiusSq == 0.0f) Circle.RadiusSq = 0.001f; - auto tCircle = new TCircle(this, &ActiveFlag, visual.CollisionGroup, - reinterpret_cast(visual.FloatArr), Circle.RadiusSq); + TCircle* tCircle = nullptr; + try + { + tCircle = new TCircle(this, &ActiveFlag, visual.CollisionGroup, + reinterpret_cast(visual.FloatArr), Circle.RadiusSq); + } + catch (...) + { + } if (tCircle) { tCircle->place_in_grid(); diff --git a/SpaceCadetPinball/TLightBargraph.cpp b/SpaceCadetPinball/TLightBargraph.cpp index 2551f0f..aef6fee 100644 --- a/SpaceCadetPinball/TLightBargraph.cpp +++ b/SpaceCadetPinball/TLightBargraph.cpp @@ -17,7 +17,13 @@ TLightBargraph::TLightBargraph(TPinballTable* table, int groupIndex) : TLightGro if (floatArr) { auto count = 2 * List.size(); - TimerTimeArray = new float[count]; + try + { + TimerTimeArray = new float[count]; + } + catch (...) + { + } if (TimerTimeArray) { for (auto i = 0u; i < count; ++floatArr) diff --git a/SpaceCadetPinball/TLightGroup.cpp b/SpaceCadetPinball/TLightGroup.cpp index 2cc1dee..616a906 100644 --- a/SpaceCadetPinball/TLightGroup.cpp +++ b/SpaceCadetPinball/TLightGroup.cpp @@ -432,7 +432,7 @@ int TLightGroup::next_light_up() { for (auto index = 0u; index < List.size(); ++index) { - if (!List.at(index)->BmpIndex1) + if (!List[index]->BmpIndex1) return static_cast(index); } return -1; diff --git a/SpaceCadetPinball/TOneway.cpp b/SpaceCadetPinball/TOneway.cpp index ca97678..94e35f7 100644 --- a/SpaceCadetPinball/TOneway.cpp +++ b/SpaceCadetPinball/TOneway.cpp @@ -20,8 +20,14 @@ TOneway::TOneway(TPinballTable* table, int groupIndex) : TCollisionComponent(tab linePt2.Y = visual.FloatArr[1]; linePt1.X = visual.FloatArr[2]; linePt1.Y = visual.FloatArr[3]; - - auto line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &linePt2, &linePt1); + TLine* line = nullptr; + try + { + line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &linePt2, &linePt1); + } + catch (...) + { + } if (line) { line->Offset(table->CollisionCompOffset); @@ -29,7 +35,14 @@ TOneway::TOneway(TPinballTable* table, int groupIndex) : TCollisionComponent(tab EdgeList.push_back(line); } - line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &linePt1, &linePt2); + line = nullptr; + try + { + line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &linePt1, &linePt2); + } + catch (...) + { + } Line = line; if (line) { diff --git a/SpaceCadetPinball/TPinballTable.cpp b/SpaceCadetPinball/TPinballTable.cpp index 62148f7..2790015 100644 --- a/SpaceCadetPinball/TPinballTable.cpp +++ b/SpaceCadetPinball/TPinballTable.cpp @@ -58,7 +58,14 @@ TPinballTable::TPinballTable(): TPinballComponent(nullptr, -1, false) MultiballFlag = 0; PlayerCount = 0; - auto ballObj = new TBall(this); + TBall* ballObj = nullptr; + try + { + ballObj = new TBall(this); + } + catch (...) + { + } BallList.push_back(ballObj); if (ballObj) ballObj->ActiveFlag = 0; @@ -368,7 +375,7 @@ int TPinballTable::Message(int code, float value) LightGroup->Message(34, 0.0); LightGroup->Message(20, 0.0); Plunger->Message(1016, 0.0); - if (Demo->ActiveFlag) + if (Demo && Demo->ActiveFlag) rc_text = pinball::get_rc_string(30, 0); else rc_text = pinball::get_rc_string(26, 0); diff --git a/SpaceCadetPinball/TRamp.cpp b/SpaceCadetPinball/TRamp.cpp index 5b524ce..04eb76d 100644 --- a/SpaceCadetPinball/TRamp.cpp +++ b/SpaceCadetPinball/TRamp.cpp @@ -116,7 +116,14 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table, } if (collisionGroup) { - auto line = new TLine(this, &ActiveFlag, collisionGroup, point1, point2); + TLine* line = nullptr; + try + { + line = new TLine(this, &ActiveFlag, collisionGroup, point1, point2); + } + catch (...) + { + } EdgeList.push_back(line); if (line) { diff --git a/SpaceCadetPinball/TRollover.cpp b/SpaceCadetPinball/TRollover.cpp index d11ad79..6146bc1 100644 --- a/SpaceCadetPinball/TRollover.cpp +++ b/SpaceCadetPinball/TRollover.cpp @@ -44,7 +44,6 @@ void TRollover::Collision(TBall* ball, vector_type* nextPosition, vector_type* d ball->Position.Y = nextPosition->Y; ball->RayMaxDistance -= coef; ball->not_again(edge); - gdrv_bitmap8* bmp = nullptr; if (!PinballTable->TiltLockFlag) { if (RolloverFlag) @@ -60,6 +59,7 @@ void TRollover::Collision(TBall* ball, vector_type* nextPosition, vector_type* d RolloverFlag = RolloverFlag == 0; if (ListBitmap) { + gdrv_bitmap8* bmp = nullptr; if (!RolloverFlag) bmp = ListBitmap->at(0); render::sprite_set_bitmap(RenderSprite, bmp); diff --git a/SpaceCadetPinball/TTableLayer.cpp b/SpaceCadetPinball/TTableLayer.cpp index e45ba36..2bc9d82 100644 --- a/SpaceCadetPinball/TTableLayer.cpp +++ b/SpaceCadetPinball/TTableLayer.cpp @@ -80,13 +80,20 @@ TTableLayer::TTableLayer(TPinballTable* table): TCollisionComponent(table, -1, f for (auto visFloatArrCount = visual.FloatArrCount; visFloatArrCount > 0; visFloatArrCount--) { - auto line = new TLine(this, - &ActiveFlag, - visual.CollisionGroup, - visArrPtr[2], - visArrPtr[3], - visArrPtr[0], - visArrPtr[1]); + TLine* line = nullptr; + try + { + line = new TLine(this, + &ActiveFlag, + visual.CollisionGroup, + visArrPtr[2], + visArrPtr[3], + visArrPtr[0], + visArrPtr[1]); + } + catch (...) + { + } if (line) { line->place_in_grid(); diff --git a/SpaceCadetPinball/TTextBox.cpp b/SpaceCadetPinball/TTextBox.cpp index 5467555..4d98b5f 100644 --- a/SpaceCadetPinball/TTextBox.cpp +++ b/SpaceCadetPinball/TTextBox.cpp @@ -123,7 +123,14 @@ void TTextBox::Display(const char* text, float time) if (Timer == -1) Clear(); - auto message = new TTextBoxMessage(text, time); + TTextBoxMessage* message = nullptr; + try + { + message = new TTextBoxMessage(text, time); + } + catch (...) + { + } if (message) { if (message->Text) diff --git a/SpaceCadetPinball/TTextBoxMessage.cpp b/SpaceCadetPinball/TTextBoxMessage.cpp index 97b4583..5d5ecd0 100644 --- a/SpaceCadetPinball/TTextBoxMessage.cpp +++ b/SpaceCadetPinball/TTextBoxMessage.cpp @@ -10,7 +10,14 @@ TTextBoxMessage::TTextBoxMessage(const char* text, float time) if (text) { const auto textLen = strlen(text) + 1; - Text = new char[textLen]; + Text = nullptr; + try + { + Text = new char[textLen]; + } + catch (...) + { + } if (Text) strncpy(Text, text, textLen); } diff --git a/SpaceCadetPinball/TTripwire.cpp b/SpaceCadetPinball/TTripwire.cpp index 46bdacc..bc34094 100644 --- a/SpaceCadetPinball/TTripwire.cpp +++ b/SpaceCadetPinball/TTripwire.cpp @@ -6,7 +6,7 @@ #include "TBall.h" #include "TPinballTable.h" -TTripwire::TTripwire(TPinballTable* table, int groupIndex) : TRollover(table, groupIndex, 1) +TTripwire::TTripwire(TPinballTable* table, int groupIndex) : TRollover(table, groupIndex, true) { } diff --git a/SpaceCadetPinball/maths.cpp b/SpaceCadetPinball/maths.cpp index 7df44a4..9a62fb2 100644 --- a/SpaceCadetPinball/maths.cpp +++ b/SpaceCadetPinball/maths.cpp @@ -206,9 +206,6 @@ void maths::line_init(line_type* line, float x0, float y0, float x1, float y1) float maths::ray_intersect_line(ray_type* ray, line_type* line) { - bool v5; - bool v6; - float perpDot = line->PerpendicularL.Y * ray->Direction.Y + ray->Direction.X * line->PerpendicularL.X; if (perpDot < 0.0f) { @@ -224,8 +221,8 @@ float maths::ray_intersect_line(ray_type* ray, line_type* line) { if (v4 >= line->OriginX) { - v5 = v4 < line->OriginY; - v6 = v4 == line->OriginY; + bool v5 = v4 < line->OriginY; + bool v6 = v4 == line->OriginY; if (v5 || v6) return result; return 1000000000.0; @@ -234,8 +231,8 @@ float maths::ray_intersect_line(ray_type* ray, line_type* line) else if (line->OriginX <= line->RayIntersect.X) { float v7 = line->RayIntersect.X; - v5 = v7 < line->OriginY; - v6 = v7 == line->OriginY; + bool v5 = v7 < line->OriginY; + bool v6 = v7 == line->OriginY; if (v5 || v6) return result; return 1000000000.0; @@ -299,7 +296,7 @@ float maths::basic_collision(TBall* ball, vector_type* nextPosition, vector_type return projSpeed; } -float maths::Distance_Squared(vector_type vec1, vector_type vec2) +float maths::Distance_Squared(vector_type& vec1, vector_type& vec2) { return (vec1.Y - vec2.Y) * (vec1.Y - vec2.Y) + (vec1.X - vec2.X) * (vec1.X - vec2.X); } diff --git a/SpaceCadetPinball/maths.h b/SpaceCadetPinball/maths.h index a975463..3e0d767 100644 --- a/SpaceCadetPinball/maths.h +++ b/SpaceCadetPinball/maths.h @@ -87,7 +87,7 @@ public: static float basic_collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float elasticity, float smoothness, float threshold, float boost); - static float Distance_Squared(vector_type vec1, vector_type vec2); + static float Distance_Squared(vector_type& vec1, vector_type& vec2); static float DotProduct(vector_type* vec1, vector_type* vec2); static void vswap(vector_type* vec1, vector_type* vec2); static float Distance(vector_type* vec1, vector_type* vec2); diff --git a/SpaceCadetPinball/partman.cpp b/SpaceCadetPinball/partman.cpp index 5c89df9..04b06a9 100644 --- a/SpaceCadetPinball/partman.cpp +++ b/SpaceCadetPinball/partman.cpp @@ -27,8 +27,12 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode) return nullptr; } - auto datFile = new DatFile(); - if (!datFile) + DatFile* datFile; + try + { + datFile = new DatFile(); + } + catch (...) { fclose(fileHandle); return nullptr; @@ -39,8 +43,12 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode) if (header.Unknown) { - auto unknownBuf = new char[header.Unknown]; - if (!unknownBuf) + char* unknownBuf; + try + { + unknownBuf = new char[header.Unknown]; + } + catch (...) { fclose(fileHandle); delete datFile; @@ -107,13 +115,18 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode) } else { - auto entryBuffer = new char[fieldSize]; - entryData->Buffer = entryBuffer; - if (!entryBuffer) + char* entryBuffer; + try { + entryBuffer = new char[fieldSize]; + } + catch (...) + { + entryData->Buffer = nullptr; abort = true; break; } + entryData->Buffer = entryBuffer; fread(entryBuffer, 1, fieldSize, fileHandle); } diff --git a/SpaceCadetPinball/render.cpp b/SpaceCadetPinball/render.cpp index 30d6b35..e2e9b2c 100644 --- a/SpaceCadetPinball/render.cpp +++ b/SpaceCadetPinball/render.cpp @@ -142,9 +142,15 @@ void render::sprite_modified(render_sprite_type_struct* sprite) render_sprite_type_struct* render::create_sprite(VisualTypes visualType, gdrv_bitmap8* bmp, zmap_header_type* zMap, int xPosition, int yPosition, rectangle_type* rect) { - auto sprite = new render_sprite_type_struct(); - if (!sprite) + render_sprite_type_struct* sprite; + try + { + sprite = new render_sprite_type_struct(); + } + catch (...) + { return nullptr; + } sprite->BmpRect.YPosition = yPosition; sprite->BmpRect.XPosition = xPosition; sprite->Bmp = bmp; @@ -420,7 +426,7 @@ void render::build_occlude_list() } } - if (!mainSprite->UnknownFlag && mainSprite->Bmp && spriteArr->size() < 2) + if (mainSprite->Bmp && spriteArr->size() < 2) spriteArr->clear(); if (!spriteArr->empty()) { diff --git a/SpaceCadetPinball/score.cpp b/SpaceCadetPinball/score.cpp index 243b56d..8277b7c 100644 --- a/SpaceCadetPinball/score.cpp +++ b/SpaceCadetPinball/score.cpp @@ -18,9 +18,15 @@ int score::init() scoreStruct* score::create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp) { - auto score = new scoreStruct(); - if (!score) + scoreStruct* score; + try + { + score = new scoreStruct(); + } + catch (...) + { return nullptr; + } score->Score = -9999; score->BackgroundBmp = renderBgBmp; diff --git a/SpaceCadetPinball/timer.cpp b/SpaceCadetPinball/timer.cpp index bfbd25c..dc4ae04 100644 --- a/SpaceCadetPinball/timer.cpp +++ b/SpaceCadetPinball/timer.cpp @@ -12,10 +12,17 @@ timer_struct* timer::TimerBuffer; int timer::init(int count) { - auto buf = new timer_struct[count]; - TimerBuffer = buf; - if (!buf) + timer_struct* buf; + try + { + buf = new timer_struct[count]; + } + catch (...) + { + TimerBuffer = nullptr; return 1; + } + TimerBuffer = buf; Count = 0; MaxCount = count; SetCount = 1;