Skip to content

Commit

Permalink
Some logging refactoring, plus some work on the subscript-out-of-rang…
Browse files Browse the repository at this point in the history
…e crash that has been occurring in GFXDeleteTexture(int handle)
  • Loading branch information
Stephen G authored and Stephen G committed Apr 20, 2024
1 parent 9607bfa commit 2c033d6
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 103 deletions.
6 changes: 3 additions & 3 deletions engine/src/audio/test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* test.cpp
*
* Copyright (C) 2001-2022 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* Copyright (C) 2001-2024 Daniel Horn, pyramid3d, 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 @@ -665,7 +665,7 @@ void closeRenderer() {
}

void VSExit(int code) {
VegaStrikeLogging::vega_logger()->FlushLogs();
VegaStrikeLogging::VegaStrikeLogger::instance().FlushLogsProgramExiting();
exit(code);
}

Expand Down
8 changes: 5 additions & 3 deletions engine/src/cmd/basecomputer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2001-2022 Daniel Horn, Mike Byron, pyramid3d, Stephen G. Tuggy,
* basecomputer.cpp
*
* Copyright (C) 2001-2024 Daniel Horn, Mike Byron, pyramid3d, Stephen G. Tuggy,
* 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 @@ -4273,7 +4275,7 @@ void trackPrice(int whichplayer, const Cargo &item, float price, const string &s
}
}

VegaStrikeLogging::vega_logger()->FlushLogs();
VegaStrikeLogging::VegaStrikeLogger::instance().FlushLogs();

highest.clear();
highest.resize(recordedHighestPrices.size());
Expand Down
5 changes: 2 additions & 3 deletions engine/src/cmd/script/director.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* director.cpp
*
* Copyright (C) 2001-2023 Daniel Horn, Alexander Rawass, pyramid3d,
* Copyright (C) 2001-2024 Daniel Horn, Alexander Rawass, pyramid3d,
* Stephen G. Tuggy, and other Vega Strike contributors
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
Expand All @@ -10,7 +10,7 @@
*
* Vega Strike is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Vega Strike is distributed in the hope that it will be useful,
Expand Down Expand Up @@ -94,7 +94,6 @@ void Mission::DirectorLoop() {
VS_LOG_AND_FLUSH(fatal, "void Mission::DirectorLoop(): Python error occurred");
PyErr_Print();
PyErr_Clear();
VegaStrikeLogging::vega_logger()->FlushLogs();
}
throw;
}
Expand Down
6 changes: 3 additions & 3 deletions engine/src/exit_unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Implementation of VSExit for unit tests
*
* Copyright (C) 2001-2022 Daniel Horn, Stephen G. Tuggy,
* Copyright (C) 2001-2024 Daniel Horn, Stephen G. Tuggy,
* and other Vega Strike contributors.
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
Expand All @@ -17,7 +17,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 All @@ -29,6 +29,6 @@
#include "vs_logging.h"

void VSExit(int code) {
VegaStrikeLogging::vega_logger()->FlushLogs();
VegaStrikeLogging::VegaStrikeLogger::instance().FlushLogsProgramExiting();
exit(code);
}
8 changes: 5 additions & 3 deletions engine/src/gamemenu.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2001-2022 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* gamemenu.cpp
*
* Copyright (C) 2001-2024 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* 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 @@ -459,7 +461,7 @@ bool GameMenu::processMainMenuButton(const EventCommandId &command, Control *con
}

