Skip to content

Commit

Permalink
Fix xm_get_number_of_rows() for undefined patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
Artefact2 committed Dec 28, 2021
1 parent 68bd967 commit 94b5121
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ uint16_t xm_get_number_of_patterns(xm_context_t* ctx) {
}

uint16_t xm_get_number_of_rows(xm_context_t* ctx, uint16_t pattern) {
return ctx->module.patterns[pattern].num_rows;
if(pattern < ctx->module.num_patterns)
return ctx->module.patterns[pattern].num_rows;
return DEFAULT_PATTERN_LENGTH;
}

uint16_t xm_get_number_of_instruments(xm_context_t* ctx) {
Expand Down
2 changes: 1 addition & 1 deletion src/play.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ static void xm_row(xm_context_t* ctx) {
* is still necessary to go the next
* pattern. */
if(!ctx->position_jump && !ctx->pattern_break &&
(ctx->current_row >= (cur ? cur->num_rows : 64) || ctx->current_row == 0)) {
(ctx->current_row >= (cur ? cur->num_rows : DEFAULT_PATTERN_LENGTH) || ctx->current_row == 0)) {
ctx->current_table_index++;
ctx->current_row = ctx->jump_row; /* This will be 0 most of
* the time, except when E60
Expand Down
1 change: 1 addition & 0 deletions src/xm_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern int __fail[-1];
#define NUM_NOTES 96
#define NUM_ENVELOPE_POINTS 12
#define MAX_NUM_ROWS 256
#define DEFAULT_PATTERN_LENGTH 64

#if XM_RAMPING
#define XM_SAMPLE_RAMPING_POINTS 0x20
Expand Down

0 comments on commit 94b5121

Please sign in to comment.