Recent

Author Topic: A strange problem  (Read 2971 times)

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 724
A strange problem
« on: March 05, 2013, 07:31:11 pm »
I have a unit that looks like this:

========================================
Unit WaveinSupport;

Interface

Uses Windows, MMSystem, SysUtils;

Const MAX_BUFFERS = 2;

  TWaveIn = class(TObject)
    Constructor Create(newFormHandle:HWnd; BfSize, newTotalBuffers : Integer);
    Destructor  Destroy;      Override;

    private
      pvpWaveHeader: Array [0..MAX_BUFFERS] of PWAVEHDR;

     ...

========================================

In the body of the code, the only reference to pvpWaveHeader looks like this:

for index = 0 to 1 do pvpWaveHeader [index] := ...

The upper limit on index here is always 1 regardless of the value of MAX_BUFFERS.

With the constant MAX_BUFFERS = 2, this unit works fine.  But if I change it to MAX_BUFFERS = 1, I get an error

'External: SIGSEGV', at address 72D245EC

I realize this is a very limited description of the problem, but does anyone have any idea what might be going on here?  I'm using Lazarus 1.0.2 with FPC 2.6.0 under Windows XP.



Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: A strange problem
« Reply #1 on: March 05, 2013, 07:39:13 pm »
Indexing seems to be OK here.
What is the "PWAVEHDR"?
Is is object? --> Is created?
OR
Is it a pointer to memory? --> Is the memory allocated (getmem)?

EDIT: You can use View -> Debug Windows -> Call Stack
It will help you to track the bug.
« Last Edit: March 05, 2013, 07:41:43 pm by Blaazen »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 724
Re: A strange problem
« Reply #2 on: March 05, 2013, 08:01:59 pm »
Hello Blaazen.

PWAVEHDR is a pointer to a record defined in MMSYSTEM.   pvpWaveHeader is an array of PWAVEHDR pointers.

In my code with MAX_BUFFERS = 1, I allocate memory for pvpWaveHeader[0] and pvpWaveHeader[1] with no problem.  The error occurs when I try to access pvpWaveHeader[1] later in my code. 

Let me try to write a short application that demonstrates the problem -- if I can re-create it that way  :).

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: A strange problem
« Reply #3 on: March 06, 2013, 05:32:00 am »
Code: [Select]
Const MAX_BUFFERS = 2;
...
pvpWaveHeader: Array [0..MAX_BUFFERS] of PWAVEHDR;
I hope you do realize, that here pvpWaveHeader has length of 3. It has indexes 0, 1, 2. Maybe you meant to write it like:
Code: [Select]
[0..MAX_BUFFERS-1]
Pascal array indexing is different from C. This:
Code: [Select]
pvpWaveHeader: Array [10..11] of PWAVEHDR;would mean that pvpWaveHeader has indexes 10 and 11. Not that it starts from 10 and has 11 starting from it.
« Last Edit: March 06, 2013, 05:35:17 am by User137 »

 

TinyPortal © 2005-2018