# Crash when dragging atom over other atom to create bond

**URL:** <https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964>\
**Category:** Support\
**Created:** [November 9, 2023, 10:43pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964 "2023-11-09T22:43:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![InkTide](https://discuss.avogadro.cc/letter_avatar_proxy/v4/letter/i/a88e4f/32.png) [@InkTide](https://discuss.avogadro.cc/u/InkTide)\
**Post date:** [November 9, 2023, 10:43pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/1 "2023-11-09T22:43:33Z")

</div>

## Environment Information

Avogadro version: 1.98.1; using the flathub repository  
Operating system and version: Zorin 16 (based on Ubuntu 20.04)

## Expected Behavior

The atom being dragged should be removed and bonds to it should transfer to the atom being dragged over.

## Actual Behavior

Application crashes.

## Steps to Reproduce

Drag an atom with a bond over another atom.

Note: deleting an atom with hydrogens attached also crashes, which might be related; something about the bond transfer/adjustment is highly unstable.

---

<div class="post-metadata">

**Author:** ![ghutchis](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/ghutchis/32/456_2.png) [@ghutchis](https://discuss.avogadro.cc/u/ghutchis)\
**Post date:** [November 10, 2023, 1:49am UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/2 "2023-11-10T01:49:07Z")

</div>

Let me see if I can understand what you’re doing. You’re using the edit tool, dragging to create a new atom and bond, and you drag over to an existing atom (e.g., to create a ring) … and there’s a crash?

I’m not super familiar with Flatpak - is it possible to get a crash log?

Can you try this with the AppImage, e.g. from [Release Avogadro 1.98.1 · OpenChemistry/avogadrolibs · GitHub](https://github.com/openchemistry/avogadrolibs/releases/latest)

---

<div class="post-metadata">

**Author:** ![ghutchis](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/ghutchis/32/456_2.png) [@ghutchis](https://discuss.avogadro.cc/u/ghutchis)\
**Post date:** [November 10, 2023, 2:05am UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/3 "2023-11-10T02:05:18Z")

</div>

I should mention that I’d ask you to try the AppImage or another package, because there _was_ a bug like this, and I fixed it … maybe in 1.95 or 1.96? It’s possible there’s still something lurking, but I’d want to make sure it’s not something with the Flatpak build itself.

---

<div class="post-metadata">

**Author:** ![InkTide](https://discuss.avogadro.cc/letter_avatar_proxy/v4/letter/i/a88e4f/32.png) [@InkTide](https://discuss.avogadro.cc/u/InkTide)\
**Post date:** [November 11, 2023, 6:43pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/4 "2023-11-11T18:43:46Z")

</div>

I tried the appimage, and it works as expected (no crash). I don’t know where a crash log for a flatpak would be located.

---

<div class="post-metadata">

**Author:** ![ghutchis](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/ghutchis/32/456_2.png) [@ghutchis](https://discuss.avogadro.cc/u/ghutchis)\
**Post date:** [November 11, 2023, 8:09pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/5 "2023-11-11T20:09:03Z")

</div>

@kevinsmia1939 - is there a good way to get a crash log from the Flatpak build?

Just to check @InkTide - when you run the Flatpak, the About box says 1.98.1?

---

<div class="post-metadata">

**Author:** ![kevinsmia1939](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/kevinsmia1939/32/786_2.png) [@kevinsmia1939](https://discuss.avogadro.cc/u/kevinsmia1939)\
**Post date:** [November 17, 2023, 11:19pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/6 "2023-11-17T23:19:48Z")

</div>

Hi @InkTide and @ghutchis  
You can see the crash log by running avogadro2 Flatpak from the terminal. Then the crash log will be seen on the terminal.  
`flatpak run org.openchemistry.Avogadro2`

Avogadro2 version is indeed 1.98.1  
I can replicate the crash by creating two separate ethane molecule then try to create a bond between them.

```auto
"Checking for formatScripts scripts in path /home/kevin/.var/app/org.openchemistry.Avogadro2/data/OpenChemistry/Avogadro/formatScripts"
"Checking for formatScripts scripts in path /app/share/OpenChemistry/Avogadro/formatScripts"
"Checking for formatScripts scripts in path /usr/share/OpenChemistry/Avogadro/formatScripts"
"Checking for formatScripts scripts in path /usr/share/runtime/share/OpenChemistry/Avogadro/formatScripts"
"Checking for formatScripts scripts in path /run/host/user-share/OpenChemistry/Avogadro/formatScripts"
"Checking for formatScripts scripts in path /run/host/share/OpenChemistry/Avogadro/formatScripts"
"Checking for formatScripts scripts in path /app/bin/../lib/avogadro2/scripts/formatScripts"
Open Babel formats ready: 142
/usr/include/c++/12.2.0/bits/stl_vector.h:1123: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.

```

The latest message is displayed before crashing.

---

<div class="post-metadata">

**Author:** ![ghutchis](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/ghutchis/32/456_2.png) [@ghutchis](https://discuss.avogadro.cc/u/ghutchis)\
**Post date:** [November 17, 2023, 11:55pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/7 "2023-11-17T23:55:01Z")

</div>

> [@kevinsmia1939](#):
>
> The latest message is displayed before crashing.

That’s only somewhat useful since it’s hard to know what Avogadro code called that `std::vector []` code.

Is it possible to run the flatpak inside of `gdb`, e.g.

```auto
gdb flatpak
…
% run run org.openchemistry.Avogadro2
… [use Avogadro to create the crash]
% bt
… [print a backtrace of the code causing the crash]

```

Getting a backtrace from the crash would be **super** useful in fixing this crash.

Alternatively, I can create a pull request with a bunch of debugging added to the editor and that would help identify the crash point.

For example, does it crash immediately when creating the bond between them, or when hydrogen atoms are added after creating the bond.

Since I can’t reproduce it myself, I’d need either @kevinsmia1939 or @InkTide to help a bit here.

Thanks! Definitely want to fix this one.

---

<div class="post-metadata">

**Author:** ![kevinsmia1939](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/kevinsmia1939/32/786_2.png) [@kevinsmia1939](https://discuss.avogadro.cc/u/kevinsmia1939)\
**Post date:** [November 18, 2023, 1:55am UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/8 "2023-11-18T01:55:09Z")

</div>

I think I will need to recompile avogadrolib and avogadro2 with `-DCMAKE_BUILD_TYPE=RelWithDebInfo`

Anyway, to use gdb in Flatpak is to run this command.  
`flatpak run --command=bash --devel org.openchemistry.Avogadro2`  
Then  
`gdb /app/bin/avogadro2`

---

<div class="post-metadata">

**Author:** ![kevinsmia1939](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/kevinsmia1939/32/786_2.png) [@kevinsmia1939](https://discuss.avogadro.cc/u/kevinsmia1939)\
**Post date:** [November 19, 2023, 12:35am UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/9 "2023-11-19T00:35:14Z")

</div>

After enable debuginfo in Flatpak, I can get the debug info now.  
To get this error, run the following command.  
`flatpak run --command=bash --devel org.openchemistry.Avogadro2`  
`gdb /app/bin/avogadro2`  
`run`

Try to crash Avogadro2

`bt`

```auto
(gdb) run
Starting program: /app/bin/avogadro2 

This GDB supports auto-downloading debuginfo from the following URLs:
https://debuginfod.opensuse.org/
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
Downloading 0.03 MB separate debug info for system-supplied DSO at 0x7ffff7fc4000
[Thread debugging using libthread_db enabled]                                                                                                                                                                                                                               
Using host libthread_db library "/usr/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffecd22640 (LWP 21)]
[New Thread 0x7fffe7fff640 (LWP 22)]
Qt: Session management error: Could not open network socket
Using locale: "en_US"
[New Thread 0x7fffda7ff640 (LWP 23)]
[New Thread 0x7fffd9ffe640 (LWP 24)]
Extension plugins dynamically found… 47
[New Thread 0x7fffd97fd640 (LWP 25)]
"Checking for energy scripts in path /home/kevin/.var/app/org.openchemistry.Avogadro2/data/OpenChemistry/Avogadro/energy"
"Checking for energy scripts in path /app/share/OpenChemistry/Avogadro/energy"
"Checking for energy scripts in path /usr/share/OpenChemistry/Avogadro/energy"
"Checking for energy scripts in path /usr/share/runtime/share/OpenChemistry/Avogadro/energy"
"Checking for energy scripts in path /run/host/user-share/OpenChemistry/Avogadro/energy"
"Checking for energy scripts in path /run/host/share/OpenChemistry/Avogadro/energy"
"Checking for energy scripts in path /app/bin/../lib/avogadro2/scripts/energy"
[Detaching after fork from child process 26]
"Cannot load script /app/lib/avogadro2/scripts/energy/ani2x.py"
[Detaching after fork from child process 27]
"Cannot load script /app/lib/avogadro2/scripts/energy/gaff.py"
[Detaching after fork from child process 28]
"Cannot load script /app/lib/avogadro2/scripts/energy/gfn1.py"
[Detaching after fork from child process 51]
"Cannot load script /app/lib/avogadro2/scripts/energy/gfn2.py"
[Detaching after fork from child process 74]
"Cannot load script /app/lib/avogadro2/scripts/energy/gfnff.py"
[Detaching after fork from child process 97]
"Cannot load script /app/lib/avogadro2/scripts/energy/mmff94.py"
[Detaching after fork from child process 98]
"Cannot load script /app/lib/avogadro2/scripts/energy/uff.py"
OBProcess::executeObabel: Running "/app/bin/obabel" "-L formats read"
[Detaching after fork from child process 99]
OBProcess::executeObabel: Running "/app/bin/obabel" "-L formats write"
[Detaching after fork from child process 100]
OBProcess::executeObabel: Running "/app/bin/obabel" "-L forcefields"
[Detaching after fork from child process 101]
OBProcess::executeObabel: Running "/app/bin/obabel" "-L charges"
[Detaching after fork from child process 102]
OBProcess::executeObabel: Running "/app/bin/obabel" "-V"
[Detaching after fork from child process 103]
"/app/bin/obabel" found: "/app/bin/obabel: Open Babel 3.1.0 -- Nov 18 2023 -- 04:35:44"
"Checking for commands scripts in path /home/kevin/.var/app/org.openchemistry.Avogadro2/data/OpenChemistry/Avogadro/commands"
"Checking for commands scripts in path /app/share/OpenChemistry/Avogadro/commands"
"Checking for commands scripts in path /usr/share/OpenChemistry/Avogadro/commands"
"Checking for commands scripts in path /usr/share/runtime/share/OpenChemistry/Avogadro/commands"
"Checking for commands scripts in path /run/host/user-share/OpenChemistry/Avogadro/commands"
"Checking for commands scripts in path /run/host/share/OpenChemistry/Avogadro/commands"
"Checking for commands scripts in path /app/bin/../lib/avogadro2/scripts/commands"
"Checking for inputGenerators scripts in path /home/kevin/.var/app/org.openchemistry.Avogadro2/data/OpenChemistry/Avogadro/inputGenerators"
"Checking for inputGenerators scripts in path /app/share/OpenChemistry/Avogadro/inputGenerators"
"Checking for inputGenerators scripts in path /usr/share/OpenChemistry/Avogadro/inputGenerators"
"Checking for inputGenerators scripts in path /usr/share/runtime/share/OpenChemistry/Avogadro/inputGenerators"
"Checking for inputGenerators scripts in path /run/host/user-share/OpenChemistry/Avogadro/inputGenerators"
"Checking for inputGenerators scripts in path /run/host/share/OpenChemistry/Avogadro/inputGenerators"
"Checking for inputGenerators scripts in path /app/bin/../lib/avogadro2/scripts/inputGenerators"
"Checking for charges scripts in path /home/kevin/.var/app/org.openchemistry.Avogadro2/data/OpenChemistry/Avogadro/charges"
"Checking for charges scripts in path /app/share/OpenChemistry/Avogadro/charges"
"Checking for charges scripts in path /usr/share/OpenChemistry/Avogadro/charges"
"Checking for charges scripts in path /usr/share/runtime/share/OpenChemistry/Avogadro/charges"
"Checking for charges scripts in path /run/host/user-share/OpenChemistry/Avogadro/charges"
"Checking for charges scripts in path /run/host/share/OpenChemistry/Avogadro/charges"
"Checking for charges scripts in path /app/bin/../lib/avogadro2/scripts/charges"
[Detaching after fork from child process 104]
"Cannot load script /app/lib/avogadro2/scripts/charges/antechamber.py"
[Detaching after fork from child process 105]
"Cannot load script /app/lib/avogadro2/scripts/charges/xtb.py"
"Checking for formatScripts scripts in path /home/kevin/.var/app/org.openchemistry.Avogadro2/data/OpenChemistry/Avogadro/formatScripts"
"Checking for formatScripts scripts in path /app/share/OpenChemistry/Avogadro/formatScripts"
"Checking for formatScripts scripts in path /usr/share/OpenChemistry/Avogadro/formatScripts"
"Checking for formatScripts scripts in path /usr/share/runtime/share/OpenChemistry/Avogadro/formatScripts"
"Checking for formatScripts scripts in path /run/host/user-share/OpenChemistry/Avogadro/formatScripts"
"Checking for formatScripts scripts in path /run/host/share/OpenChemistry/Avogadro/formatScripts"
"Checking for formatScripts scripts in path /app/bin/../lib/avogadro2/scripts/formatScripts"
[Detaching after fork from child process 106]
[Detaching after fork from child process 107]
[Detaching after fork from child process 108]
[New Thread 0x7fffcbfff640 (LWP 109)]
[New Thread 0x7fffcb7fe640 (LWP 110)]
[New Thread 0x7fffcaffd640 (LWP 111)]
Open Babel formats ready: 142
/usr/include/c++/12.2.0/bits/stl_vector.h:1123: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.

Thread 1 "avogadro2" received signal SIGABRT, Aborted.
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
44 return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0;
(gdb) bt
#0 __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1 0x00007ffff5891273 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2 0x00007ffff583f04e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3 0x00007ffff58287fc in __GI_abort () at abort.c:79
#4 0x00007ffff5ce1f9d in std::__glibcxx_assert_fail (file=file@entry=0x7ffff69b8110 "/usr/include/c++/12.2.0/bits/stl_vector.h", line=line@entry=1123, 
    function=function@entry=0x7ffff69b9a30 "std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]", 
    condition=condition@entry=0x7ffff69b8000 "__n < this->size()") at ../../../../../libstdc++-v3/src/c++11/debug.cc:60
#5 0x00007ffff695c48c in std::vector<int, std::allocator<int> >::operator[] (this=<optimized out>, __n=<optimized out>) at /usr/include/c++/12.2.0/bits/stl_vector.h:1121
#6 std::vector<int, std::allocator<int> >::operator[] (this=<optimized out>, __n=<optimized out>) at /usr/include/c++/12.2.0/bits/stl_vector.h:1121
#7 Avogadro::Core::Graph::addEdge (this=this@entry=0x555555eb91d8, a=a@entry=0, b=b@entry=8) at /run/build/avogadrolibs/avogadrolibs/avogadro/core/graph.cpp:204
#8 0x00007ffff69757ff in Avogadro::Core::Molecule::addBond (this=0x555555eb9040, atom1=0, atom2=8, order=<optimized out>) at /run/build/avogadrolibs/avogadrolibs/avogadro/core/molecule.cpp:591
#9 0x00007ffff771d7c5 in QUndoStack::push (this=this@entry=0x555555e22cc0, cmd=<optimized out>, cmd@entry=0x555556a3b720) at util/qundostack.cpp:639
#10 0x00007ffff7f34eab in Avogadro::QtGui::RWMolecule::addBond (this=this@entry=0x555555e22ca0, atom1=atom1@entry=8, atom2=atom2@entry=0, order=<optimized out>) at /run/build/avogadrolibs/avogadrolibs/avogadro/qtgui/rwmolecule.cpp:273
#11 0x00007ffff7ac9c4f in Avogadro::QtGui::RWMolecule::addBond (order=<optimized out>, atom2=<synthetic pointer>..., atom1=<synthetic pointer>..., this=0x555555e22ca0) at /run/build/avogadrolibs/avogadrolibs/avogadro/qtgui/rwmolecule.h:769
#12 Avogadro::QtGui::RWMolecule::addBond (order=<optimized out>, atom2=<synthetic pointer>..., atom1=<synthetic pointer>..., this=<optimized out>) at /run/build/avogadrolibs/avogadrolibs/avogadro/qtgui/rwmolecule.h:763
#13 Avogadro::QtPlugins::Editor::atomLeftDrag (this=0x555555a8b210, e=<optimized out>) at /run/build/avogadrolibs/avogadrolibs/avogadro/qtplugins/editor/editor.cpp:596
#14 0x00007ffff7ac9fd0 in Avogadro::QtPlugins::Editor::mouseMoveEvent (this=0x555555a8b210, e=0x7fffffffca10) at /run/build/avogadrolibs/avogadrolibs/avogadro/qtplugins/editor/editor.cpp:180
#15 0x00007ffff7fb6da7 in Avogadro::QtOpenGL::GLWidget::mouseMoveEvent (this=0x555555a00710, e=0x7fffffffca10) at /run/build/avogadrolibs/avogadrolibs/avogadro/qtopengl/glwidget.cpp:270
#16 0x00007ffff73bce28 in QWidget::event (this=0x555555a00710, event=0x7fffffffca10) at kernel/qwidget.cpp:9045
#17 0x00007ffff737affe in QApplicationPrivate::notify_helper (this=this@entry=0x555555749560, receiver=receiver@entry=0x555555a00710, e=e@entry=0x7fffffffca10) at kernel/qapplication.cpp:3640
#18 0x00007ffff7383592 in QApplication::notify (this=<optimized out>, receiver=0x555555a00710, e=<optimized out>) at kernel/qapplication.cpp:3084
#19 0x00007ffff62ced98 in QCoreApplication::notifyInternal2 (receiver=0x555555a00710, event=0x7fffffffca10) at kernel/qcoreapplication.cpp:1064
#20 0x00007ffff738169e in QApplicationPrivate::sendMouseEvent (receiver=receiver@entry=0x555555a00710, event=event@entry=0x7fffffffca10, alienWidget=<optimized out>, nativeWidget=0x7fffffffd1c0, buttonDown=buttonDown@entry=0x7ffff78c29f0 <qt_button_down>, 
    lastMouseReceiver=..., spontaneous=true, onlyDispatchEnterLeave=false) at kernel/qapplication.cpp:2622
#21 0x00007ffff73d5c5e in QWidgetWindow::handleMouseEvent (this=0x55555602e2b0, event=0x7fffffffccc0) at kernel/qwidgetwindow.cpp:684
#22 0x00007ffff73d9100 in QWidgetWindow::event (this=0x55555602e2b0, event=0x7fffffffccc0) at kernel/qwidgetwindow.cpp:300
#23 0x00007ffff737affe in QApplicationPrivate::notify_helper (this=<optimized out>, receiver=0x55555602e2b0, e=0x7fffffffccc0) at kernel/qapplication.cpp:3640
#24 0x00007ffff62ced98 in QCoreApplication::notifyInternal2 (receiver=0x55555602e2b0, event=0x7fffffffccc0) at kernel/qcoreapplication.cpp:1064
#25 0x00007ffff6b571bd in QGuiApplicationPrivate::processMouseEvent (e=0x55555609ac40) at kernel/qguiapplication.cpp:2278
#26 0x00007ffff6b2a0bc in QWindowSystemInterface::sendWindowSystemEvents (flags=flags@entry=...) at kernel/qwindowsysteminterface.cpp:1169
#27 0x00007fffed50992a in xcbSourceDispatch (source=source@entry=0x555555800e80) at qxcbeventdispatcher.cpp:105
#28 0x00007ffff3320d71 in g_main_dispatch (context=0x7fffe8005010) at ../glib/gmain.c:3419
#29 g_main_context_dispatch (context=0x7fffe8005010) at ../glib/gmain.c:4137
#30 0x00007ffff3377028 in g_main_context_iterate.constprop.0 (context=context@entry=0x7fffe8005010, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:4213
#31 0x00007ffff331e4a3 in g_main_context_iteration (context=0x7fffe8005010, may_block=1) at ../glib/gmain.c:4278
#32 0x00007ffff6326ae6 in QEventDispatcherGlib::processEvents (this=0x5555557f47b0, flags=...) at kernel/qeventdispatcher_glib.cpp:423
#33 0x00007ffff62cd80b in QEventLoop::exec (this=this@entry=0x7fffffffd000, flags=..., flags@entry=...) at ../../include/QtCore/../../src/corelib/global/qflags.h:69
#34 0x00007ffff62d5976 in QCoreApplication::exec () at ../../include/QtCore/../../src/corelib/global/qflags.h:121
#35 0x00007ffff6b4ac2c in QGuiApplication::exec () at kernel/qguiapplication.cpp:1863
#36 0x00007ffff737af75 in QApplication::exec () at kernel/qapplication.cpp:2832
#37 0x000055555556de13 in main (argc=<optimized out>, argv=<optimized out>) at /run/build/Avogadro2/Avogadro2/avogadro/avogadro.cpp:258
(gdb)

```

---

<div class="post-metadata">

**Author:** ![ghutchis](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/ghutchis/32/456_2.png) [@ghutchis](https://discuss.avogadro.cc/u/ghutchis)\
**Post date:** [November 19, 2023, 2:15am UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/10 "2023-11-19T02:15:46Z")

</div>

Thanks, that’s very helpful. I’ll take a look through the `addBond` code and the editor and see if I can figure out the trigger.

---

<div class="post-metadata">

**Author:** ![kevinsmia1939](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/kevinsmia1939/32/786_2.png) [@kevinsmia1939](https://discuss.avogadro.cc/u/kevinsmia1939)\
**Post date:** [November 19, 2023, 2:31am UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/11 "2023-11-19T02:31:43Z")

</div>

The build configurations can be found in the org.openchemistry.Avogadro2.yaml file in this repo which I enable the debuginfo. [GitHub - kevinsmia1939/org.openchemistry.Avogadro2](https://github.com/kevinsmia1939/org.openchemistry.Avogadro2/tree/master)

---

<div class="post-metadata">

**Author:** ![aeonik](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/aeonik/32/2252_2.png) [@aeonik](https://discuss.avogadro.cc/u/aeonik)\
**Post date:** [September 4, 2024, 5:01pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/12 "2024-09-04T17:01:08Z")

</div>

I ran into this issue today from a build that I did from HEAD.

This happens when I copy a section of my molecule and paste it back in. I do this in order to duplicate sections, for example when building polymers.

Avogadro **crashes** as soon as I try to connect the bonds of the **pasted** molecule **to** the **original** molecule.

Notably, it does **NOT crash** when I connect the bond from the **original** molecule **to** the newly **pasted** molecule.

This is the backtrace I got:

```auto
Error starting RPC server: "QLocalServer::listen: Address in use"                                                                                                                                                                                              
Starting new server.
Open Babel formats ready: 145
[New Thread 0x7fffb6a006c0 (LWP 2116424)]
[New Thread 0x7fffb60006c0 (LWP 2116425)]
[New Thread 0x7fffb56006c0 (LWP 2116426)]
/usr/include/c++/14.2.1/bits/stl_vector.h:1130: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.

Thread 1 "avogadro2" received signal SIGABRT, Aborted.
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
44 return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0;
(gdb) bt
#0 __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1 0x00007ffff5ca5463 in __pthread_kill_internal (threadid=<optimized out>, signo=6) at pthread_kill.c:78
#2 0x00007ffff5c4c120 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3 0x00007ffff5c334c3 in __GI_abort () at abort.c:79
#4 0x00007ffff5ed3bb0 in std::__glibcxx_assert_fail
    (file=file@entry=0x7ffff710e8f8 "/usr/include/c++/14.2.1/bits/stl_vector.h", line=line@entry=1130, function=function@entry=0x7ffff70e8c98 "std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]", condition=condition@entry=0x7ffff70de294 "__n < this->size()") at /usr/src/debug/gcc/gcc/libstdc++-v3/src/c++11/assert_fail.cc:41
#5 0x00007ffff712e0ab in std::vector<int, std::allocator<int> >::operator[] (this=<optimized out>, __n=<optimized out>) at /usr/include/c++/14.2.1/bits/stl_vector.h:1128
#6 std::vector<int, std::allocator<int> >::operator[] (this=<optimized out>, __n=<optimized out>) at /usr/include/c++/14.2.1/bits/stl_vector.h:1128
#7 Avogadro::Core::Graph::addEdge (this=this@entry=0x555555d78760, a=<optimized out>, a@entry=8, b=<optimized out>, b@entry=14) at /tmp/makepkg/avogadrolibs-git/src/avogadrolibs/avogadro/core/graph.cpp:204
#8 0x00007ffff7150648 in Avogadro::Core::Molecule::addBond (this=0x555555d78590, atom1=8, atom2=14, order=<optimized out>) at /tmp/makepkg/avogadrolibs-git/src/avogadrolibs/avogadro/core/molecule.cpp:677
#9 0x00007ffff76feaaa in QUndoStack::push(QUndoCommand*) () at /usr/lib/libQt5Widgets.so.5
#10 0x00007ffff7ee1ab5 in Avogadro::QtGui::RWMolecule::addBond (this=this@entry=0x555555d53360, atom1=atom1@entry=14, atom2=atom2@entry=8, order=1 '\001') at /tmp/makepkg/avogadrolibs-git/src/avogadrolibs/avogadro/qtgui/rwmolecule.cpp:274

```

---

<div class="post-metadata">

**Author:** ![ghutchis](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/ghutchis/32/456_2.png) [@ghutchis](https://discuss.avogadro.cc/u/ghutchis)\
**Post date:** [September 4, 2024, 5:27pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/13 "2024-09-04T17:27:16Z")

</div>

Thanks, that’s helpful although I can’t reproduce it.

You said you ran your own build. Can you try a Debug build … it looks like some of the key hints in the backtrace are optimized out.

---

<div class="post-metadata">

**Author:** ![aeonik](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/aeonik/32/2252_2.png) [@aeonik](https://discuss.avogadro.cc/u/aeonik)\
**Post date:** [September 5, 2024, 8:32pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/14 "2024-09-05T20:32:29Z")

</div>

I rebuilt Avogadroapp with debugging on, but in the process I also found out that my build was accidentally linking to my system version of Avogadrolibs 1.99.0-356-g96c13db8.

I built the entire OpenChemistry source tree and ran it from the separate build directory as mentioned here [Building Source Code — Avogadro 1.99.0 documentation](https://two.avogadro.cc/install/build.html), and it appears the bug was fixed in the latest versions of Avogadrolibs.

---

<div class="post-metadata">

**Author:** ![aeonik](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/aeonik/32/2252_2.png) [@aeonik](https://discuss.avogadro.cc/u/aeonik)\
**Post date:** [September 6, 2024, 8:53pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/15 "2024-09-06T20:53:37Z")

</div>

Sorry to bring this up again, but I was mistaken.

I fixed up some linking issues I had, and the issue came back again, but I am narrowing down the root cause, and it has to do with some optimizations that are set on my Arch Linux system.

It seems when I set `-D_GLIBCXX_ASSERTIONS` in the **CXXFLAGS** it causes this issue. On Arch Linux this was enabled in my package manager.

I can send a message the Arch Linux folks to change this, but I am not sure if this is a compiler bug, Avogadro bug, or what at this point. I caught in the debugger as well. Picture attached.

 ![Screenshot_20240906_0429EDT](https://discuss.avogadro.cc/uploads/default/original/2X/0/0cd70ee0c0229251c85c21ddaaa36d5d12334ff9.png)

Avogadro seems to run perfectly fine without this compiler flag.

These were all of my flags:

```auto
CFLAGS="-march=native -O2 -pipe -fno-plt -fexceptions \
        -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \
        -fstack-clash-protection -fcf-protection"
CXXFLAGS="$CFLAGS -Wp,-D_GLIBCXX_ASSERTIONS"
LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fuse-ld=mold"
LTOFLAGS="-flto=auto"

```

I can now reproduce it 100% of the time in CLion.

This is the most stubborn bug I have ever tracked down. It has taken me a week to narrow it down.

This is the backtrace from gdb:

```auto
(gdb) bt
#0 0x00007ffff0ca53f4 in ??? () at /usr/lib/libc.so.6
#1 0x00007ffff0c4c120 in raise () at /usr/lib/libc.so.6
#2 0x00007ffff0c334c3 in abort () at /usr/lib/libc.so.6
#3 0x00007fffec2d3bb0 in std::__glibcxx_assert_fail (file=<optimized out>, line=<optimized out>, function=<optimized out>, condition=<optimized out>) at /usr/src/debug/gcc/gcc/libstdc++-v3/src/c++11/assert_fail.cc:41
#4 0x00007ffff598e500 in std::vector<int, std::allocator<int> >::operator[] (this=0x555555d732c8, __n=22) at /usr/include/c++/14.2.1/bits/stl_vector.h:1130
#5 0x00007ffff599bdbc in Avogadro::Core::Graph::addEdge (this=0x555555d73290, a=1, b=11) at /home/dave/git/openchemistry/avogadrolibs/avogadro/core/graph.cpp:227
#6 0x00007ffff59bedb7 in Avogadro::Core::Molecule::addBond (this=0x555555d730c0, atom1=1, atom2=11, order=1 '\001') at /home/dave/git/openchemistry/avogadrolibs/avogadro/core/molecule.cpp:677
#7 0x00007ffff7460d48 in Avogadro::QtGui::Molecule::addBond (this=0x555555d730b0, atomId1=1, atomId2=11, order=1 '\001') at /home/dave/git/openchemistry/avogadrolibs/avogadro/qtgui/molecule.cpp:175
#8 0x00007ffff7473ee7 in Avogadro::QtGui::(anonymous namespace)::AddBondCommand::redo (this=0x555555736620) at /home/dave/git/openchemistry/avogadrolibs/avogadro/qtgui/rwmolecule_undo.h:407
#9 0x00007ffff6efeaaa in QUndoStack::push(QUndoCommand*) () at /usr/lib/libQt5Widgets.so.5

```

I also have a coredump but it’s pretty huge (2.3GB), and I don’t seem to be able to attach it, nor any compressed version of it here.

Regards,  
Aeonik

---

<div class="post-metadata">

**Author:** ![aeonik](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/aeonik/32/2252_2.png) [@aeonik](https://discuss.avogadro.cc/u/aeonik)\
**Post date:** [September 6, 2024, 9:08pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/16 "2024-09-06T21:08:07Z")

</div>

Posted on Arch Linux forums here:  
[https://bbs.archlinux.org/viewtopic.php?pid=2194502#p2194502](https://bbs.archlinux.org/viewtopic.php?pid=2194502#p2194502)

---

<div class="post-metadata">

**Author:** ![ghutchis](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/ghutchis/32/456_2.png) [@ghutchis](https://discuss.avogadro.cc/u/ghutchis)\
**Post date:** [September 6, 2024, 9:18pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/17 "2024-09-06T21:18:59Z")

</div>

> [@aeonik](#):
>
> I can now reproduce it 100% of the time in CLion.

Can you tell me a bit about what you’re doing in Avogadro? Like how many atoms are in each fragment? Could you upload the fragment or the file before the crash?

It looks like it’s trying to add a bond from atom 11 to atom 1, so it’s going to the various `addBond` and finally `addEdge` in the graph.cpp code.

That code is attempting to merge the two subgraphs (e.g., disconnected fragments):

```auto
    for (size_t i : m_subgraphToVertices[subgraphB]) {
      m_subgraphToVertices[subgraphA].insert(i);
      m_vertexToSubgraph[i] = subgraphA;
    }

```

The line in question would be `m_vertexToSubgraph[i]` … which would make me think that `i` is an invalid index in `m_vertexToSubgraph`.

---

<div class="post-metadata">

**Author:** ![aeonik](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/aeonik/32/2252_2.png) [@aeonik](https://discuss.avogadro.cc/u/aeonik)\
**Post date:** [September 6, 2024, 11:58pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/18 "2024-09-06T23:58:58Z")

</div>

Dr. Hutchison,  
I am attempting to build a Polypropylene polymer, I am interested in the electrical potential of the molecular orbits.

I use the drawing tool for the first three carbon atoms, copy the monomer (forgive me if I use the incorrect terminology, I only took high school chemistry). After I create the monomer, I copy and paste it, then connect the pasted carbon atom back to the original monomer.

You can see the screenshot attached showing the moment right before the crash.

 ![Screenshot_Untitled• - Avogadro 1.99.0-25-ga705453_20240906_0753EDT-1](https://discuss.avogadro.cc/uploads/default/original/2X/2/2392f6b8fd084717c334bd6635738dafe19d7a82.png)

Regards,  
Aeonik

---

<div class="post-metadata">

**Author:** ![ghutchis](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/ghutchis/32/456_2.png) [@ghutchis](https://discuss.avogadro.cc/u/ghutchis)\
**Post date:** [September 7, 2024, 8:48pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/19 "2024-09-07T20:48:26Z")

</div>

Awesome. I can now reproduce this on an Ubuntu image with `-Wp,-D_GLIBCXX_ASSERTIONS`

I’ll go take a look at the underlying cause. 🙂

Based on other bug reports on GitHub, you’re not the only one seeing this crash.

---

<div class="post-metadata">

**Author:** ![ghutchis](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/ghutchis/32/456_2.png) [@ghutchis](https://discuss.avogadro.cc/u/ghutchis)\
**Post date:** [September 7, 2024, 9:37pm UTC](https://discuss.avogadro.cc/t/crash-when-dragging-atom-over-other-atom-to-create-bond/4964/20 "2024-09-07T21:37:54Z")

</div>

Give this patch a try – seems to work for some limited testing:

> <https://github.com/OpenChemistry/avogadrolibs/pull/1704>
>
> Fixes bug from @aeonik
> https://discuss.avogadro.cc/t/crash-when-dragging-atom-o…ver-other-atom-to-create-bond/4964/18
> 
> Developer Certificate of Origin
> Version 1.1
> 
> Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
> 1 Letterman Drive
> Suite D4700
> San Francisco, CA, 94129
> 
> Everyone is permitted to copy and distribute verbatim copies of this
> license document, but changing it is not allowed.
> 
> 
> Developer's Certificate of Origin 1.1
> 
> By making a contribution to this project, I certify that:
> 
> (a) The contribution was created in whole or in part by me and I
> have the right to submit it under the open source license
> indicated in the file; or
> 
> (b) The contribution is based upon previous work that, to the best
> of my knowledge, is covered under an appropriate open source
> license and I have the right under that license to submit that
> work with modifications, whether created in whole or in part
> by me, under the same open source license (unless I am
> permitted to submit under a different license), as indicated
> in the file; or
> 
> (c) The contribution was provided directly to me by some other
> person who certified (a), (b) or (c) and I have not modified
> it.
> 
> (d) I understand and agree that this project and the contribution
> are public and that a record of the contribution (including all
> personal information I submit with it, including my sign-off) is
> maintained indefinitely and may be redistributed consistent with
> this project or the open source license(s) involved.

I’m not 100% sure why it gets into this condition, but this it at least good defensive programming.
