From fbbd275c6252fa2017d362bcfe4a6545ccdb7ae3 Mon Sep 17 00:00:00 2001 From: cambrialas Date: Thu, 5 Dec 2024 14:28:03 +0100 Subject: [PATCH] Windows bug fix: Variable array length --- common/lc_traintrack.cpp | 1 - common/lc_traintrack.h | 2 +- common/lc_viewmanipulator.cpp | 23 +++++++++++++---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/common/lc_traintrack.cpp b/common/lc_traintrack.cpp index 1f964e00..76d67f72 100644 --- a/common/lc_traintrack.cpp +++ b/common/lc_traintrack.cpp @@ -5,7 +5,6 @@ #include "piece.h" #include "lc_application.h" -#include // todo: // auto replace cross when going over a straight section // redo gizmo diff --git a/common/lc_traintrack.h b/common/lc_traintrack.h index eb71905b..6bccf847 100644 --- a/common/lc_traintrack.h +++ b/common/lc_traintrack.h @@ -28,7 +28,7 @@ public: return relatedPieces[index]; } - int Size() + size_t Size() { return relatedPieces.size(); } diff --git a/common/lc_viewmanipulator.cpp b/common/lc_viewmanipulator.cpp index cd2c257c..15a50d3a 100644 --- a/common/lc_viewmanipulator.cpp +++ b/common/lc_viewmanipulator.cpp @@ -384,9 +384,10 @@ void lcViewManipulator::DrawTrainTrack(lcPiece* Piece, lcContext* Context, float lcRelatedPiecesGroup* releatedPieces = Connections[ConnectionIndex].relatedPiecesGroup; int noOfPieces = releatedPieces->Size(); - lcVector3 Verts[noOfPieces * 2]; + int NumVerts = noOfPieces * 2; - int NumVerts = 0; + std::vector Verts; + Verts.resize(NumVerts); int degreeStep = 0; @@ -394,14 +395,15 @@ void lcViewManipulator::DrawTrainTrack(lcPiece* Piece, lcContext* Context, float degreeStep = 120 / (noOfPieces - 1); } + int VertsIdx = 0; for(int pieceNo = 0; pieceNo < noOfPieces; pieceNo++) { - Verts[NumVerts++] = Transform.GetTranslation() / OverlayScale; - Verts[NumVerts++] = (Transform.GetTranslation() + lcMul31(lcVector3(Transform[0]), lcMatrix44RotationZ(LC_DTOR * (-60 + (degreeStep * pieceNo) ))) * 100) / OverlayScale; + Verts[VertsIdx++] = Transform.GetTranslation() / OverlayScale; + Verts[VertsIdx++] = (Transform.GetTranslation() + lcMul31(lcVector3(Transform[0]), lcMatrix44RotationZ(LC_DTOR * (-60 + (degreeStep * pieceNo) ))) * 100) / OverlayScale; } Context->SetColor(1.0f, 1.0f, 1.0f, 1.0f); - Context->SetVertexBufferPointer(Verts); + Context->SetVertexBufferPointer(Verts.data()); Context->ClearIndexBuffer(); Context->SetVertexFormatPosition(3); @@ -978,11 +980,12 @@ std::pair lcViewManipulator::UpdateSelectMove() const lcMatrix44& Transform = Connections[ConnectionIndex].Transform; lcRelatedPiecesGroup* releatedPieces = Connections[ConnectionIndex].relatedPiecesGroup; + int noOfPieces = releatedPieces->Size(); + int NumVerts = noOfPieces; - lcVector3 Verts[noOfPieces]; - - int NumVerts = 0; + std::vector Verts; + Verts.resize(NumVerts); int degreeStep = 0; @@ -990,8 +993,8 @@ std::pair lcViewManipulator::UpdateSelectMove() degreeStep = 120 / (noOfPieces - 1); } - for(int pieceNo = 0; pieceNo < noOfPieces; pieceNo++) { - Verts[NumVerts++] = (Transform.GetTranslation() + lcMul31(lcVector3(Transform[0]), lcMatrix44RotationZ(LC_DTOR * (-60 + (degreeStep * pieceNo) ))) * 100) / 1; + for(int VertexIndex = 0; VertexIndex < noOfPieces; VertexIndex++) { + Verts[VertexIndex] = (Transform.GetTranslation() + lcMul31(lcVector3(Transform[0]), lcMatrix44RotationZ(LC_DTOR * (-60 + (degreeStep * VertexIndex) ))) * 100) / 1; } for (int VertexIndex = 0; VertexIndex < NumVerts; VertexIndex++)