Discussion:
[fpc-pascal] Random crashes in i386-macosx in PasCocoa
Felipe Monteiro de Carvalho
2008-09-29 11:44:02 UTC
Permalink
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
Felipe Monteiro de Carvalho
2008-09-29 13:37:06 UTC
Permalink
I have commented the code to the point where nothing is different from
similar projects, but the crash remains ... it's almost like Mac OS X
doesn't like my project, or it stored somewhere that this one won't be
allowed to run =) I even deleted the entire directory structure and
got fresh files from subversion, but still doesn't work =/
--
Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho
2008-09-29 13:39:49 UTC
Permalink
wow! Changing the bundle name the stacktrace of the crash changes!

Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_INVALID_ADDRESS (0x0001) at 0x40d42008

Thread 0 Crashed:
0 libobjc.A.dylib 0x90a5dc7e _cache_flush + 71
1 libobjc.A.dylib 0x90a5db04 flush_caches + 254
2 org.magnifier.magnifier 0x00039eda
FOUNDATION_NSOBJECT_$__ADDMETHOD$ANSISTRING$ANSISTRING$POINTER + 170
3 org.magnifier.magnifier 0x000413c1
CONTROLLER_TMYCONTROLLER_$__ADDMETHODS + 65
4 org.magnifier.magnifier 0x00039bce
FOUNDATION_NSOBJECT_$__CREATE$$NSOBJECT + 190
5 org.magnifier.magnifier 0x000415b7
CONTROLLER_TMYCONTROLLER_$__CREATE$$TMYCONTROLLER + 311
6 org.magnifier.magnifier 0x0000214b PASCALMAIN + 91
7 org.magnifier.magnifier 0x0001be75
SYSTEM_FPC_SYSTEMMAIN$LONGINT$PPCHAR$PPCHAR + 69
8 org.magnifier.magnifier 0x000020d2 start + 258
9 org.magnifier.magnifier 0x00001ff9 start + 41

Now I am getting somewhere....

It was really unhappy with the previous texteditor.app name (I had
even restarted the system to check if it was holding some kind of
info).
--
Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho
2008-09-29 13:44:30 UTC
Permalink
nope ... went back to the previous crash
--
Felipe Monteiro de Carvalho
Loading...