Mail Archives: djgpp/1999/09/09/03:43:12
Why this program receives SIGSEGV?
typedef struct SNDSTRUC_typ
{
unsigned short sound;
unsigned short sndlen;
short *IsPlaying;
short frequency;
} SNDSTRUC, *SNDSTRUC_PTR;
typedef struct sound_typ
{
unsigned char *buffer;
short status;
SNDSTRUC SS;
} ssound, *ssound_ptr;
int main(void)
{
......
Load_Sound(..............);
.......
return 0;
}
int Sound_Load(char *filename, ssound_ptr the_sound, int translate)
{
......
......
int *selector;
..........
if(_dos_open(filename, _O_RDONLY, &sound_handle)) { OK
printf("file not found");
return 1;
}
size_of_file = filelength(sound_handle);
tmp_ptr = s_ptr =
(unsigned char*)__dpmi_allocate_dos_memory((size_of_file+15) >> 4,
selector); OK
do { OK
_dos_read(sound_handle, temp_ptr, 0x4000, &bytes_read);
// update pointer
temp_ptr += bytes_read;
} while (bytes_read == 0x4000);
// fechar ficheiro OK
_dos_close(sound_handle);
header_length = s_ptr[20]; OK
the_sound->buffer = s_ptr; OK
// set SNDSTRUC for DIGPAK - OK
the_sound->SS.sound = (unsigned short)(s_ptr + header_length + 4);
the_sound->SS.sndlen = (unsigned short)(size_of_file -
header_length);
the_sound->SS.IsPlaying = (short *)(&the_sound->status);
the_sound->SS.frequency = (short) ( (long)(-1000000) /
((int)s_ptr[header_length+4]-256));
return 0; OK
} // fim da funcao Sound_Load <---- ABORT: SIGSEGV!!!
( from "The Black Art of 3D Programming", Andre LaMothe)
Thanks in advance
Aperes
- Raw text -