Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ccGuiPythonInstance.cpp and prevent crash #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chunibyo-wly
Copy link

Sometimes, removefromdb causes the Python plugin and CC software to crash.

Ubuntu 22.04
Python 3.11

image
image

After modification, the user can also use Python objects.
image
image

@tmontaigu
Copy link
Owner

Do you have an example that triggers the crash ?

@chunibyo-wly
Copy link
Author

chunibyo-wly commented Aug 29, 2024

Do you have an example that triggers the crash ?

Sorry about the missing information.
Here is the smallest example to reproduce.

And also, I am not sure if it is the evidence that I have found other people having met the same problem (refer this commit)

There might be three occasions,

  1. sometimes, deleting immediately crash the plugin and softwares.
  2. sometimes, deleting and adding works fine, but when I close the PyQt plugin, both of them crashes.
  3. last way to inccur it is that if reopened the plugin again , crash would trigger
import pycc, cccorelib
from PyQt5.QtCore import Qt
from PyQt5.QtCore import QEventLoop, pyqtSignal, QCoreApplication, pyqtSlot
from PyQt5.QtWidgets import (
    QLabel,
    QWidget,
    QVBoxLayout,
    QPushButton,
    QHBoxLayout,
    QMessageBox,
)

cc = pycc.GetInstance()


class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.init_ui()

    def init_ui(self):
        self.layout = QVBoxLayout()
        self.setLayout(self.layout)

        self.button = QPushButton("removeFromDB")
        self.button.clicked.connect(self.on_button_click)
        self.layout.addWidget(self.button)

    def closeEvent(self, event):
        event.accept()  # Close the window
        self.event_loop.quit()

    @pyqtSlot()
    def on_button_click(self):
        a = cc.getSelectedEntities()[0]
        # b = a.getScalarField(a.getScalarFieldIndexByName("Instance_ID")).asArray()
        ref_pcd = cccorelib.ReferenceCloud(a)
        for idx in range(a.size()):
            ref_pcd.addPointIndex(idx)
        selected = a.partialClone(ref_pcd)
        selected.setName('aaa')
        cc.addToDB(selected)
        cc.removeFromDB(a)


def _create_app_and_run():
    plugin_widget = MainWindow()
    plugin_widget.setWindowTitle("SBASE annotator")
    loop = QEventLoop()
    plugin_widget.show()
    plugin_widget.event_loop = loop
    cc.freezeUI(False)
    cc.updateUI()
    loop.exec_()


_create_app_and_run()```

@chunibyo-wly
Copy link
Author

Speaking of which, I found that the asArray command converting vector of scalar field to numpy array in batch sometimes return the wrong value, but if I used getitem to get value index by index, it could work as designed.

I am not sure what happened, while I am planning to debug it in the next month if I had time.

@chunibyo-wly
Copy link
Author

After experiements,
the flatpack installed version cloudcompare(v2.13.2), the results of py::array_t is right, but wrong value in the python side.

However, the compiled version of cloudcompare and pybind11 worked fine.
So it seemded an old issue of pybind11.

@rjanvier
Copy link
Contributor

rjanvier commented Sep 1, 2024

Hi. Thanks for the report. I update the beta channel of the flatpack on flathub. could you please give a try and tell me if it fixes your issue (at least for the py::array_t) ? thanks.

@tmontaigu
Copy link
Owner

I'm not quite sure removeFromDB is the problem, I have not run the full code you sent, onlye the

        a = cc.getSelectedEntities()[0]
        # b = a.getScalarField(a.getScalarFieldIndexByName("Instance_ID")).asArray()
        ref_pcd = cccorelib.ReferenceCloud(a)
        for idx in range(a.size()):
            ref_pcd.addPointIndex(idx)
        selected = a.partialClone(ref_pcd)
        selected.setName('aaa')
        cc.addToDB(selected)
        cc.removeFromDB(a)

part.
And barely got a crash in like 30+ runs of the function, and the crash stack trace did not point the removeFromDB

Also, the change proposed is not really a fix since it creates a memory leak

I'll try running the full example to see if it changes anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants