From c623e4d8145d54b1a16f78ea8aee089cf8af2a19 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Thu, 24 Oct 2024 00:17:35 +0200 Subject: [PATCH 1/3] tr1: improve crash reports --- docs/tr1/CHANGELOG.md | 1 + src/tr1/game/shell.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/tr1/CHANGELOG.md b/docs/tr1/CHANGELOG.md index fc37355e7..a7686a427 100644 --- a/docs/tr1/CHANGELOG.md +++ b/docs/tr1/CHANGELOG.md @@ -1,6 +1,7 @@ ## [Unreleased](https://github.com/LostArtefacts/TRX/compare/tr1-4.5.1...develop) - ××××-××-×× - added support for wading, similar to TR2+ (#1537) - fixed missing pushblock SFX in Natla's Mines (#1714) +- fixed crash reports not working in certain circumstances (#1738) - improved enemy item drops by supporting the TR2+ approach of having drops defined in level data (#1713) - improved Italian localization for the Config Tool diff --git a/src/tr1/game/shell.c b/src/tr1/game/shell.c index 62d5eaa91..11b2f7430 100644 --- a/src/tr1/game/shell.c +++ b/src/tr1/game/shell.c @@ -287,8 +287,8 @@ void Shell_Main(void) void Shell_ExitSystem(const char *message) { - Shell_Shutdown(); S_Shell_ShowFatalError(message); + Shell_Shutdown(); } void Shell_ExitSystemFmt(const char *fmt, ...) From 4c845a8f0c58292a2e815ef72cdb03de288b0e24 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Thu, 24 Oct 2024 01:27:22 +0200 Subject: [PATCH 2/3] tr1: log details for SDL OpenGL context fails --- src/libtrx/gfx/context.c | 7 ++++--- src/libtrx/log.c | 2 -- src/tr1/game/shell.c | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libtrx/gfx/context.c b/src/libtrx/gfx/context.c index 1176ac113..65b4b5935 100644 --- a/src/libtrx/gfx/context.c +++ b/src/libtrx/gfx/context.c @@ -128,12 +128,13 @@ void GFX_Context_Attach(void *window_handle) m_Context.context = SDL_GL_CreateContext(m_Context.window_handle); - if (!m_Context.context) { - Shell_ExitSystem("Can't create OpenGL context"); + if (m_Context.context == NULL) { + Shell_ExitSystemFmt("Can't create OpenGL context: %s", SDL_GetError()); } if (SDL_GL_MakeCurrent(m_Context.window_handle, m_Context.context)) { - Shell_ExitSystem("Can't activate OpenGL context"); + Shell_ExitSystemFmt( + "Can't activate OpenGL context: %s", SDL_GetError()); } LOG_INFO("OpenGL vendor string: %s", glGetString(GL_VENDOR)); diff --git a/src/libtrx/log.c b/src/libtrx/log.c index cc8d3443c..07e75492b 100644 --- a/src/libtrx/log.c +++ b/src/libtrx/log.c @@ -1,7 +1,5 @@ #include "log.h" -#include "memory.h" - #include #include diff --git a/src/tr1/game/shell.c b/src/tr1/game/shell.c index 11b2f7430..37bafd333 100644 --- a/src/tr1/game/shell.c +++ b/src/tr1/game/shell.c @@ -136,7 +136,7 @@ void Shell_Init(const char *gameflow_path) Screen_Init(); if (!GameFlow_LoadFromFile(gameflow_path)) { - Shell_ExitSystem("MAIN: unable to load script file"); + Shell_ExitSystemFmt("Unable to load gameflow file: %s", gameflow_path); return; } Savegame_Init(); From a1b50ffbf0a6471ccb174ca5235c0d13c00c8d9f Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Thu, 24 Oct 2024 01:40:28 +0200 Subject: [PATCH 3/3] gfx: be more careful with cleanups --- src/libtrx/gfx/gl/buffer.c | 30 ++++++++++++------- src/libtrx/gfx/gl/program.c | 14 +++++++++ src/libtrx/gfx/gl/sampler.c | 18 +++++++++-- src/libtrx/gfx/gl/texture.c | 11 +++++-- src/libtrx/gfx/gl/vertex_array.c | 18 +++++++---- src/libtrx/include/libtrx/gfx/gl/buffer.h | 3 ++ src/libtrx/include/libtrx/gfx/gl/program.h | 1 + src/libtrx/include/libtrx/gfx/gl/sampler.h | 3 ++ src/libtrx/include/libtrx/gfx/gl/texture.h | 3 ++ .../include/libtrx/gfx/gl/vertex_array.h | 3 ++ 10 files changed, 84 insertions(+), 20 deletions(-) diff --git a/src/libtrx/gfx/gl/buffer.c b/src/libtrx/gfx/gl/buffer.c index aed161a43..f2aa5538a 100644 --- a/src/libtrx/gfx/gl/buffer.c +++ b/src/libtrx/gfx/gl/buffer.c @@ -6,22 +6,27 @@ void GFX_GL_Buffer_Init(GFX_GL_BUFFER *buf, GLenum target) { - assert(buf); + assert(buf != NULL); buf->target = target; glGenBuffers(1, &buf->id); GFX_GL_CheckError(); + buf->initialized = true; } void GFX_GL_Buffer_Close(GFX_GL_BUFFER *buf) { - assert(buf); - glDeleteBuffers(1, &buf->id); - GFX_GL_CheckError(); + assert(buf != NULL); + if (buf->initialized) { + glDeleteBuffers(1, &buf->id); + GFX_GL_CheckError(); + } + buf->initialized = false; } void GFX_GL_Buffer_Bind(GFX_GL_BUFFER *buf) { - assert(buf); + assert(buf != NULL); + assert(buf->initialized); glBindBuffer(buf->target, buf->id); GFX_GL_CheckError(); } @@ -29,7 +34,8 @@ void GFX_GL_Buffer_Bind(GFX_GL_BUFFER *buf) void GFX_GL_Buffer_Data( GFX_GL_BUFFER *buf, GLsizei size, const void *data, GLenum usage) { - assert(buf); + assert(buf != NULL); + assert(buf->initialized); glBufferData(buf->target, size, data, usage); GFX_GL_CheckError(); } @@ -37,14 +43,16 @@ void GFX_GL_Buffer_Data( void GFX_GL_Buffer_SubData( GFX_GL_BUFFER *buf, GLsizei offset, GLsizei size, const void *data) { - assert(buf); + assert(buf != NULL); + assert(buf->initialized); glBufferSubData(buf->target, offset, size, data); GFX_GL_CheckError(); } void *GFX_GL_Buffer_Map(GFX_GL_BUFFER *buf, GLenum access) { - assert(buf); + assert(buf != NULL); + assert(buf->initialized); void *ret = glMapBuffer(buf->target, access); GFX_GL_CheckError(); return ret; @@ -52,14 +60,16 @@ void *GFX_GL_Buffer_Map(GFX_GL_BUFFER *buf, GLenum access) void GFX_GL_Buffer_Unmap(GFX_GL_BUFFER *buf) { - assert(buf); + assert(buf != NULL); + assert(buf->initialized); glUnmapBuffer(buf->target); GFX_GL_CheckError(); } GLint GFX_GL_Buffer_Parameter(GFX_GL_BUFFER *buf, GLenum pname) { - assert(buf); + assert(buf != NULL); + assert(buf->initialized); GLint params = 0; glGetBufferParameteriv(buf->target, pname, ¶ms); GFX_GL_CheckError(); diff --git a/src/libtrx/gfx/gl/program.c b/src/libtrx/gfx/gl/program.c index a3e65ab92..c45c182bf 100644 --- a/src/libtrx/gfx/gl/program.c +++ b/src/libtrx/gfx/gl/program.c @@ -24,6 +24,7 @@ bool GFX_GL_Program_Init(GFX_GL_PROGRAM *program) void GFX_GL_Program_Close(GFX_GL_PROGRAM *program) { + assert(program != NULL); if (program->id) { glDeleteProgram(program->id); GFX_GL_CheckError(); @@ -33,6 +34,7 @@ void GFX_GL_Program_Close(GFX_GL_PROGRAM *program) void GFX_GL_Program_Bind(GFX_GL_PROGRAM *program) { + assert(program != NULL); glUseProgram(program->id); GFX_GL_CheckError(); } @@ -40,6 +42,8 @@ void GFX_GL_Program_Bind(GFX_GL_PROGRAM *program) char *GFX_GL_Program_PreprocessShader( const char *content, GLenum type, GFX_GL_BACKEND backend) { + assert(content != NULL); + const char *version_ogl21 = "#version 120\n" "#extension GL_ARB_explicit_attrib_location: enable\n" @@ -85,6 +89,9 @@ char *GFX_GL_Program_PreprocessShader( void GFX_GL_Program_AttachShader( GFX_GL_PROGRAM *program, GLenum type, const char *path) { + assert(program != NULL); + assert(path != NULL); + GLuint shader_id = glCreateShader(type); GFX_GL_CheckError(); if (!shader_id) { @@ -137,6 +144,7 @@ void GFX_GL_Program_AttachShader( void GFX_GL_Program_Link(GFX_GL_PROGRAM *program) { + assert(program != NULL); glLinkProgram(program->id); GFX_GL_CheckError(); @@ -160,12 +168,14 @@ void GFX_GL_Program_Link(GFX_GL_PROGRAM *program) void GFX_GL_Program_FragmentData(GFX_GL_PROGRAM *program, const char *name) { + assert(program != NULL); glBindFragDataLocation(program->id, 0, name); GFX_GL_CheckError(); } GLint GFX_GL_Program_UniformLocation(GFX_GL_PROGRAM *program, const char *name) { + assert(program != NULL); GLint location = glGetUniformLocation(program->id, name); GFX_GL_CheckError(); if (location == -1) { @@ -177,6 +187,7 @@ GLint GFX_GL_Program_UniformLocation(GFX_GL_PROGRAM *program, const char *name) void GFX_GL_Program_Uniform3f( GFX_GL_PROGRAM *program, GLint loc, GLfloat v0, GLfloat v1, GLfloat v2) { + assert(program != NULL); glUniform3f(loc, v0, v1, v2); GFX_GL_CheckError(); } @@ -185,12 +196,14 @@ void GFX_GL_Program_Uniform4f( GFX_GL_PROGRAM *program, GLint loc, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { + assert(program != NULL); glUniform4f(loc, v0, v1, v2, v3); GFX_GL_CheckError(); } void GFX_GL_Program_Uniform1i(GFX_GL_PROGRAM *program, GLint loc, GLint v0) { + assert(program != NULL); glUniform1i(loc, v0); GFX_GL_CheckError(); } @@ -199,6 +212,7 @@ void GFX_GL_Program_UniformMatrix4fv( GFX_GL_PROGRAM *program, GLint loc, GLsizei count, GLboolean transpose, const GLfloat *value) { + assert(program != NULL); glUniformMatrix4fv(loc, count, transpose, value); GFX_GL_CheckError(); } diff --git a/src/libtrx/gfx/gl/sampler.c b/src/libtrx/gfx/gl/sampler.c index cb76df850..1735693d2 100644 --- a/src/libtrx/gfx/gl/sampler.c +++ b/src/libtrx/gfx/gl/sampler.c @@ -2,20 +2,30 @@ #include "gfx/gl/utils.h" +#include + void GFX_GL_Sampler_Init(GFX_GL_SAMPLER *sampler) { + assert(sampler != NULL); glGenSamplers(1, &sampler->id); GFX_GL_CheckError(); + sampler->initialized = true; } void GFX_GL_Sampler_Close(GFX_GL_SAMPLER *sampler) { - glDeleteSamplers(1, &sampler->id); - GFX_GL_CheckError(); + assert(sampler != NULL); + if (sampler->initialized) { + glDeleteSamplers(1, &sampler->id); + GFX_GL_CheckError(); + } + sampler->initialized = false; } void GFX_GL_Sampler_Bind(GFX_GL_SAMPLER *sampler, GLuint unit) { + assert(sampler != NULL); + assert(sampler->initialized); glBindSampler(unit, sampler->id); GFX_GL_CheckError(); } @@ -23,6 +33,8 @@ void GFX_GL_Sampler_Bind(GFX_GL_SAMPLER *sampler, GLuint unit) void GFX_GL_Sampler_Parameteri( GFX_GL_SAMPLER *sampler, GLenum pname, GLint param) { + assert(sampler != NULL); + assert(sampler->initialized); glSamplerParameteri(sampler->id, pname, param); GFX_GL_CheckError(); } @@ -30,6 +42,8 @@ void GFX_GL_Sampler_Parameteri( void GFX_GL_Sampler_Parameterf( GFX_GL_SAMPLER *sampler, GLenum pname, GLfloat param) { + assert(sampler != NULL); + assert(sampler->initialized); glSamplerParameterf(sampler->id, pname, param); GFX_GL_CheckError(); } diff --git a/src/libtrx/gfx/gl/texture.c b/src/libtrx/gfx/gl/texture.c index f5f067dcd..d0659389e 100644 --- a/src/libtrx/gfx/gl/texture.c +++ b/src/libtrx/gfx/gl/texture.c @@ -27,18 +27,23 @@ void GFX_GL_Texture_Init(GFX_GL_TEXTURE *texture, GLenum target) texture->target = target; glGenTextures(1, &texture->id); GFX_GL_CheckError(); + texture->initialized = true; } void GFX_GL_Texture_Close(GFX_GL_TEXTURE *texture) { assert(texture != NULL); - glDeleteTextures(1, &texture->id); - GFX_GL_CheckError(); + if (texture->initialized) { + glDeleteTextures(1, &texture->id); + GFX_GL_CheckError(); + } + texture->initialized = false; } void GFX_GL_Texture_Bind(GFX_GL_TEXTURE *texture) { assert(texture != NULL); + assert(texture->initialized); glBindTexture(texture->target, texture->id); GFX_GL_CheckError(); } @@ -48,6 +53,7 @@ void GFX_GL_Texture_Load( GLint internal_format, GLint format) { assert(texture != NULL); + assert(texture->initialized); GFX_GL_Texture_Bind(texture); @@ -65,6 +71,7 @@ void GFX_GL_Texture_Load( void GFX_GL_Texture_LoadFromBackBuffer(GFX_GL_TEXTURE *const texture) { assert(texture != NULL); + assert(texture->initialized); GFX_GL_Texture_Bind(texture); diff --git a/src/libtrx/gfx/gl/vertex_array.c b/src/libtrx/gfx/gl/vertex_array.c index 6f8903968..461ca531d 100644 --- a/src/libtrx/gfx/gl/vertex_array.c +++ b/src/libtrx/gfx/gl/vertex_array.c @@ -7,21 +7,26 @@ void GFX_GL_VertexArray_Init(GFX_GL_VERTEX_ARRAY *array) { - assert(array); + assert(array != NULL); glGenVertexArrays(1, &array->id); GFX_GL_CheckError(); + array->initialized = true; } void GFX_GL_VertexArray_Close(GFX_GL_VERTEX_ARRAY *array) { - assert(array); - glDeleteVertexArrays(1, &array->id); - GFX_GL_CheckError(); + assert(array != NULL); + if (array->initialized) { + glDeleteVertexArrays(1, &array->id); + GFX_GL_CheckError(); + } + array->initialized = false; } void GFX_GL_VertexArray_Bind(GFX_GL_VERTEX_ARRAY *array) { - assert(array); + assert(array != NULL); + assert(array->initialized); glBindVertexArray(array->id); GFX_GL_CheckError(); } @@ -30,7 +35,8 @@ void GFX_GL_VertexArray_Attribute( GFX_GL_VERTEX_ARRAY *array, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLsizei offset) { - assert(array); + assert(array != NULL); + assert(array->initialized); glEnableVertexAttribArray(index); GFX_GL_CheckError(); diff --git a/src/libtrx/include/libtrx/gfx/gl/buffer.h b/src/libtrx/include/libtrx/gfx/gl/buffer.h index 99f8f68c2..d3711cd74 100644 --- a/src/libtrx/include/libtrx/gfx/gl/buffer.h +++ b/src/libtrx/include/libtrx/gfx/gl/buffer.h @@ -2,7 +2,10 @@ #include "gl_core_3_3.h" +#include + typedef struct { + bool initialized; GLuint id; GLenum target; } GFX_GL_BUFFER; diff --git a/src/libtrx/include/libtrx/gfx/gl/program.h b/src/libtrx/include/libtrx/gfx/gl/program.h index 427a8bb4d..0ab22dae7 100644 --- a/src/libtrx/include/libtrx/gfx/gl/program.h +++ b/src/libtrx/include/libtrx/gfx/gl/program.h @@ -6,6 +6,7 @@ #include typedef struct { + bool initialized; GLuint id; } GFX_GL_PROGRAM; diff --git a/src/libtrx/include/libtrx/gfx/gl/sampler.h b/src/libtrx/include/libtrx/gfx/gl/sampler.h index b1bae2ae1..e45e6c29a 100644 --- a/src/libtrx/include/libtrx/gfx/gl/sampler.h +++ b/src/libtrx/include/libtrx/gfx/gl/sampler.h @@ -2,7 +2,10 @@ #include "../gl/gl_core_3_3.h" +#include + typedef struct { + bool initialized; GLuint id; } GFX_GL_SAMPLER; diff --git a/src/libtrx/include/libtrx/gfx/gl/texture.h b/src/libtrx/include/libtrx/gfx/gl/texture.h index 96b7bc34e..99d7b1543 100644 --- a/src/libtrx/include/libtrx/gfx/gl/texture.h +++ b/src/libtrx/include/libtrx/gfx/gl/texture.h @@ -2,7 +2,10 @@ #include "../gl/gl_core_3_3.h" +#include + typedef struct { + bool initialized; GLuint id; GLenum target; } GFX_GL_TEXTURE; diff --git a/src/libtrx/include/libtrx/gfx/gl/vertex_array.h b/src/libtrx/include/libtrx/gfx/gl/vertex_array.h index 01615f1fc..e25b26481 100644 --- a/src/libtrx/include/libtrx/gfx/gl/vertex_array.h +++ b/src/libtrx/include/libtrx/gfx/gl/vertex_array.h @@ -2,7 +2,10 @@ #include "../gl/gl_core_3_3.h" +#include + typedef struct { + bool initialized; GLuint id; } GFX_GL_VERTEX_ARRAY;