A couple of Formatted Text Control users found an interesting bug in the Xojo Windows 64-bit compiler. If the user pasted anything into the control it would hard crash the Windows application. I spent a couple of days trying to find a workaround and was flummoxed on how to fix. Thankfully there’s an easy workaround thanks to Team Xojo.
In the Open event of the FTC control we create a new FTCUndoManager instance. When the user pastes something into the control we pass the existing text into the Undo Manager so it can properly save the before state and allow an undo of the paste.
Pasting text calls the SavePaste method of the FTCUndoManager class. This is where things start to go wrong. This method passes Self into the constructor for the FTCUndoPaste class. Stopping the debugger in this method shows us that self is nil! What’s odd is several other passed in class objects are nil too (even though they are not at the control level). That self is nil is indeed a problem since FTCUndoPaste needs the reference to the UndoManager for a variety of reasons.
How can self be nil? After all this is a method in the class. By definition self should be non-nil. I think this would fall under ‘compiler problem’. I submitted a private Feedback report to Xojo (53967) and thankfully Xojo reviewed it quickly and were intrigued enough to look into it. It was verified and a workaround was quickly found.
William from Xojo wrote this:
There seems to be an issue with passing byval structure parameters (for 64-bit Window build), as a workaround you can pass these byref instead, i.e. MyFunction(…, Byref firstPa as ParagraphAttributes)
So I was able to change two methods, FTCUndoManager.savePaste and FTCUndoPaste.constructor, by using byRef for each object we pass into the Undo Manager into and in the Undo Paste class. Voila! Problem solved.
I suspect that FTC is big enough and complex enough to manifest some edge case for the 64-bit compiler. If you run into an issue like this try this workaround. And don’t forget to submit a Feedback report to Xojo since the more edge cases they can find the more likely it is they can determine the cause.