Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   EAccessViolation mit Codeoptimierung (https://www.delphipraxis.net/56869-eaccessviolation-mit-codeoptimierung.html)

turboPASCAL 12. Nov 2005 15:03


EAccessViolation mit Codeoptimierung
 
Delphi-Quellcode:
type
  FSOUND_SAMPLE = record

    buff: Punsignedchar;               // pointer to sound data
    ...
  end;
  PFSOUND_SAMPLE = ^FSOUND_SAMPLE;

  FSOUND_CHANNEL = record
    index: int;                        // position in channel pool.
    volume: int;                       // current volume (00-FFh).
    frequency: int;                    // speed or rate of playback in hz.
    pan: int;                          // panning value (00-FFh).
    actualvolume: int;                 // driver level current volume.
    actualpan: int;                    // driver level panning value.
    sampleoffset: unsignedint;         // sample offset (sample starts playing from here).

    sptr: PFSOUND_SAMPLE;              // currently playing sample

    ...
  end;

  PFSOUND_CHANNEL = ^FSOUND_CHANNEL;


procedure...
...
  asm
        push   ebp
        mov   ebx, mix_mixptr
        mov   mix_mixbuffptr, ebx

        mov   ecx, cptr
        mov   mix_cptr, ecx

        cmp   ecx, 0                         // if (!cptr) ...
        je   @MixExit                      //   ... then skip this channel!

>>>--> mov   ebx, [ecx+FSOUND_CHANNEL.sptr] // load the correct SAMPLE pointer
                                               // for this channel

        mov   mix_sptr, ebx                 // store sample pointer away
        cmp   ebx, 0                         // if (!sptr) ...
        je   @MixExit                      //   ... then skip this channel!

        // get pointer to sample buffer
        mov   eax, [ebx+FSOUND_SAMPLE.buff]
        mov   mix_samplebuff, eax
...
Wieso kommt hier eine EAccessViolation ? Wenn ich in den Optionen vom Compiler die Codeoptimierung abschalte {$O-} gibt es keine Probleme.

Muetze1 13. Nov 2005 07:38

Re: EAccessViolation mit Codeoptimierung
 
Grundsätzlich: Register sichern! Die in der Hilfe angegebenen frei zu verwendeten CPU Register sind bei eingeschalteter Optimierung hinfällig. Daher sind alle als "nicht veränderbar" zu betrachten. Daher debugge auch mal, ob alle deine Variablen richtig referenziert werden und du somit auf das richtige zugreifst. Auch musst du unbedingt das Directionflag wieder herstellen, wenn du es veränderst!

turboPASCAL 13. Nov 2005 09:29

Re: EAccessViolation mit Codeoptimierung
 
Moin,

:gruebel: aha, die CPU Register sind bei eingeschalteter Optimierung hinfällig. Das heisst wohl dass der Compiler bei dem Optimieren möglicherweise die Register ändert oder ersetzt ?.

Leider habe ich nicht genug Kenntnisse von der Materie Assembler. Die Hilfe hilft mir nicht wirklich, da ich nur die PE-Version besitze.

Könntest du (und oder auch die anderen ;) ) mir zeigen wie das gemacht werden muss ?


Zitat:

Zitat von Die Delphi 6 - Hilfe (F1)
Delphi führt keine »unsicheren« Optimierungen durch, die die Aufmerksamkeit des Programmierers auf die Probe stellen.

:mrgreen:

Muetze1 13. Nov 2005 09:45

Re: EAccessViolation mit Codeoptimierung
 
Zitat:

Zitat von turboPASCAL
aha, die CPU Register sind bei eingeschalteter Optimierung hinfällig. Das heisst wohl dass der Compiler bei dem Optimieren möglicherweise die Register ändert oder ersetzt ?.

Genau das meinte ich.

turboPASCAL 13. Nov 2005 10:00

Re: EAccessViolation mit Codeoptimierung
 
Wie kann man das jetzt ändern ?
Delphi-Quellcode:
var
  cptr: PFSOUND_CHANNEL;

procedure FSOUND_Mixer_FPU_Ramp(mixptr: Pointer; len: int; returnaddress: char);
var
  count: int;
begin

  //   static FSOUND_CHANNEL *cptr;
  //   static int count;
   // IMPORTANT no local variables on stack.. we are trashing EBP. static puts values on heap.

  if (len <= 0) then
    exit;

  mix_numsamples := len;
  mix_mixptr := unsignedint(mixptr);
  mix_mixbuffend := mix_mixptr + (mix_numsamples shl 3);

  //==============================================================================================
  // LOOP THROUGH CHANNELS
  //==============================================================================================

  for count := 0 to 64 - 1 do
  begin
    cptr := @_FSOUND_Channel[count];

    asm

      push   ebp
      mov      ebx, mix_mixptr
      mov      mix_mixbuffptr, ebx

      mov      ecx, cptr
      mov      mix_cptr, ecx

      cmp      ecx, 0      // if (!cptr) ...
      je      @MixExit   //  ... then skip this channel!

      mov      ebx, [ecx+FSOUND_CHANNEL.sptr]   // load the correct SAMPLE pointer for this channel
      mov      mix_sptr, ebx   // store sample pointer away
      cmp      ebx, 0      // if (!sptr) ...
      je      @MixExit   //     ... then skip this channel!

      // get pointer to sample buffer
      mov      eax, [ebx+FSOUND_SAMPLE.buff]
      mov      mix_samplebuff, eax
Delphi-Quellcode:
mov   ebx, [ecx+FSOUND_CHANNEL.sptr]
Ist möglicherweise unsicher. Das heisst mann müsste das so machen: (nicht lachen bitte)

Delphi-Quellcode:
add   ecx, FSOUND_CHANNEL.sptr
mov   ebx, [ecx]
PS.: das Programm ist nicht von mir.

turboPASCAL 13. Nov 2005 16:58

Re: EAccessViolation mit Codeoptimierung
 
Delphi-Quellcode:
add   ecx, FSOUND_CHANNEL.sptr
mov   ebx, [ecx]
Habe ich mal versucht, aber dann haut der Sound nicht hin, aber es klappt mit der Optimierung. :gruebel:


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:29 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz