Einzelnen Beitrag anzeigen

roboter202

Registriert seit: 6. Mär 2011
98 Beiträge
 
Delphi 6 Professional
 
#1

OpenAl header + MemLeak

  Alt 17. Mai 2012, 13:42
Hallo,

Ich hatte in meinen Programm einige Speicherlecks und hab das dann einmal mit MemCheck geprüft. Konnte dann auch alles fixen bis auf einen Fehler.

Hier mal der Log file:

Code:
MemCheck version 2.75

TOP 10 Leaks: begin
Leak #0 User allocated memory (GetMem)
   Size: 4
   2 Occurences
   call stack - 0 : Module OpenAL.pas Routine @Openal@LoadWavStream Line 2243 Find error: 00481E48
   call stack - 1 : Module OpenAL.pas Routine @Openal@alutLoadWAVFile Line 2282 Find error: 00482012
   call stack - 2 : Module USoundHelper.pas Routine @Usoundhelper@TSoundHelper@loadSoundFromFile Line 58 Find error: 0048A7D1
   call stack - 3 : Module UGui.pas Routine @Ugui@TGui@Init Line 116 Find error: 0048B072
   call stack - 4 : Module UWnd.pas Routine @Uwnd@TWnd@InitGame Line 149 Find error: 0048FE9A
   call stack - 5 : Module UWnd.pas Routine @Uwnd@TWnd@FormCreate Line 285 Find error: 004905F8
   call stack - 6 : Routine @Forms@TCustomForm@DoCreate Find error: 0044D8FF
   call stack - 7 : Routine @Forms@TCustomForm@AfterConstruction Find error: 0044D5EB
   call stack - 8 : Routine @Forms@TApplication@CreateForm Find error: 00454A34
   call stack - 9 : Module Maze.dpr Routine initialization Line 18 Find error: 00495F25
   call stack - 10 : (no debug info) Find error: 7C817073
   call stack - 11 : (no debug info) Find error: FFFFFFFC

TOP 10 Leaks: end

Total leak: 8 bytes


*** MEMCHK: Blocks STILL allocated ***

Leak #0 User allocated memory (GetMem)
   Size: 4
   2 Occurences
   call stack - 0 : Module OpenAL.pas Routine @Openal@LoadWavStream Line 2243 Find error: 00481E48
   call stack - 1 : Module OpenAL.pas Routine @Openal@alutLoadWAVFile Line 2282 Find error: 00482012
   call stack - 2 : Module USoundHelper.pas Routine @Usoundhelper@TSoundHelper@loadSoundFromFile Line 58 Find error: 0048A7D1
   call stack - 3 : Module UGui.pas Routine @Ugui@TGui@Init Line 116 Find error: 0048B072
   call stack - 4 : Module UWnd.pas Routine @Uwnd@TWnd@InitGame Line 149 Find error: 0048FE9A
   call stack - 5 : Module UWnd.pas Routine @Uwnd@TWnd@FormCreate Line 285 Find error: 004905F8
   call stack - 6 : Routine @Forms@TCustomForm@DoCreate Find error: 0044D8FF
   call stack - 7 : Routine @Forms@TCustomForm@AfterConstruction Find error: 0044D5EB
   call stack - 8 : Routine @Forms@TApplication@CreateForm Find error: 00454A34
   call stack - 9 : Module Maze.dpr Routine initialization Line 18 Find error: 00495F25
   call stack - 10 : (no debug info) Find error: 7C817073
   call stack - 11 : (no debug info) Find error: FFFFFFFC

*** MEMCHK: End of allocated blocks ***


*** MEMCHK: Chronological leak information ***

* User allocated memory (GetMem) (Leak #0) Size: 4
* User allocated memory (GetMem) (Leak #0) Size: 4

*** MEMCHK: End of chronological leak information ***


*** MEMCHK: Blocks written to after destruction ***

   Bad blocks count: 0


*** MEMCHK: End of blocks written to after destruction ***
Wenn ich das nun richtig verstehe entsteht der Fehler hier
@Openal@LoadWavStream Line 2243
Und setzt sich dann über alle Methoden fort, die diese Aufrufen.
Nun ist der OpenAL header ja nicht von mir.
Den hab ich nämlich hier: http://www.noeska.com/doal/downloads.aspx her.

In @Usoundhelper@TSoundHelper@loadSoundFromFile Line 58 lade ich eine WAV-Datei in einen Buffer:

Delphi-Quellcode:
function TSoundHelper.loadSoundFromFile(f: String): Integer;
var
  format: TALEnum;
  size: TALSizei;
  freq: TALSizei;
  loop: TALInt;
  data: TALVoid;
begin
  setLength(sounds, length(sounds) +1);
  result := high(sounds);
  try
    AlGenBuffers(1, @sounds[result]);
    AlutLoadWAVFile(f, format, data, size, freq, loop);
    AlBufferData(sounds[result], format, data, size, freq);
  finally
    AlutUnloadWav(format, data, size, freq);
  end;
Alles streng nach Tutorial. http://www.noeska.com/doal/lesson1.aspx

Nun, wie werde ich das Speicherleck los? Oder geht das nicht weil die OpenAL.pas fhelerhaft ist.

hier mal die Zeilen in der openal.pas wo der Fehler auftritt.

Delphi-Quellcode:
function LoadWavStream(Stream: Tstream; var format: TALenum; var data: TALvoid; var size: TALsizei; var freq: TALsizei; var loop: TALint): Boolean;
var
  WavHeader: TWavHeader;
  readname: pansichar;
  name: ansistring;
  readint: integer;
begin
    Result:=False;

    //Read wav header
    stream.Read(WavHeader, sizeof(TWavHeader));

    //Determine SampleRate
    freq:=WavHeader.SampleRate;

    //Detemine waveformat
    if WavHeader.ChannelNumber = 1 then
    case WavHeader.BitsPerSample of
    8: format := AL_FORMAT_MONO8;
    16: format := AL_FORMAT_MONO16;
    end;

    if WavHeader.ChannelNumber = 2 then
    case WavHeader.BitsPerSample of
    8: format := AL_FORMAT_STEREO8;
    16: format := AL_FORMAT_STEREO16;
    end;

    //go to end of wavheader
    stream.seek((8-44)+12+4+WavHeader.FormatHeaderSize+4,soFromCurrent); //hmm crappy...

    //loop to rest of wave file data chunks
    repeat
      //read chunk name
      getmem(readname,4); //HIER TRITT DER FEHLER AUF !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      stream.Read(readname^, 4);
      name:=readname[0]+readname[1]+readname[2]+readname[3];
      if name='datathen
      begin
        //Get the size of the wave data
        stream.Read(readint,4);
        size:=readint;
        //if WavHeader.BitsPerSample = 8 then size:=size+1; //fix for 8bit???
        //Read the actual wave data
        getmem(data,size);
        stream.Read(Data^, size);

        //Decode wave data if needed
        if WavHeader.FormatCode=WAV_IMA_ADPCM then
        begin
          //TODO: add code to decompress IMA ADPCM data
        end;
        if WavHeader.FormatCode=WAV_MP3 then
        begin
          //TODO: add code to decompress MP3 data
        end;
        Result:=True;
      end
      else
      begin
        //Skip unknown chunk(s)
        stream.Read(readint,4);
        stream.Position:=stream.Position+readint;
      end;
    until stream.Position>=stream.size;

end;
Gruß roboter202
Christian
i := 0 ; While i = 0 do beep ;
  Mit Zitat antworten Zitat