Re: [AD] tiny seekmidi fix

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


(sorry for double sending privatly, I got cought by the list
configuration again)

On Thu, 2002-08-15 at 22:34, Eric Botcazou wrote:
> > > There's a small bug in seekmidi, for some .mid files midi_pos will wrap
> > > around to the negative length inside the loop when passing an argument
> > > bigger than the length, causing an endless loop. My patch fixes it.
> >
> > Looks fine.
> 
> Err... I answered too quickly :-(
> 
> Elias, did you investigate the cascading effects of the bug ? For example,
> line 1365, midi_pos is again tested against -1. Thanks in advance.
> 

Oops, no, didn't see it. It seems to be the only cascading effect
though. My modification to exmidi.c only uses seekmidi to find the
length of the MIDI, then restarts it, so I didn't notice anything. I
attach a new patch, because this means also allegro._tx needed to be
modified.

--
Elias Pschernig

Index: src/midi.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/midi.c,v
retrieving revision 1.14
diff -u -r1.14 midi.c
--- src/midi.c	21 Mar 2002 09:33:45 -0000	1.14
+++ src/midi.c	16 Aug 2002 06:13:57 -0000
@@ -1341,7 +1341,7 @@
       prepare_to_play(midifile);
 
    /* now sit back and let midi_player get to the position */
-   while ((midi_pos < target) && (midi_pos != -1)) {
+   while ((midi_pos < target) && (midi_pos >= 0)) {
       int mmpc = midi_pos_counter;
       int mmp = midi_pos;
 
@@ -1362,7 +1362,7 @@
    midi_driver = old_driver;
    midi_seeking = 0;
 
-   if (midi_pos != -1) {
+   if (midi_pos >= 0) {
       /* refresh the driver with any changed parameters */
       if (midi_driver->raw_midi) {
 	 for (c=0; c<16; c++) {
Index: docs/src/allegro._tx
===================================================================
RCS file: /cvsroot/alleg/allegro/docs/src/allegro._tx,v
retrieving revision 1.69
diff -u -r1.69 allegro._tx
--- docs/src/allegro._tx	14 Aug 2002 19:36:15 -0000	1.69
+++ docs/src/allegro._tx	16 Aug 2002 06:14:29 -0000
@@ -5498,8 +5498,8 @@
    beginning; otherwise it seeks from the current position. Returns zero if 
    successful, non-zero if it hit the end of the file (1 means it stopped 
    playing, 2 means it looped back to the start). If this function stops 
-   because it reached EOF, midi_pos will be set to the negative length of 
-   the MIDI file.
+   because it reached EOF, and no looping is in effect, midi_pos will be
+   set to the negative length of the MIDI file.
 
 @@void @midi_out(unsigned char *data, int length);
 @xref install_sound, load_midi_patches, midi_recorder


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/