Skip to content

Commit 3d2a64a

Browse files
committed
fix: improve frame wrapping logic and error handling in rendering code
- Updated error message in FS_OpenFileInPak to include a newline for better readability. - Added checks for valid frame counts in animation and mesh rendering functions across OpenGL and Vulkan implementations to prevent division by zero errors. - Refactored frame wrapping logic to use a local variable for clarity and performance.
1 parent c749083 commit 3d2a64a

9 files changed

Lines changed: 34 additions & 13 deletions

File tree

src/qcommon/files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ static int FS_OpenFileInPak( fileHandle_t *file, pack_t *pak, fileInPack_t *pakF
15701570
// open a new file on the pakfile
15711571
temp = unzReOpen( pak->pakFilename, pak->handle );
15721572
if ( temp == NULL ) {
1573-
Com_Printf( S_COLOR_RED "Couldn't reopen %s", pak->pakFilename );
1573+
Com_Printf( S_COLOR_RED "Couldn't reopen %s\n", pak->pakFilename );
15741574
*file = FS_INVALID_HANDLE;
15751575
return -1;
15761576
}

src/renderers/opengl/tr_animation.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,15 @@ void R_MDRAddAnimSurfaces( trRefEntity_t *ent ) {
191191

192192
personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && (tr.viewParms.portalView == PV_NONE);
193193

194+
if ( !header || header->numFrames < 1 ) {
195+
return;
196+
}
197+
194198
if ( ent->e.renderfx & RF_WRAP_FRAMES )
195199
{
196-
ent->e.frame %= header->numFrames;
197-
ent->e.oldframe %= header->numFrames;
200+
const int nf = (int)header->numFrames;
201+
ent->e.frame %= nf;
202+
ent->e.oldframe %= nf;
198203
}
199204

200205
//

src/renderers/opengl/tr_mesh.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,14 @@ void R_AddMD3Surfaces( trRefEntity_t *ent ) {
300300
// don't add third_person objects if not in a portal
301301
personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && (tr.viewParms.portalView == PV_NONE);
302302

303+
if ( !tr.currentModel->md3[0] || tr.currentModel->md3[0]->numFrames < 1 ) {
304+
return;
305+
}
306+
303307
if ( ent->e.renderfx & RF_WRAP_FRAMES ) {
304-
ent->e.frame %= tr.currentModel->md3[0]->numFrames;
305-
ent->e.oldframe %= tr.currentModel->md3[0]->numFrames;
308+
const int nf = tr.currentModel->md3[0]->numFrames;
309+
ent->e.frame %= nf;
310+
ent->e.oldframe %= nf;
306311
}
307312

308313
//

src/renderers/opengl/tr_model_iqm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ void R_AddIQMSurfaces( trRefEntity_t *ent ) {
10731073
// don't add third_person objects if not in a portal
10741074
personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && (tr.viewParms.portalView == PV_NONE);
10751075

1076-
if ( ent->e.renderfx & RF_WRAP_FRAMES ) {
1076+
if ( ent->e.renderfx & RF_WRAP_FRAMES && data->num_frames > 0 ) {
10771077
ent->e.frame %= data->num_frames;
10781078
ent->e.oldframe %= data->num_frames;
10791079
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
glslang_validator_path=/usr/bin/glslangValidator
22
glslang_validator_version=Glslang Version: 11:16.2.0
3-
generated_at=2026-04-27T03:13:41Z
3+
generated_at=2026-04-27T05:04:11Z
44
shader_data_sha256=b6c7f805a5810cddfd7365a786824d42ea896f25f1d35c3ec412e157eaeee493
55
shader_binding_sha256=960921d52493ab4fcf2f8b60edb34fa0b64a852c47b5ad2ae3abdf06c35ebe4a

src/renderers/vulkan/tr_animation.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,15 @@ void R_MDRAddAnimSurfaces( trRefEntity_t *ent ) {
192192

193193
personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && (tr.viewParms.portalView == PV_NONE);
194194

195+
if ( !header || header->numFrames < 1 ) {
196+
return;
197+
}
198+
195199
if ( ent->e.renderfx & RF_WRAP_FRAMES )
196200
{
197-
ent->e.frame %= header->numFrames;
198-
ent->e.oldframe %= header->numFrames;
201+
const int nf = (int)header->numFrames;
202+
ent->e.frame %= nf;
203+
ent->e.oldframe %= nf;
199204
}
200205

201206
//

src/renderers/vulkan/tr_mesh.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,14 @@ void R_AddMD3Surfaces( trRefEntity_t *ent ) {
300300
// don't add third_person objects if not in a portal
301301
personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && (tr.viewParms.portalView == PV_NONE);
302302

303+
if ( !tr.currentModel->md3[0] || tr.currentModel->md3[0]->numFrames < 1 ) {
304+
return;
305+
}
306+
303307
if ( ent->e.renderfx & RF_WRAP_FRAMES ) {
304-
ent->e.frame %= tr.currentModel->md3[0]->numFrames;
305-
ent->e.oldframe %= tr.currentModel->md3[0]->numFrames;
308+
const int nf = tr.currentModel->md3[0]->numFrames;
309+
ent->e.frame %= nf;
310+
ent->e.oldframe %= nf;
306311
}
307312

308313
//

src/renderers/vulkan/tr_model_iqm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ void R_AddIQMSurfaces( trRefEntity_t *ent ) {
15621562
// don't add third_person objects if not in a portal
15631563
personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && (tr.viewParms.portalView == PV_NONE);
15641564

1565-
if ( ent->e.renderfx & RF_WRAP_FRAMES ) {
1565+
if ( ent->e.renderfx & RF_WRAP_FRAMES && data->num_frames > 0 ) {
15661566
ent->e.frame %= data->num_frames;
15671567
ent->e.oldframe %= data->num_frames;
15681568
}

src/renderers/vulkan/vk_instance.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ static qboolean vk_create_device( VkPhysicalDevice physical_device, int device_i
188188
VkPhysicalDevice8BitStorageFeatures storage_8bit_features;
189189
#endif
190190
VkPhysicalDeviceMeshShaderFeaturesNV mesh_shader_features_nv;
191+
/* Must survive until qvkCreateDevice (do not declare inside a narrow if-block). */
192+
VkPhysicalDeviceHostQueryResetFeatures host_query;
191193

192194
ri.Printf( PRINT_ALL, "...selected physical device: %i\n", device_index );
193195

@@ -681,7 +683,6 @@ static qboolean vk_create_device( VkPhysicalDevice physical_device, int device_i
681683
}
682684
#endif
683685
if ( hostQueryReset ) {
684-
VkPhysicalDeviceHostQueryResetFeatures host_query;
685686
const void *prev_next = device_desc.pNext;
686687
Com_Memset( &host_query, 0, sizeof( host_query ) );
687688
host_query.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES;

0 commit comments

Comments
 (0)