[fpc-pascal] Random crashes in i386-macosx in PasCocoa

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Mon Sep 29 13:44:02 CEST 2008


Hello,

I am getting a very strange crash, in a place of my code which never
hat problems before. The exact same code works in another PasCocoa
example, and even the same code worked before! Sometimes the
application won't crash, but most times it will. Here is my code (also
available in the lazarus-ccr subversion in
lazarus-ccr/bindings/pascocoa/examples/texteditor

Any ideas? I am really lost at what could cause such behavior. I am
using fpc 2.2.2 in Mac OS X 10.4
var
  pool: NSAutoreleasePool;
begin
  { Avoids arithmetic exceptions in Objective-C code }

  SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
exOverflow, exUnderflow, exPrecision]); // doesn't matter if I comment
this

  {  Creates the AutoreleasePool }
  pool := NSAutoreleasePool.Create;

  { Creates the application NSApp object }
  NSApp := NSApplication.sharedApplication;

  { Initializes the controller, view and model objects }

  myController := TMyController.Create(); // Enters here
 ...

constructor TMyController.Create;
begin
  { The class is registered on the Objective-C runtime before the
NSObject constructor is called }
  if not CreateClassDefinition(ClassName(), Str_NSObject) then
WriteLn('Failed to create objc class ' + ClassName());

  inherited Create; // Enters here

  { Create objects }

  OpenPanel := NSOpenPanel.openPanel;
  SavePanel := NSSavePanel.savePanel;
end;

constructor NSObject.Create;
begin
  ClassId := getClass();
  allocbuf := objc_msgSend(ClassId,
sel_registerName(PChar(Str_alloc)), []); // Crashes here
  Handle := objc_msgSend(allocbuf, sel_registerName(PChar(Str_init)), []);

  { Adds custom methods, if any }
  AddMethods();
end;


Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000007
0x90a594c7 in objc_msgSend ()
(gdb) bt
#0  0x90a594c7 in objc_msgSend ()
#1  0x000f7294 in U_SYSTEM_RETURNNILIFGROWHEAPFAILS ()
#2  0x0004629e in TMYCONTROLLER__CREATE (vmt=0xdf8f4, this=0x41d190)
at controller.pas:77
#3  0x00002788 in PASCALMAIN () at texteditor.pas:38
#4  0x0001c555 in SYSTEM_FPC_SYSTEMMAIN$LONGINT$PPCHAR$PPCHAR ()
#5  0x00002702 in _start ()
#6  0x00002629 in start ()

thanks,
-- 
Felipe Monteiro de Carvalho



More information about the fpc-pascal mailing list