I've posted the code for the simple test application previously, but can provide if necessary. Basically a function in a DYLIB is passed a string parameter, it returns TRUE with an OUT variable of another string which proves that the data went into the DYLIB function and returned out. The function template:
I've posted the code for the simple test application previously, but can provide if necessary. Basically a function in a DYLIB is passed a string parameter, it returns TRUE with an OUT variable of another string which proves that the data went into the DYLIB function and returned out. The function template:
function _say_Hello(Hello: string; out ReturnString: string): boolean; cdecl; external TestDLL;
I have simple showmessage() statements in the calling application for things like onCloseQuery and onClose etc, these all show, everything WORKS as it should until the application closes(onCloseQuery executed, onClose executed, and about half a second to a second after everything shuts down the problem report pops up). I've put the google drive link to the error log. Basically I get this:
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000bf7ffffc
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [0]
When I look at the stack trace (attached), there are none of my two files (DylibTest and libpTesDLL.DYLIB) mentioned, it's all RTL/system units. I've googled Seg Fault 11, but nothing jumps out.
EDIT: Added an Initialisation and Finalization section to the unit of the calling program. Initialisation is processed, Finalization is not processed (although both are processed in the Win32 version).
Any ideas appreciated......
https://drive.google.com/a/orexresearch.com/file/d/1wzVGrVbimjyZPfat3S-sZeBajqkKosCG/view?usp=drive_web
function _say_Hello(Hello: string; out ReturnString: string): boolean; cdecl; external TestDLL;
I have simple showmessage() statements in the calling application for things like onCloseQuery and onClose etc, these all show, everything WORKS as it should until the application closes(onCloseQuery executed, onClose executed, and about half a second to a second after everything shuts down the problem report pops up). I've put the google drive link to the error log. Basically I get this:
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000bf7ffffc
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [0]
When I look at the stack trace (attached), there are none of my two files (DylibTest and libpTesDLL.DYLIB) mentioned, it's all RTL/system units. I've googled Seg Fault 11, but nothing jumps out.
EDIT: Added an Initialisation and Finalization section to the unit of the calling program. Initialisation is processed, Finalization is not processed (although both are processed in the Win32 version).
Any ideas appreciated......
https://drive.google.com/a/orexresearch.com/file/d/1wzVGrVbimjyZPfat3S-sZeBajqkKosCG/view?usp=drive_web
Did a deploy of same code and PAServer terminal showed this for many lines:
ReplyDeleteRuntime error 231 at 001844AD
Ran the app again from Finder and didn't get the 231 error, but still got the seg fault 11.
If I take out all reference to the DLL, app terminates (doesn't showmessage in Finalize) without error. So looks like it's whatever is happening when the DLL Unloads.
ReplyDeleteAnswered by (and thanks to) @Remy LeBeau on StackOverflow:
ReplyDeletestring is NOT a portable data type for interop across library boundaries. Use PChar instead, and then you need to decide WHO allocates and frees memory for strings - the library or the calling app - and HOW they are allocated and freed, and do so in an interop compatible manner. You are not passing strings across the library boundary in a safe manner, so it is no wonder that you are crashing your code.
Try something more like this instead:
....
....