bool GameMenu::processExitGameButton(const EventCommandId &command, Control *control) {
VegaStrikeLogging::vega_logger()->FlushLogs();
VegaStrikeLogging::VegaStrikeLogger::instance().FlushLogsProgramExiting();
winsys_exit(0);
return true;
}
Expand Down
16 changes: 10 additions & 6 deletions engine/src/gfx/aux_texture.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/**
/*
* aux_texture.cpp
*
* Copyright (C) 2001-2002 Daniel Horn
* Copyright (C) 2020 pyramid3d, Stephen G. Tuggy, Roy Falk,
* and other Vega Strike contributors
* Copyright (C) 2021-2022 Stephen G. Tuggy
* Copyright (C) 2001-2024 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* Roy Falk, and other Vega Strike contributors
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
*
Expand Down Expand Up @@ -558,7 +556,13 @@ Texture::~Texture() {
} else {
original->refcount--;
if (original->refcount == 0) {
delete original;
if (original == this) {
VS_LOG(debug, "In Texture::~Texture() in aux_texture.cpp: original->refcount == 0, but original == this, so not deleting again. (We are already in the destructor.)");
} else {
VS_LOG(trace, "In Texture::~Texture() in aux_texture.cpp: original->refcount == 0, and original != this, so deleting original");
delete original;
original = nullptr;
}
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions engine/src/gfx/particle.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* particle.cpp
*
* Copyright (c) 2001-2022 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* Copyright (c) 2001-2024 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* and other Vega Strike Contributors
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
Expand All @@ -10,16 +10,16 @@
*
* Vega Strike is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 @@ -311,7 +311,7 @@ void ParticleTrail::DrawAndUpdate() {
}

particleVert.clear();
particleVert.reserve(particles.size() * (3 + 4));
particleVert.reserve(particles.size() * (static_cast<size_t>(3) + 4));
std::back_insert_iterator<std::vector<float> > v(particleVert);
for (size_t i = 0; i < nparticles; ++i) {
const QVector &loc = particles[i].location;
Expand Down Expand Up @@ -395,7 +395,7 @@ void ParticleTrail::DrawAndUpdate() {
}

particleVert.clear();
particleVert.reserve(nparticles * vertsPerParticle * (3 + 4 + 2));
particleVert.reserve(nparticles * vertsPerParticle * (static_cast<size_t>(3 + 4) + 2));
std::back_insert_iterator<std::vector<float> > v(particleVert);
for (size_t i = 0; i < nparticles; ++i) {
SetQuadVertex(particles[i].location, particles[i].color, particles[i].size, pgrow, ptrans, v, kCameraPosition);
Expand Down
12 changes: 8 additions & 4 deletions engine/src/gfx/sprite.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2001-2023 Daniel Horn, Alan Shieh, klaussfreire,
/*
* sprite.h
*
* Copyright (C) 2001-2024 Daniel Horn, Alan Shieh, klaussfreire,
* surfdargent, dan_w, pyramid3d, Stephen G. Tuggy, Benjamen R. Meyer,
* and other Vega Strike contributors.
*
Expand All @@ -14,12 +16,14 @@
*
* 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/>.
*/


#ifndef VEGA_STRIKE_ENGINE_GFX_SPRITE_H
#define VEGA_STRIKE_ENGINE_GFX_SPRITE_H

