ID crashes when call method "createHyperlinkQRCode" on Rectangle from "afterOpen" event handler
ID 18.1 Windows 10
I'm trying to develop a script that updates the QR code (creates anew in the same Rectangle ) when the document is opened.
The Startup Script sets the event handler of the "afterOpen" event, where the "createHyperlinkQRCode" method is called on the found Rectangle object.
In this case, InDesign crashes with an error
<crash exception="EXCEPTION_ACCESS_VIOLATION" exceptionCode="0xc0000005" instruction="0x00007FFD49229914">
Creating a QR code manually through the main menu does not cause errors. The error does not occur when the script calls the "createHyperlinkQRCode" method on the Document object. But in this case, I have to point with the cursor to the place of inserting the QR code, and this creates an unnecessary waste of time.
If the script is called from the script panel, it works without errors, which indicates that there are no errors in the script.
I tried the following layouts (they cause the same error and crash InDesign):
(1) Preferred option. Call the QR code creation method directly in the "afterOpen" event handler.
(2) I extended the Rectangle object with an additional method that is called in the "afterOpen" event handler.
(3) I made a separate script that can be run manually. It works if I run it manually. And crashes if I call this script in the "afterOpen" event handler using doScript().
-
m1b commented
I can confirm that this bug still exists. I'm running MacOS 15.2 ID 20.0.1.
My test code:
```
//@targetengine "mySession"
var myEventListener = app.eventListeners.item("mAfSave");
if (myEventListener.isValid)
myEventListener.remove();myEventListener = app.addEventListener("afterSave", testQRCodeCrash);
// myEventListener = app.addEventListener("afterOpen", testQRCodeCrash);
myEventListener.name = "mAfSave";function testQRCodeCrash() {
alert('Test started');
if (!app.documents.length) return;
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
// any of these cause Indesign to crash:
app.activeDocument.rectangles.add({ geometricBounds: [0, 0, 40, 40] }).createPlainTextQRCode('test');
// app.activeDocument.rectangles.add({ geometricBounds: [0, 0, 100, 100] }).createTextMsgQRCode('1234567890', 'test');
// app.activeDocument.rectangles.add({ geometricBounds: [0, 0, 100, 100] }).createEmailQRCode('foo@bar.com', 'test', 'test');
// app.activeDocument.rectangles.add({ geometricBounds: [0, 0, 100, 100] }).createHyperlinkQRCode('https://foo-bar.com/test');alert('Test completed');
};
```
See this [discussion on the forum](https://community.adobe.com/t5/indesign-discussions/function-createplaintextqrcode-crashes-adobe-indesign-without-any-reason-provided/m-p/15036478#M601870), too.
- Mark