[Lazarus] Library function trashing object (was: SIGSEGV when trying to use a TCustomControl)

Leonardo M. Ramé l.rame at griensu.com
Fri Apr 19 19:18:14 CEST 2013


I'm using a C++ library with a function that receives a parameter this
way:

int getData(void * &buffer, unsigned long &bufSize){
  bufSize = 10;
  return 1;
}

The Pascal definition I'm using is this:

function (var buffer: pointer; var bufsize: longword): Integer; cdecl;

I'm using this library without any issue in a couple of programs, but in
this new program, after the "bufSize" variable is assigned (inside the
library) an object of my Lazarus program is trashed. Weird.

The instance of my object (an very simple TCustomControl descendant) is
declared in a TForm class, as FMyControl: TMyControl, then created an
instance in TForm's constructor. In another method of TForm, I call the
library's function then I try to use a method of FMyControl, but it
gives a SigSegv.

Example:

procedure TForm1.doSomething;
var
  lBuffer: PWord;
  lBufSize: longword;
begin
  lBuffer := nil;
  lBufSize := 0;
  FMyControl.call_some_method; // FMyControl has debugging info.
  getData(lBuffer, lBufSize);
  FMyControl.call_some_method; // FMyControl "cannot access memory address...SIGSEGV"
end;

I can modify the C++ function if needed. Am I incorrectly declaring the
function params?. Why is FMyControl's memory position trashed?.

Regards,
-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com




More information about the Lazarus mailing list