Expand Down Expand Up @@ -47,7 +51,7 @@ class VSSprite {
bool isAnimation;

//For private use only
VSSprite() : surface(0) {
VSSprite() : surface(nullptr), isAnimation(false), rotation(0.0F), maxs(0.0F), maxt(0.0F), heighto2(0.0F), widtho2(0.0F), xcenter(0.0F), ycenter(0.0F) {
}

public:
Expand Down
28 changes: 18 additions & 10 deletions engine/src/gldrv/gl_texture.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* gl_texture.cpp
*
* Copyright (C) 2001-2023 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* Copyright (C) 2001-2024 Daniel Horn, pyramid3d, 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 @@ -463,8 +463,8 @@ static void DownSampleTexture(unsigned char **newbuf,
amask >>= 1, tshift++, hshift++;
}
int tmask = (1 << tshift) - 1;
*newbuf = (unsigned char *) malloc(newheight * newwidth * pixsize * sizeof(unsigned char));
unsigned int temp[32 * 4];
*newbuf = (unsigned char*)malloc(static_cast<size_t>(newheight) * newwidth * pixsize * sizeof(unsigned char));
unsigned int temp[32 * 4]{};
unsigned char *orow = (*newbuf);
const unsigned char *irow = oldbuf;
for (i = 0; i < newheight; i++, orow += ostride, irow += rowstride) {
Expand Down Expand Up @@ -510,7 +510,7 @@ static void DownSampleTexture(unsigned char **newbuf,
//Specific purpose downsampler: 2x2 averaging
//a) Very little overhead
//b) Very common case (mipmap generation)
*newbuf = (unsigned char *) malloc(newheight * newwidth * pixsize * sizeof(unsigned char));
*newbuf = (unsigned char*)malloc(static_cast<size_t>(newheight) * newwidth * pixsize * sizeof(unsigned char));
unsigned char *orow = (*newbuf);
int ostride = newwidth * pixsize;
int istride = width * pixsize;
Expand Down Expand Up @@ -1093,11 +1093,18 @@ GFXBOOL /*GFXDRVAPI*/ GFXTransferTexture(unsigned char *buffer,
}

void /*GFXDRVAPI*/ GFXDeleteTexture(int handle) {
if (handle < 0) {
VS_LOG(error, (boost::format("GFXDeleteTexture(int handle) called with invalid, negative handle value %1%") % handle));
return;
} else if (handle >= textures.size()) {
VS_LOG(error, (boost::format("GFXDeleteTexture(int handle) called with invalid handle value %1%, which is greater than textures.size(): %2%") % handle % textures.size()));
return;
}
if (textures[handle].alive) {
glDeleteTextures(1, &textures[handle].name);
for (size_t i = 0; i < sizeof(activetexture) / sizeof(int); ++i) {
if (activetexture[i] == handle) {
activetexture[i] = -1;
glDeleteTextures(1, &textures[handle].name); // Is this correct? - SGT 2024-04-18
for (int & each_texture : activetexture) {
if (each_texture == handle) {
each_texture = -1;
}
}
}
Expand All @@ -1110,7 +1117,7 @@ void /*GFXDRVAPI*/ GFXDeleteTexture(int handle) {

void GFXInitTextureManager() {
for (size_t handle = 0; handle < textures.size(); ++handle) {
textures[handle].palette = NULL;
textures[handle].palette = nullptr;
textures[handle].width = textures[handle].height = textures[handle].iwidth = textures[handle].iheight = 0;
textures[handle].texturestage = 0;
textures[handle].name = 0;
Expand All @@ -1123,6 +1130,7 @@ void GFXInitTextureManager() {
}

void GFXDestroyAllTextures() {
// TODO: There's got to be a more efficient way to do this -- SGT 2024-04-18
for (size_t handle = 0; handle < textures.size(); handle++) {
GFXDeleteTexture(handle);
}
Expand Down
10 changes: 7 additions & 3 deletions engine/src/in_kb.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2001-2023 Daniel Horn, pyramid3d, Stephen G. Tuggy, Benjamen R. Meyer,
* in_kb.h
*
* Copyright (C) 2001-2024 Daniel Horn, pyramid3d, Stephen G. Tuggy, Benjamen R. Meyer,
* and other Vega Strike contributors.
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
Expand All @@ -13,12 +15,14 @@
*
* 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/>.
*/


#ifndef VEGA_STRIKE_ENGINE_IN_KB_H
#define VEGA_STRIKE_ENGINE_IN_KB_H

Expand All @@ -42,7 +46,7 @@ static void DefaultKBHandler(const KBData &, KBSTATE newState) // FIXME ?
struct HandlerCall {
KBHandler function;
KBData data;
KBSTATE state;
KBSTATE state{ KBSTATE::RESET }; // This variable was uninitialized. Is this a good initial value for it?

HandlerCall() {
function = DefaultKBHandler;
Expand Down
Loading

0 comments on commit 2c033d6

Please sign in to comment.