Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some crashes 2025-01-13 #987

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b2de538
unit_csv.cpp: Handle shield values that cannot be converted to an int
stephengtuggy Jan 12, 2025
0132b05
Get rid of vs_vector. It was a bad idea to begin with, and only ever …
stephengtuggy Jan 12, 2025
61c58b2
Drop reference to vs_vector.h in Stdafx.h
stephengtuggy Jan 12, 2025
1ab4736
damageable.cpp: Fix index-out-of-bounds condition in Damageable::Armo…
stephengtuggy Jan 12, 2025
21440fd
basecomputer.cpp: Replace all uses of operator[] on vectors with `.at…
stephengtuggy Jan 12, 2025
b1d4927
gl_texture.cpp: Replace all uses of operator[] on vectors with `.at(.…
stephengtuggy Jan 12, 2025
8988b4c
controls_factory.cpp: Replace all uses of operator[] on vectors with …
stephengtuggy Jan 12, 2025
fd09cd8
component_utils.cpp: Fix "Yaw_Governor_Right" and "Yaw_Governor_Left"
stephengtuggy Jan 12, 2025
af66299
component_utils.cpp: Spiffy up copyright header
stephengtuggy Jan 12, 2025
34cb8e1
Merge branch 'master' into fix/index_out_of_bounds_2025-01-11
stephengtuggy Jan 13, 2025
7604ba3
mesh_gfx.cpp: Use std::stable_partition deletion method (twice) in Me…
stephengtuggy Jan 13, 2025
c4a2fdc
mesh_gfx.cpp: Fix data type
stephengtuggy Jan 13, 2025
0933770
mesh_gfx.cpp: More logging
stephengtuggy Jan 13, 2025
8d9132d
controls_factory.cpp: Handle fewer font elements than expected
stephengtuggy Jan 14, 2025
8edfc65
mesh_gfx.cpp: Log deletions only when 1 or more elements were deleted
stephengtuggy Jan 14, 2025
2af613f
basecomputer.cpp: Fix two CodeQL alerts
stephengtuggy Jan 14, 2025
b7e9964
mesh_gfx.cpp: More fine-tuning
stephengtuggy Jan 14, 2025
afce86c
gh-actions-pr.yml: Comment out openSUSE Leap and Rocky Linux 9, since…
stephengtuggy Jan 14, 2025
30a7f68
unit_json_factory.cpp: Handle JSON parsing errors
stephengtuggy Jan 14, 2025
82b09eb
unit_json_factory.cpp: VS_LOG_FLUSH_EXIT on JSON parsing errors
stephengtuggy Jan 14, 2025
3781301
unit_json_factory.cpp: catch std::exception instead of boost::json::s…
stephengtuggy Jan 14, 2025
4cd3f7d
Merge branch 'sgt_mac_2025-01-09' into fix/index_out_of_bounds_2025-0…
stephengtuggy Jan 14, 2025
6e4decc
Merge branch 'master' into fix/index_out_of_bounds_2025-01-11
stephengtuggy Jan 14, 2025
4c99f0e
Apply @royfalk 's changes to vdu.cpp from #973
stephengtuggy Jan 14, 2025
7a92f2a
vsfilesystem.cpp, xml_support.h: Omit some commented-out code
stephengtuggy Jan 15, 2025
481a838
cockpit.cpp: Use boost::format instead of sprintf to build the "Your …
stephengtuggy Jan 15, 2025
ce9c51f
Add some more Python error handling, logging, and search paths
stephengtuggy Jan 15, 2025
df25d52
basecomputer.cpp, unit_generic.cpp: Fix a few Python module paths; al…
stephengtuggy Jan 15, 2025
6dcf929
Merge remote-tracking branch 'origin/fix/index_out_of_bounds_2025-01-…
stephengtuggy Jan 15, 2025
d597c12
Got the ship_view Python module to load! Now to fix the code in that …
stephengtuggy Jan 15, 2025
09f516c
Merge branch 'master' into fix/index_out_of_bounds_2025-01-11
stephengtuggy Jan 15, 2025
36c49d7
Merge branch 'master' into fix/index_out_of_bounds_2025-01-11
stephengtuggy Jan 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/gh-actions-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ jobs:
OpenGL_GL_PREFERENCE: 'GLVND'
ENABLE_PIE: 'OFF'
allow_failure: false
- FROM: 'opensuse/leap:15.6'
COMPILER: 'clang'
OpenGL_GL_PREFERENCE: 'LEGACY'
ENABLE_PIE: 'ON'
allow_failure: true
#- FROM: 'opensuse/leap:15.6'
# COMPILER: 'clang'
# OpenGL_GL_PREFERENCE: 'LEGACY'
# ENABLE_PIE: 'ON'
# allow_failure: true
- FROM: 'fedora:41'
COMPILER: 'clang'
OpenGL_GL_PREFERENCE: 'LEGACY'
Expand All @@ -71,11 +71,11 @@ jobs:
OpenGL_GL_PREFERENCE: 'GLVND'
ENABLE_PIE: 'ON'
allow_failure: false
- FROM: 'rockylinux_rockylinux:9.5'
COMPILER: 'gcc'
OpenGL_GL_PREFERENCE: 'GLVND'
ENABLE_PIE: 'ON'
allow_failure: true
#- FROM: 'rockylinux_rockylinux:9.5'
# COMPILER: 'gcc'
# OpenGL_GL_PREFERENCE: 'GLVND'
# ENABLE_PIE: 'ON'
# allow_failure: true
# Disabled until the build can be fixed
#- FROM: 'rockylinux_rockylinux:8.10'
# COMPILER: 'clang'
Expand Down
135 changes: 68 additions & 67 deletions engine/src/cmd/basecomputer.cpp

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions engine/src/cmd/collide2/CSopcodecollider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/*
* Copyright (C) 2020 pyramid3d
* Copyright (C) 2020-2022 Stephen G. Tuggy
* Copyright (C) 2020-2025 Stephen G. Tuggy
*/


Expand All @@ -40,9 +40,8 @@
#undef _X

using namespace Opcode;
using namespace VegaStrike;

static vs_vector<csCollisionPair> pairs;
static std::vector<csCollisionPair> pairs;

csOPCODECollider::csOPCODECollider(const std::vector<mesh_polygon> &polygons) {
m_pCollisionModel = nullptr;
Expand Down Expand Up @@ -70,8 +69,8 @@ void csOPCODECollider::GeometryInitialize(const std::vector<mesh_polygon> &polyg
OPCODECREATE OPCC;
unsigned int tri_count = 0;
std::vector<Vector>::size_type vert_count = 0;
for (std::vector<mesh_polygon>::size_type i = 0; i < polygons.size(); ++i) {
vert_count += polygons.at(i).v.size();
for (const auto & polygon : polygons) {
vert_count += polygon.v.size();
}
tri_count = vert_count / 3;
if (tri_count) {
Expand All @@ -88,11 +87,11 @@ void csOPCODECollider::GeometryInitialize(const std::vector<mesh_polygon> &polyg

/* Copies the Vector's in mesh_polygon to Point's in vertholder.
* This sucks but i dont see anyway around it */
for (std::vector<mesh_polygon>::size_type i = 0; i < polygons.size(); ++i) {
const mesh_polygon *p = (&polygons.at(i));
for (std::vector<Vector>::size_type j = 0; j < p->v.size(); ++j) {
vertholder[last++].Set(p->v[j].i, p->v[j].j, p->v[j].k);
tmp.AddBoundingVertex(p->v[j]);
for (const auto & polygon : polygons) {
const mesh_polygon *p = (&polygon);
for (const auto & j : p->v) {
vertholder[last++].Set(j.i, j.j, j.k);
tmp.AddBoundingVertex(j);
}
}
radius = max3(tmp.MaxX() - tmp.MinX(), tmp.MaxY() - tmp.MinY(),
Expand Down Expand Up @@ -284,11 +283,12 @@ void csOPCODECollider::CopyCollisionPairs(csOPCODECollider *col1,
const Pair *colPairs = TreeCollider.GetPairs();
Point *vertholder0 = col1->vertholder;
Point *vertholder1 = col2->vertholder;
int j;
uint32_t j;
size_t oldlen = pairs.size();
pairs.resize(oldlen + N_pairs);
size_t newlen = oldlen + N_pairs;
pairs.resize(newlen);

for (unsigned int i = 0; i < N_pairs; ++i) {
for (unsigned int i = 0; i < N_pairs && oldlen < newlen; ++i) {
j = 3 * colPairs[i].id0;
pairs.at(oldlen).a1 = vertholder0[j];
pairs.at(oldlen).b1 = vertholder0[j + 1];
Expand Down
10 changes: 4 additions & 6 deletions engine/src/cmd/collide2/Stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
* Copyright (C) 2001 Pierre Terdiman
* Homepage: http://www.codercorner.com/Opcode.htm
*
* Copyright (C) Daniel Horn, chuck starchaser, and pheonixstorm
* Copyright (C) 2020 pyramid3d, Stephen G. Tuggy, and other Vega Strike contributors
* Copyright (C) 2021-2023 Stephen G. Tuggy, Benjamen R. Meyer
* Copyright (C) 2001-2025 Daniel Horn, chuck starchaser, pheonixstorm,
* Stephen G. Tuggy, Benjamen R. Meyer, and other Vega Strike contributors
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
*
Expand All @@ -19,11 +18,11 @@
*
* Vega Strike is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>.
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand All @@ -46,6 +45,5 @@
#include "opcodetypes.h"
#include "opcodesysdef.h"
#include "Opcode.h"
#include "vs_vector.h"

#endif //VEGA_STRIKE_ENGINE_CMD_COLLSION2_STDAFX_H
29 changes: 16 additions & 13 deletions engine/src/cmd/controls_factory.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
/*
* controls_factory.cpp
*
* Copyright (C) Daniel Horn
* Copyright (C) 2023 Roy Falk, Stephen G. Tuggy, Benjamen R. Meyer and other Vega Strike
* contributors
* Copyright (C) 2001-2025 Daniel Horn, Roy Falk, Stephen G. Tuggy,
* Benjamen R. Meyer and other Vega Strike contributors
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
*
Expand All @@ -16,11 +15,11 @@
*
* Vega Strike is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>.
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>.
*/

#include "controls_factory.h"
Expand Down Expand Up @@ -105,9 +104,9 @@ static std::vector<double> splitAndConvert (const std::string &s, char delim) {
GFXColor getColor(const std::string& colorString) {
std::vector<double> colorTuple = splitAndConvert(colorString, ',');
if(colorTuple.size() == 4) {
return GFXColor(colorTuple[0], colorTuple[1], colorTuple[2], colorTuple[3]);
return GFXColor(colorTuple.at(0), colorTuple.at(1), colorTuple.at(2), colorTuple.at(3));
} else {
return GFXColor(colorTuple[0], colorTuple[1], colorTuple[2]);
return GFXColor(colorTuple.at(0), colorTuple.at(1), colorTuple.at(2));
}

}
Expand Down Expand Up @@ -140,7 +139,7 @@ Control* getControl(std::map<std::string, std::string> attributes) {
// Text Margin
if(attributes.count("textMargins")) {
std::vector<double> size = splitAndConvert(attributes["textMargins"], ',');
sd->setTextMargins(Size(size[0], size[1]));
sd->setTextMargins(Size(size.at(0), size.at(1)));
}

if(attributes.count("multiline")) {
Expand Down Expand Up @@ -258,7 +257,7 @@ Control* getControl(std::map<std::string, std::string> attributes) {
// Text Margin
if(attributes.count("textMargins")) {
std::vector<double> size = splitAndConvert(attributes["textMargins"], ',');
p->setTextMargins(Size(size[0], size[1]));
p->setTextMargins(Size(size.at(0), size.at(1)));
}
} else if(type == "staticImageDisplay") {
StaticImageDisplay* sid = new StaticImageDisplay;
Expand All @@ -272,14 +271,18 @@ Control* getControl(std::map<std::string, std::string> attributes) {
// Font
if(attributes.count("font")) {
std::vector<double> font_array = splitAndConvert(attributes["font"], ',');
Font font(font_array[0], font_array[1]);
c->setFont(font);
if (font_array.size() < 2) {
VS_LOG(error, "controls_factory getControl(): font_array doesn't have enough elements");
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why this condition is happening. We will probably want to investigate further. But for now, this keeps the game from crashing at this point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this raises a bigger philosophical question of how much crap are we willing to let the engine take from the assets?

For JSON files, the file obviously needs to be formatted correctly or parsing will fail. Most JSON files are crucial to the game, so may as well crash it with an error.

But this is inside content and for a specific control so it points to an error in how I converted fonts to controls. Best open an issue/bug for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Font font(font_array.at(0), font_array.at(1));
c->setFont(font);
}
}

// Rect
if(attributes.count("rect")) {
std::vector<double> rect = splitAndConvert(attributes["rect"], ',');
c->setRect(Rect(rect[0], rect[1], rect[2], rect[3]));
c->setRect(Rect(rect.at(0), rect.at(1), rect.at(2), rect.at(3)));
}

// Color
Expand Down
10 changes: 4 additions & 6 deletions engine/src/cmd/damageable.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* damageable.cpp
*
* Copyright (C) 2020-2022 Daniel Horn, Roy Falk, Stephen G. Tuggy and
* Copyright (C) 2020-2025 Daniel Horn, Roy Falk, Stephen G. Tuggy and
* other Vega Strike contributors
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
Expand All @@ -15,11 +15,11 @@
*
* Vega Strike is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>.
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>.
*/


Expand Down Expand Up @@ -524,7 +524,7 @@ float Damageable::RShieldData() const {
void Damageable::ArmorData(float armor[8]) const {
Damageable *damageable = const_cast<Damageable *>(this);
DamageableLayer armor_layer = damageable->GetArmorLayer();
for (int i = 0; i < 8; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. You caught a bug of mine here. Did this segfault or fill the array with junk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I actually hit this section of code during my testing. If I had, though, I think a segfault would have been most likely. The destination array was too small to write 8 elements to.

for (int i = 0; i < armor_layer.number_of_facets; ++i) {
armor[i] = armor_layer.facets[i].health;
}
}
Expand Down Expand Up @@ -612,5 +612,3 @@ bool Damageable::flickerDamage() {
}
return false;
}


24 changes: 15 additions & 9 deletions engine/src/cmd/unit_csv.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* Copyright (C) 2001-2022 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* and other Vega Strike contributors.
* unit_csv.cpp
*
* Copyright (C) 2001-2025 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* Roy Falk, and other Vega Strike contributors.
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
*
Expand All @@ -13,7 +15,7 @@
*
* Vega Strike is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
Expand Down Expand Up @@ -854,7 +856,16 @@ void Unit::LoadRow(std::string unit_identifier, string modification, bool saved_

for (int i = 0; i < shield->number_of_facets; i++) {
const std::string shield_string_value = UnitCSVFactory::GetVariable(unit_key, shield_keys[i], std::string());
shield_values[i] = std::stoi(shield_string_value);
if (shield_string_value.empty()) {
shield_values[i] = 0.0f;
} else {
try {
shield_values[i] = static_cast<float>(std::stoi(shield_string_value));
} catch (const std::invalid_argument& ex) {
VS_LOG(warning, (boost::format("Unable to convert shield value '%1%' to a number") % shield_string_value));
shield_values[i] = 0.0f;
}
}
}

if (shield->number_of_facets == 4 || shield->number_of_facets == 2) {
Expand Down Expand Up @@ -1389,8 +1400,3 @@ string Unit::WriteUnitString() {
std::map<std::string, std::string> unit = UnitToMap();
return writeCSV(unit);
}





8 changes: 4 additions & 4 deletions engine/src/cmd/unit_generic.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* unit_generic.cpp
*
* Copyright (C) 2001-2023 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* Copyright (C) 2001-2025 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* and other Vega Strike contributors.
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
Expand All @@ -19,7 +19,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>.
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>.
*/

// -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
Expand Down Expand Up @@ -2941,7 +2941,7 @@ bool Unit::UpAndDownGrade(const Unit *up,

if (!csv_cell_null_check || force_change_on_nothing
|| cell_has_recursive_data(upgrade_name, up->faction, "Armor_Front_Top_Right")) {
for (int i = 0; i < 8; i++) {
for (int i = 0; i < armor->number_of_facets; ++i) {
STDUPGRADE(armor->facets[i].health,
up->armor->facets[i].health,
templ->armor->facets[i].health, 0);
Expand Down Expand Up @@ -4682,4 +4682,4 @@ float Unit::energyData() const {
} else {
return energy.Percent();
}
}
}
10 changes: 7 additions & 3 deletions engine/src/cmd/unit_json_factory.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*
* unit_csv_factory.cpp
*
* Copyright (C) 2021 Roy Falk
* Copyright (C) 2022 Stephen G. Tuggy
* Copyright (C) 2021-2025 Roy Falk and Stephen G. Tuggy
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
*
Expand Down Expand Up @@ -39,7 +38,12 @@
void UnitJSONFactory::ParseJSON(VSFileSystem::VSFile &file, bool player_ship) {
const std::string json_text = file.ReadFull();

boost::json::value json_value = boost::json::parse(json_text);
boost::json::value json_value;
try {
json_value = boost::json::parse(json_text);
} catch (std::exception const& e) {
VS_LOG_FLUSH_EXIT(fatal, (boost::format("Error parsing JSON in UnitJSONFactory::ParseJSON(): %1%") % e.what()), 42);
}
boost::json::array root_array = json_value.get_array();

for(boost::json::value& unit_value : root_array) {
Expand Down
8 changes: 4 additions & 4 deletions engine/src/components/component_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* src/components/component_printer.cpp
* src/components/component_utils.cpp
*
* Copyright (C) 2001-2023 Daniel Horn, Benjamen Meyer, Roy Falk, Stephen G. Tuggy,
* Copyright (C) 2001-2025 Daniel Horn, Benjamen Meyer, Roy Falk, Stephen G. Tuggy,
* and other Vega Strike contributors.
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
Expand All @@ -15,7 +15,7 @@
*
* Vega Strike is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
Expand Down Expand Up @@ -139,7 +139,7 @@ EnergyContainer* GetSourceFromConfiguration(const EnergyConsumerSource source, E


// For Drive and DriveUpgrade
const std::string yaw_governor[] = {"Yaw_Governor", "Yaw_Governor", "Yaw_Governor"};
const std::string yaw_governor[] = {"Yaw_Governor", "Yaw_Governor_Right", "Yaw_Governor_Left"};
const std::string pitch_governor[] = {"Pitch_Governor", "Pitch_Governor_Up", "Pitch_Governor_Down"};
const std::string roll_governor[] = {"Roll_Governor", "Roll_Governor_Right", "Roll_Governor_Left"};

Expand Down
Loading
Loading