Please help me see this problem,about GSComponent

I want to execute create a new component in the same layer, and then copy the pieceSettings and position of the selected component to the new component (the created component is an existing component, and the property is the same to the selected one). After that, adjust the property value of one of the components. Later, the other one will change fllow it. What is the cause? Sometimes, the software will crash and exit directly. Here is my code:

layer = font.selectedLayers[0]
for component in layer.components:
    if component.selected:
        tempComponent = GSComponent('_part.001')
        tempComponent.setPieceSettings_(component.pieceSettings())
        tempComponent.position = component.position
        layer.components.append(tempComponent)

The crash information is as follows:

Incident Identifier: A5F6E631-E0C6-4651-8032-9778E55802D2
CrashReporter Key: 5F017ACE-3ADC-50E7-8522-9BB790E02DEE
Hardware Model: iMac19,2
Process: Glyphs [10318]
Path:
Identifier: com.GeorgSeifert.Glyphs2
Version: 2.6.2 (1246)
Code Type: X86-64
Parent Process: launchd [1]

Date/Time: 2019-08-20T10:50:48Z
Launch Time: 2019-08-20T10:46:41Z
OS Version: Mac OS X 10.14.6 (18G84)
Report Version: 104

Exception Type: SIGSEGV
Exception Codes: SEGV_MAPERR at 0x18
Crashed Thread: 0

Application Specific Information:
Selector name found in current argument registers: self

Thread 0 Crashed:
0 libobjc.A.dylib 0x00007fff6480469d objc_msgSend + 29
1 _objc.so 0x0000000112e3e62c pythonify_c_value + 946
2 _objc.so 0x0000000112e301e1 PyObjCFFI_BuildResult + 741
3 _objc.so 0x0000000112e3121b PyObjCFFI_Caller + 2182
4 _objc.so 0x0000000112e435d5 PyObjCSelector_GetMetadata + 1880
5 Python 0x00007fff43f88078 PyObject_Call + 97
6 Python 0x00007fff43ffe9d3 PyEval_EvalFrameEx + 3312
7 Python 0x00007fff43f9ca89 PyGen_NeedsFinalizing + 244
8 Python 0x00007fff43fffd6c PyEval_EvalFrameEx + 8329
9 Python 0x00007fff43f9ca89 PyGen_NeedsFinalizing + 244
10 Python 0x00007fff43fffd6c PyEval_EvalFrameEx + 8329
11 Python 0x00007fff43ffdab2 PyEval_EvalCodeEx + 1555
12 Python 0x00007fff43ffd499 PyEval_EvalCode + 32
13 Python 0x00007fff4401c645 PyParser_ASTFromFile + 287
14 Python 0x00007fff4401c6ec PyRun_FileExFlags + 130
15 Python 0x00007fff4401c26b PyRun_SimpleFileExFlags + 718
16 Glyphs 0x000000010ce5b81a 0x10ce21000 + 239642
17 Glyphs 0x000000010ce5b690 0x10ce21000 + 239248
18 AppKit 0x00007fff37973644 -[NSApplication(NSResponder) sendAction:to:from:] + 312
19 Glyphs 0x000000010cea1545 0x10ce21000 + 525637
20 AppKit 0x00007fff379cf86b -[NSMenuItem _corePerformAction] + 323
21 AppKit 0x00007fff379cf5dc -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 114
22 AppKit 0x00007fff379ce44e -[NSMenu performKeyEquivalent:] + 363
23 AppKit 0x00007fff37e53d5f routeKeyEquivalent + 860
24 AppKit 0x00007fff3768c148 -[NSApplication(NSEvent) sendEvent:] + 1064
25 HockeySDK 0x000000010d5b4f7f 0x10d5a5000 + 65407
26 Glyphs 0x000000010cea0f5d 0x10ce21000 + 524125
27 AppKit 0x00007fff3767a5e0 -[NSApplication run] + 755
28 AppKit 0x00007fff37669ae8 NSApplicationMain + 777
29 Glyphs 0x000000010ce29e37 0x10ce21000 + 36407
30 libdyld.dylib 0x00007fff65fe03d5 start + 1

…There’s still a lot to fill in. I sent an error report.

You can’t append to a list that you iterate.

this should work

layer = font.selectedLayers[0]
for component in list(layer.components):
    if component.selected:
        tempComponent = GSComponent('_part.001')
        tempComponent.setPieceSettings_(component.pieceSettings())
        tempComponent.position = component.position
        layer.components.append(tempComponent)
1 Like

oh,thanks,I try it