Crash in [[NSString alloc] initWithCString:msg]
Crash in [[NSString alloc] initWithCString:msg]
- Subject: Crash in [[NSString alloc] initWithCString:msg]
- From: JoanBa <email@hidden>
- Date: Fri, 9 Apr 2004 18:34:50 +0200
Hi,
I'm having a problem with Cocoa... I'm using a GUI created with Xcode +
Interface Builder, this GUI, which corresponds to class FlyController,
has a NSTextView object which I use as a console. I want to redirect to
this view all messages generated from the different threads of my app,
so in class FlyController I've the following method to append text to
the view:
- (void)appendToLog:(NSString *)message {
NSRange endRange;
endRange.location = [[vConsole textStorage] length];
endRange.length = 0;
[vConsole replaceCharactersInRange:endRange withString:message];
endRange.length = [message length];
[vConsole scrollRangeToVisible:endRange];
}
Simple and easy, from an Apple sample.
The other threads send their messages to this console with the
following code ( this is the offending code... ):
void FlyUDPReceiver::msgToLog(const char *argv, ...) {
// Concatenar tots els par`metres, en format printf, que arriben dins
un C string.
va_list llista;
char *msg = (char *) malloc(sizeof(char) * MAXDATASIZE);
if (msg == NULL) return;
va_start(llista, argv);
vsprintf(msg, argv, llista);
va_end(llista);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *wip = [[NSString alloc] initWithCString:msg]; // offending
line !!!!!
objc_msgSend(mcontroller, sel_getUid("appendToLog:"), wip);
[pool release];
return;
}
When I put my application in trace mode, a lot of messages need to be
output in the console and the apps crash with logs like this:
Date/Time: 2004-04-08 13:32:46 +0200
OS Version: 10.3.3 (Build 7F44)
Report Version: 2
Command: FlyMotion
Path:
/projectes/FlyMotion/codi/FlyMotion/build/FlyMotion.app/Contents/MacOS/
FlyMotion
Version: 0.1 (0.1)
PID: 1271
Thread: 2
Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_INVALID_ADDRESS (0x0001) at 0xa1b1c1db
Thread 0:
0 <<00000000>> 0xffff85d8 __spin_lock_relinquish + 0x18
1 libSystem.B.dylib 0x90002ec8 szone_malloc + 0x68
2 libSystem.B.dylib 0x90001174 malloc_zone_malloc + 0x94
3 libSystem.B.dylib 0x90001f64 malloc + 0x44
4 ATS 0x96bf9b74 SetupInternalArrays + 0x30
5 ATS 0x96bf99f4 _eLLCLayoutText + 0x58
6 ATS 0x96bf9978 LLCLayoutText + 0x48
7 com.apple.AppKit 0x92ded42c -[NSATSTypesetter
_beginLayout:] + 0x1d0
8 com.apple.AppKit 0x92e0b6e8 -[NSATSTypesetter
layoutParagraphAtPoint:] + 0x344
9 com.apple.AppKit 0x92dd07b0 -[NSATSTypesetter
layoutGlyphsInLayoutManager:startingAtGlyphIndex:
maxNumberOfLineFragments:nextGlyphIndex:] + 0x6f4
10 com.apple.AppKit 0x92dd8d30 -[NSLayoutManager(NSPrivate)
_fillLayoutHoleAtIndex:desiredNumberOfLines:] + 0x43c
11 com.apple.AppKit 0x92df1ec4
_NSFastFillAllLayoutHolesUpToEndOfContainerForGlyphIndex + 0x248
12 com.apple.AppKit 0x92ddc650 -[NSLayoutManager
textContainerForGlyphAtIndex:effectiveRange:] + 0x5c
13 com.apple.AppKit 0x92e07300 -[NSLayoutManager
glyphRangeForTextContainer:] + 0x144
14 com.apple.AppKit 0x92e1c8d0
-[NSAttributedString(NSStringDrawingExtension) _sizeWithSize:] + 0x178
15 com.apple.AppKit 0x92e6fbe8
-[NSAttributedString(NSStringDrawing) size] + 0x58
16 StringTexture.ob 0x050b0238 -[StringTexture genTexture] +
0xb4 (StringTexture.m:159)
17 StringTexture.ob 0x050b07c8 -[StringTexture drawAtPoint:]
+ 0x5c (StringTexture.m:214)
18 Fly3D.ob 0x0050a0e0 -[Fly3DView drawInfo] + 0x1c8
(Fly3D.mm:748)
19 Fly3D.ob 0x00508088 -[Fly3DView drawRect:] + 0x88
(Fly3D.mm:427)
20 com.apple.AppKit 0x92dc7864 -[NSView _drawRect:clip:] +
0x770
21 com.apple.AppKit 0x92dd8260 -[NSView
_recursiveDisplayAllDirtyWithLockFocus:visRect:] + 0xe8
22 com.apple.AppKit 0x92dc3b7c -[NSView
_recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:
rectIsVisibleRectForView:topView:] + 0x9c
23 com.apple.AppKit 0x92dc3f98 -[NSView
_recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:
rectIsVisibleRectForView:topView:] + 0x4b8
24 com.apple.AppKit 0x92e109d8 -[NSFrameView
_recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:
rectIsVisibleRectForView:topView:] + 0x124
25 com.apple.AppKit 0x92df7b74 -[NSThemeFrame
_recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:
rectIsVisibleRectForView:topView:] + 0xc0
26 com.apple.AppKit 0x92dd4e34 -[NSView
_displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] +
0x180
27 com.apple.AppKit 0x92dedd5c -[NSView displayIfNeeded] +
0xa8
28 com.apple.AppKit 0x92dfea34 -[NSWindow displayIfNeeded] +
0xb4
29 com.apple.AppKit 0x92ddf13c _handleWindowNeedsDisplay +
0xe0
30 com.apple.CoreFoundation 0x90191d60 __CFRunLoopDoObservers + 0x194
31 com.apple.CoreFoundation 0x901915fc __CFRunLoopRun + 0x18c
32 com.apple.CoreFoundation 0x90195f4c CFRunLoopRunSpecific + 0x148
33 com.apple.HIToolbox 0x927d648c RunCurrentEventLoopInMode +
0xac
34 com.apple.HIToolbox 0x927dcb6c ReceiveNextEventCommon + 0xf4
35 com.apple.HIToolbox 0x927feccc
BlockUntilNextEventMatchingListInMode + 0x60
36 com.apple.AppKit 0x92dd2a34 _DPSNextEvent + 0x180
37 com.apple.AppKit 0x92de93b0 -[NSApplication
nextEventMatchingMask:untilDate:inMode:dequeue:] + 0x74
38 com.apple.AppKit 0x92dfd718 -[NSApplication run] + 0x21c
39 com.apple.AppKit 0x92eb9b80 NSApplicationMain + 0x1d0
40 main.ob 0x000fdf30 main + 0x38 (main.mm:11)
41 com.apple.myCocoaApp 0x00002734 start + 0x1bc
42 com.apple.myCocoaApp 0x000025a8 start + 0x30
Thread 1:
0 libSystem.B.dylib 0x90017048 semaphore_wait_signal_trap +
0x8
1 libSystem.B.dylib 0x9000e890 _pthread_cond_wait + 0x270
2 com.apple.Foundation 0x90a4c238 -[NSConditionLock
lockWhenCondition:] + 0x44
3 com.apple.AppKit 0x92dca8dc -[NSUIHeartBeat
_heartBeatThread:] + 0x190
4 com.apple.Foundation 0x90a3a2c4 forkThreadForFunction + 0x6c
5 libSystem.B.dylib 0x900247e8 _pthread_body + 0x28
Thread 2 Crashed:
0 libSystem.B.dylib 0x900035a4 szone_malloc + 0x744
1 libSystem.B.dylib 0x90001174 malloc_zone_malloc + 0x94
2 com.apple.CoreFoundation 0x90191f8c _CFRuntimeCreateInstance + 0xc8
3 com.apple.CoreFoundation 0x90195268
__CFStringCreateImmutableFunnel3 + 0x634
4 com.apple.CoreFoundation 0x901a663c CFStringCreateWithCString +
0x5c
5 FlyUDPReceiver.ob 0x00298504 FlyUDPReceiver::msgToLog(char
const*, ...) + 0x108 (FlyUDPReceiver.mm:52)
6 FlyUDPReceiver.ob 0x00298ed8 FlyUDPReceiver::run() + 0x45c
(FlyUDPReceiver.mm:250)
7 thread.ob 0x000f9c88 threadLauncher + 0x44
(thread.cpp:28)
8 libSystem.B.dylib 0x900247e8 _pthread_body + 0x28
Thread 3:
0 <<00000000>> 0xffff85d8 __spin_lock_relinquish + 0x18
1 libSystem.B.dylib 0x90002f10 szone_malloc + 0xb0
2 libSystem.B.dylib 0x90001174 malloc_zone_malloc + 0x94
3 com.apple.CoreFoundation 0x90191f8c _CFRuntimeCreateInstance + 0xc8
4 com.apple.CoreFoundation 0x901949b4 __CFArrayInit + 0x158
5 com.apple.CoreFoundation 0x901acc3c CFArrayCreate + 0x2c
6 com.apple.Foundation 0x90a360cc
-[NSObject(NSMainThreadPerformAdditions)
performSelectorOnMainThread:withObject:waitUntilDone:] + 0x54
7 com.apple.AppKit 0x92ddc374 -[NSWindow
_postWindowNeedsDisplay] + 0x124
8 com.apple.AppKit 0x92dc84a8 -[NSView
setNeedsDisplayInRect:] + 0x394
9 com.apple.AppKit 0x92dd48ac -[NSView setNeedsDisplay:] +
0x34
10 Fly3D.ob 0x00506ff0 runLoop() + 0x154
(Fly3D.mm:120)
11 Fly3D.ob 0x00507ab0 Fly3D::run() + 0x80
(Fly3D.mm:305)
12 thread.ob 0x000f9c88 threadLauncher + 0x44
(thread.cpp:28)
13 libSystem.B.dylib 0x900247e8 _pthread_body + 0x28
Any idea ?
Bes regards,
Joan B. Altadill
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.