I'm getting very weird behavior of my app.
My app crashes when it tries to create a file with invalid file name.
The real code is a bit different, but it's similar to this:
procedure Foo(const AFileName: string);
var
f: TFileStream;
begin
try
f := TFileStream.Create(AFileName, fmCreate);
f.Free;
if FileExists(AFileName) then DeleteFile(AFileName);
except
on E: Exception do begin
// the code never gets here
raise Exception.Create(Format('Unable to create output file %s', [AFileName]));
end;
end;
end;
Thing is that while in the IDE the EFCreateError is shown and after that I see the Disassembly window and then IDE freezes and app just crashes.
If I run it from the shell it gets terminated with the following error:
2022-09-18 21:23:45.262 ****[6525:46831] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSBigMutableString replaceCharactersInRange:withString:]: nil argument'
*** First throw call stack:
(
0 CoreFoundation 0x00007ff80f7d5e9b __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007ff80f537e48 objc_exception_throw + 48
2 Foundation 0x00007ff810504955 -[NSBigMutableString replaceCharactersInRange:withString:] + 1163
3 Foundation 0x00007ff8104fc0b1 -[NSConcreteMutableAttributedString replaceCharactersInRange:withString:] + 367
4 UIFoundation 0x00007ff812f3ea97 __NSConcreteTextStorageLockedForwarding + 66
5 UIFoundation 0x00007ff812f790f2 -[NSConcreteTextStorage replaceCharactersInRange:withString:] + 74
6 AppKit 0x00007ff8122d8a46 -[NSTextView _insertText:replacementRange:] + 1760
I tried to reproduce it with a small console app, but there it worked just fine.
Lazarus 2.2.2 (Intel mode)
Mac M1
macOS 12.6
FPC 3.3.1 (latest from the trunk)