I’m calling applescripts from within filemaker to do something with parameters and after finishing it fills in a global field in filemaker.
BUT!!! When building the scripts with ASOC in them they often let filemaker crash after some runs of the same script. the crash reports then always shows something like
Application Specific Information:
abort() called
*** error for object 0x7fe67e017408: incorrect checksum for freed object - object was probably modified after being freed.
I already contacted filemaker about this, send them a stack trace, but they say filemaker is not involved.
They said: The crashed thread only shows system calls (libsystem, CoreGraphics, HIToolbox, CoreFoundation, AppKit).
Is there anything I can do to find out what’s going wrong.
With the same setup but without ASOC I can run the scripts for hours without any issue.
any help would greatly be appreciated. I als have the feeling that building a script with SD7 is more vulnerable than one build in SD6. Is this possible?
This would appear to be a memory corruption bug. These kinds of problems are very difficult to trace because the cause is usually displaced in time from the consequence. In this case, you have some piece of memory being deallocated, and then reallocated to some other purpose, and then being modified after its deallocation by code which has a stale reference to the memory.
There are no obvious clues in your crash report and I cannot think of any good ways of tracing this without involving some of the debugging tools built into Xcode. This isn’t viable given that you only have the FileMaker binary to work with.
ASObjC makes it exceeding easy to corrupt memory. I would start by auditing all of the ASObjC code to ensure you are allocating and messaging objects correctly.
You say that the script crashes once ASObjC code is introduced into FileMaker. Does this same ASObjC code crash when it runs from SD or the Script Editor? If you can reproduce the crash in SD, that rules FileMaker out of the equation which is somewhat helpful. This also points the finger firmly at your ASObjC code.
Thnx Mark,
For your explanation. No it doesn’t crash when run from SD.
Maybe Shane can have a look at a part of the code
I’m calling a API with the following code and maybe I’m not deallocating some parts correctly?
set rResult to (NSJSONSerialization’s JSONObjectWithData:((NSString’s stringWithString:mRequestStr)'s dataUsingEncoding:(NSUTF8StringEncoding)) options:0 |error|:( missing value )) asrecord if ( countof rResult) is 1 then set mData to “” set mRecordProperty to ((NSDictionary’s dictionaryWithDictionary:rResult)'s allKeys() aslist )'s item 1 astext set theDict to NSDictionary’s dictionaryWithDictionary:rResult set mValue to theDict’s objectForKey:mRecordProperty set mURL to mURL & “?” & mRecordProperty & “=” & mValue endif set jSONDataString to NSString’s stringWithString:mRequestStr set jsonData to jSONDataString’s dataUsingEncoding:(NSUTF8StringEncoding) set {aJsonDict, theError} to NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:( reference ) ifnot theError ismissing valuethenreturn -128 – STOPPEN set {mData, theError} to NSJSONSerialization’s dataWithJSONObject:aJsonDict options:0 |error|:( reference ) set aRequest to NSMutableURLRequest’s requestWithURL:(|NSURL|'s URLWithString:mURL)
aRequest’s setHTTPMethod:“GET”
aRequest’s setValue:“application/json” forHTTPHeaderField:“Content-Type”
aRequest’s setValue:("Bearer " & gAccessToken) forHTTPHeaderField:“Authorization” if mData isnot “” then aRequest’s setHTTPBody:mData set aRes to NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:( reference ) |error|:( missing value ) set resList to aRes aslist set bRes to contents of ( firstitemof resList) set resStr to NSString’s alloc()'s initWithData:bRes encoding:(NSUTF8StringEncoding) set jsonString to resStr astext set resStr tomissing value set theResult to (NSJSONSerialization’s JSONObjectWithData:((NSString’s stringWithString:jsonString)'s dataUsingEncoding:(NSUTF8StringEncoding)) options:0 |error|:( missing value )) asrecord
at the top of the script I’m using the following:
use AppleScript version “2.4” usescripting additions
useframework “Foundation” property NSString : a referencetocurrent application’s NSString property NSUTF8StringEncoding : a referencetocurrent application’s NSUTF8StringEncoding property |NSURL| : a referencetocurrent application’s |NSURL| property NSMutableURLRequest : a referencetocurrent application’s NSMutableURLRequest property NSURLConnection : a referencetocurrent application’s NSURLConnection property NSJSONSerialization : a referencetocurrent application’s NSJSONSerialization property NSDictionary : a referencetocurrent application’s NSDictionary
I’ve just combined some ASObjC code from Shane and Takaaki Naganoya and google searches.…
I don’t have much to add to what Mark’s said. The answer to your question about saving from v6 versus v7, though, is that it won’t make any difference.
You don’t really have any control over memory allocation — AppleScript does that for you (or not).
I’m wondering whether it’s possible that using NSURLConnection is triggering something, but that’s just a gut feeling.
What happens if you use the code as an applet? Mt recollection of how FileMaker works with AS is hazy.
Hi Shane thanks for the answer so far
With a applet do you mean a script app that runs once or that stays open?
I’m already running the script as a application that runs if you start the script with parameters from within filemaker and quits after it returns a reply json-like to filemaker…
Sometimes it makes filemaker crash at the start and sometimes after the return of the reply by clicking on another element in filemaker itself that even has nothing to do with the script itself.
use AppleScript version “2.4” usescripting additions useframework “Foundation” set mPosixPath to “/Users/luc.lnt/Documents/FMP_ASSCRIPTS/PX-ERP_AppleScriptApps/PX-ERP_Teamleader - Events_0100r.app” set mPath to ( POSIX file mPosixPath) try
mPath asalias onerror errMsg tellapplication “SystemUIServer” toactivate ( display alert “AppleScriptApp '” & mPosixPath & “’ bestaat niet !” message errMsg) endtry set dbInfo to {dbName:“PX.fmp12”, FMPversion:“17”, dbTable:“GLOBAL”, dbField:“SCRIPTRESULT”} set theEventParam to {theEvent:“ShowScriptVersion”, thePhrasID:""} set mParams to {dbInfo} & {theEventParam} set reply torun script mPath with parameters mParams tellapplication “FileMaker Pro Advanced” telldatabase “PX.fmp12” totelltable “GLOBAL” tosetfield “GLOBAL” to reply endtell
As Mark said, these kinds of errors are very difficult to track down. There’s no guarantee that there is one cause: the fact that you had it happen without ASObjC suggests an unrelated crash.
I’m not sure what to advise, other than trying to run your code in separate apps where possible, to limit any direct effect on FileMaker.
It seems that using the use clause for script libraries is making filemaker more vulnerable for crashes.
After removing the ASObjC parts it kept crashing with the same errors.
Then I changed back to my old way of working with SD5 — so I could load some script libraries in resources and now after calling it multiple times it seems to no longer crash.
I again will try to add some ASObjC in my scripts and evaluate again.
Why is the use clause making a application unstable with memory leaks or corruption?
Anyone else from Apple reading this?
If FileMaker is running your scripts directly, I’d guess it’s using a single instance of the AppleScript component. (You can test this by changing text item delimiters in one script, and seeing if the change is reflected in another.)
Script libraries are cached per component instances. That is, assuming the above, once one script loads a particular script library, it remains cached by AppleScript. So if another script uses, say, a different version of the lib, it will actually still get the first one loaded.
It also means any top-level values in loaded libraries are going to be persistent, and shared between any clients of that library: when you set a library property, you set it for all clients of that library using that AppleScript component instance.
In such circumstances, it’s feasible that one script could do something behind the back of another to make bad things happen.
This may all be irrelevant in your case – it’s hard to know. But in case it is relevant, you need to make sure all scripts are expecting the same library code, and that the libraries’ properties and globals are accessed by client scripts on the basis that they don’t have exclusive access. For example, you may need to consider accessing them through handlers that check their contents, rather than assuming they have the value your script last gave them.