crash when updating global property

Hi All,

I have found a bug in my ASOC project. The trouble is - it isn’t consistent. It crashes after 3 or 4 or ten runs unexpectedly. I have tracked it down to one of two handlers. They both will cause it independentaly. Removing the code in either stops the crashes associated with that one.

This one appends text to a log file:

 on wrightTotestlog_(stuffToWrite)
		if textlog then
			try
				log "In"
				set stuffToWrite to stuffToWrite as string
				do shell script "echo '" & newstuff & "' >>" & quoted form of LogPath
				log "out"
			end try
		end if
end wrightTotestlog_

This one appends text to a property “logText” which is later used to update a log window text view:

on updateLogText_(newline)
	log "IN"
	set aa to my logText as string
	set bb to newline as string
	set my logText to (my logText as string) & return & bb 
	log "Out"
end updateLogText

Every time there is a crash it stops after the “in” and throws the bad access error.

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0xffffffffffffffba
Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Application Specific Information:
objc[1095]: garbage collection is ON

From what I have read, this error usually results from accessing a variable that has been released already, not having retained something etc… but with ASOC and GC on I can not figure out what is the culprit.

Running the exact same code and parameters repeatedly goes fine and then suddenly crashes.

Any clues where to look, if I am assigning something I shouldn’t, etc. would be much appreciated. I have spent hours trying different syntax with always the same results. I just want to update a log as the code rolls along.

Thanks, Rob

In your first handler, where is newstuff coming from? You don’t seem to use stuffToWrite.

In your second, you don’t use aa.

Add some more logging – a log after each line, to catch the actual offending line. Log the variable values, too.

sorry, I stupidly removed a few lines to simplify things and didn’t send the edited ones


on updateLogText_(newline)
   log "IN"
   set aa to my logText as string
   log aa
   set bb to newline as string
   log bb
   set my logText to  aa & return & bb 
   log my logText
   log "Out"
end updateLogText
on wrightTotestlog_(stuffToWrite)
           try
               log "In"
               set newstuff to stuffToWrite as string
               log newstuff
               do shell script "echo '" & newstuff & "' >>" & quoted form of LogPath
               log "out"
           end try
end wrightTotestlog_

I’ll run it again and check the logging but I already had done that and never saw anything unusual - the same lines that work in previous run suddenly choke. The lines that fail are

set my logText to aa & return & bb

do shell script “echo '” & newstuff & “’ >>” & quoted form of LogPath

More tests…

Thanks, Rob