CadQuery / CQ-editor

CadQuery GUI editor based on PyQT
Apache License 2.0
777 stars 120 forks source link

Crash on cq.Solid.extrudeLinearWithRotation() #286

Open gumyr opened 3 years ago

gumyr commented 3 years ago

To Reproduce

While working on the creation of a thread library I discovered that cq-editor crashes on extrusions with rotation and was able to reproduce the problem with the following (note that FreeCad is able to open the generated step file which looks surprisingly good for such a rough approximation) :

import cadquery as cq

# Create a rough approximation of the perimeter of a cross section of a M3-0.5 screw
outer_wire = cq.Workplane("XY").circle(1.5).translate((0.2, 0, 0)).wires().val()
print(f"Is outer_wire valid? {outer_wire.isValid()}")  # True

thread_length = 5

# Extrude the wire back into thread
thread = cq.Solid.extrudeLinearWithRotation(
    outerWire=outer_wire,
    innerWires=[],
    vecCenter=cq.Vector(0, 0, 0),
    vecNormal=cq.Vector(0, 0, thread_length),
    angleDegrees=360 * (thread_length / 0.5),
)
print(f"Is thread valid? {thread.isValid()}")  # True

# Let's see what it looks like
cq.exporters.export(thread, "thread.step")

# What does cq-editor see?
if "show_object" in locals():
    show_object(outer_wire, name="outer_wire")
    show_object(thread, name="thread")

Environment

OS: Ubuntu 21.04

Output of conda list from your active Conda environment:

#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       1_gnu    conda-forge
alabaster                 0.7.12                     py_0    conda-forge
alsa-lib                  1.2.3                h516909a_0    conda-forge
appdirs                   1.4.4              pyh9f0ad1d_0    conda-forge
argh                      0.26.2          pyh9f0ad1d_1002    conda-forge
astroid                   2.6.2            py39hf3d152e_0    conda-forge
async_generator           1.10                       py_0    conda-forge
atomicwrites              1.4.0              pyh9f0ad1d_0    conda-forge
attrs                     21.2.0             pyhd8ed1ab_0    conda-forge
autopep8                  1.5.6              pyhd8ed1ab_0    conda-forge
babel                     2.9.1              pyh44b312d_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
black                     19.10b0                    py_4    conda-forge
bleach                    3.3.0              pyh44b312d_0    conda-forge
brotlipy                  0.7.0           py39h3811e60_1001    conda-forge
build                     0.5.1                    pypi_0    pypi
bzip2                     1.0.8                h7f98852_4    conda-forge
c-ares                    1.17.1               h7f98852_1    conda-forge
ca-certificates           2021.5.30            ha878542_0    conda-forge
cadquery                  master                    py3.9    cadquery
certifi                   2021.5.30        py39hf3d152e_0    conda-forge
cffi                      1.14.5           py39he32792d_0    conda-forge
chardet                   4.0.0            py39hf3d152e_1    conda-forge
click                     8.0.1            py39hf3d152e_0    conda-forge
cloudpickle               1.6.0                      py_0    conda-forge
codecov                   2.1.11             pyhd3deb0d_0    conda-forge
colorama                  0.4.4              pyh9f0ad1d_0    conda-forge
coverage                  5.5              py39h3811e60_0    conda-forge
cq-editor                 master                    py3.9    cadquery
cq-warehouse              0.1.0                     dev_0    <develop>
cryptography              3.4.7            py39hbca0aa6_0    conda-forge
curl                      7.77.0               hea6ffbf_0    conda-forge
dbus                      1.13.6               h48d8840_2    conda-forge
debugpy                   1.3.0            py39he80948d_0    conda-forge
decorator                 5.0.9              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
diff-match-patch          20200713           pyh9f0ad1d_0    conda-forge
docutils                  0.16             py39hf3d152e_3    conda-forge
double-conversion         3.1.5                h9c3ff4c_2    conda-forge
eigen                     3.3.9                h4bd325d_1    conda-forge
entrypoints               0.3             pyhd8ed1ab_1003    conda-forge
expat                     2.4.1                h9c3ff4c_0    conda-forge
ezdxf                     0.16.3           py39h1a9c180_0    conda-forge
ffmpeg                    4.3.1                hca11adc_2    conda-forge
flake8                    3.8.4                      py_0    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.13.1            hba837de_1005    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
freeimage                 3.18.0               h88c329d_7    conda-forge
freetype                  2.10.4               h0708190_1    conda-forge
future                    0.18.2           py39hf3d152e_3    conda-forge
gettext                   0.19.8.1          h0b5b191_1005    conda-forge
gl2ps                     1.4.2                h0708190_0    conda-forge
glew                      2.1.0                h9c3ff4c_2    conda-forge
glib                      2.68.3               h9c3ff4c_0    conda-forge
glib-tools                2.68.3               h9c3ff4c_0    conda-forge
gmp                       6.2.1                h58526e2_0    conda-forge
gmpy2                     2.1.0b5          py39h78fa15d_0    conda-forge
gnutls                    3.6.13               h85f3911_1    conda-forge
gst-plugins-base          1.18.4               hf529b03_2    conda-forge
gstreamer                 1.18.4               h76c114f_2    conda-forge
hdf4                      4.2.15               h10796ff_3    conda-forge
hdf5                      1.10.6          nompi_h6a2412b_1114    conda-forge
icu                       68.1                 h58526e2_0    conda-forge
idna                      2.10               pyh9f0ad1d_0    conda-forge
ilmbase                   2.5.5                h780b84a_0    conda-forge
imagesize                 1.2.0                      py_0    conda-forge
importlib-metadata        4.6.1            py39hf3d152e_0    conda-forge
importlib_metadata        4.6.1                hd8ed1ab_0    conda-forge
iniconfig                 1.1.1              pyh9f0ad1d_0    conda-forge
intervaltree              3.0.2                      py_0    conda-forge
ipykernel                 6.0.1            py39hef51801_0    conda-forge
ipython                   7.24.1           py39hef51801_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
isort                     5.9.2              pyhd8ed1ab_0    conda-forge
jbig                      2.1               h7f98852_2003    conda-forge
jedi                      0.17.2           py39hf3d152e_1    conda-forge
jeepney                   0.7.0              pyhd8ed1ab_0    conda-forge
jinja2                    3.0.1              pyhd8ed1ab_0    conda-forge
jpeg                      9d                   h36c2ea0_0    conda-forge
jsoncpp                   1.9.4                h4bd325d_2    conda-forge
jsonschema                3.2.0              pyhd8ed1ab_3    conda-forge
jupyter_client            6.1.12             pyhd8ed1ab_0    conda-forge
jupyter_core              4.7.1            py39hf3d152e_0    conda-forge
jupyterlab_pygments       0.1.2              pyh9f0ad1d_0    conda-forge
jxrlib                    1.1                  h7f98852_2    conda-forge
keyring                   23.0.1           py39hf3d152e_0    conda-forge
krb5                      1.19.1               hcc1bbae_0    conda-forge
lame                      3.100             h7f98852_1001    conda-forge
lazy-object-proxy         1.6.0            py39h3811e60_0    conda-forge
lcms2                     2.12                 hddcbb42_0    conda-forge
ld_impl_linux-64          2.35.1               hea4e1c9_2    conda-forge
lerc                      2.2.1                h9c3ff4c_0    conda-forge
libblas                   3.9.0                9_openblas    conda-forge
libcblas                  3.9.0                9_openblas    conda-forge
libclang                  11.1.0          default_ha53f305_1    conda-forge
libcurl                   7.77.0               h2574ce0_0    conda-forge
libdeflate                1.7                  h7f98852_5    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 h516909a_1    conda-forge
libevent                  2.1.10               hcdb4288_3    conda-forge
libffi                    3.3                  h58526e2_2    conda-forge
libgcc-ng                 9.3.0               h2828fa1_19    conda-forge
libgfortran-ng            9.3.0               hff62375_19    conda-forge
libgfortran5              9.3.0               hff62375_19    conda-forge
libglib                   2.68.3               h3e27bee_0    conda-forge
libglu                    9.0.0             he1b5a44_1001    conda-forge
libgomp                   9.3.0               h2828fa1_19    conda-forge
libiconv                  1.16                 h516909a_0    conda-forge
liblapack                 3.9.0                9_openblas    conda-forge
libllvm11                 11.1.0               hf817b99_2    conda-forge
libnetcdf                 4.8.0           nompi_hcd642e3_103    conda-forge
libnghttp2                1.43.0               h812cca2_0    conda-forge
libogg                    1.3.4                h7f98852_1    conda-forge
libopenblas               0.3.15          pthreads_h8fe5266_1    conda-forge
libopus                   1.3.1                h7f98852_1    conda-forge
libpng                    1.6.37               h21135ba_2    conda-forge
libpq                     13.3                 hd57d9b9_0    conda-forge
libraw                    0.20.2               h10796ff_1    conda-forge
libsodium                 1.0.18               h36c2ea0_1    conda-forge
libspatialindex           1.9.3                h9c3ff4c_3    conda-forge
libssh2                   1.9.0                ha56f1ee_6    conda-forge
libstdcxx-ng              9.3.0               h6de172a_19    conda-forge
libtheora                 1.1.1             h7f98852_1005    conda-forge
libtiff                   4.3.0                hf544144_1    conda-forge
libuuid                   2.32.1            h7f98852_1000    conda-forge
libvorbis                 1.3.7                h9c3ff4c_0    conda-forge
libwebp-base              1.2.0                h7f98852_2    conda-forge
libxcb                    1.13              h7f98852_1003    conda-forge
libxkbcommon              1.0.3                he3ba5ed_0    conda-forge
libxml2                   2.9.12               h72842e0_0    conda-forge
libzip                    1.7.3                h4de3113_0    conda-forge
logbook                   1.5.3            py39h3811e60_4    conda-forge
loguru                    0.5.3            py39hf3d152e_2    conda-forge
lz4-c                     1.9.3                h9c3ff4c_0    conda-forge
markupsafe                2.0.1            py39h3811e60_0    conda-forge
matplotlib-inline         0.1.2              pyhd8ed1ab_2    conda-forge
mccabe                    0.6.1                      py_1    conda-forge
mistune                   0.8.4           py39h3811e60_1004    conda-forge
more-itertools            8.8.0              pyhd8ed1ab_0    conda-forge
mpc                       1.1.0             h04dde30_1009    conda-forge
mpfr                      4.0.2                he80fd80_1    conda-forge
mpmath                    1.2.1              pyhd8ed1ab_0    conda-forge
mypy                      0.910                    pypi_0    pypi
mypy-extensions           0.4.3                    pypi_0    pypi
mysql-common              8.0.25               ha770c72_2    conda-forge
mysql-libs                8.0.25               hfa10184_2    conda-forge
nbclient                  0.5.3              pyhd8ed1ab_0    conda-forge
nbconvert                 6.1.0            py39hf3d152e_0    conda-forge
nbformat                  5.1.3              pyhd8ed1ab_0    conda-forge
ncurses                   6.2                  h58526e2_4    conda-forge
nest-asyncio              1.5.1              pyhd8ed1ab_0    conda-forge
nettle                    3.6                  he412f7d_0    conda-forge
nlopt                     2.7.0            py39hf3b21e1_0    conda-forge
nptyping                  1.4.2              pyhd8ed1ab_0    conda-forge
nspr                      4.30                 h9c3ff4c_0    conda-forge
nss                       3.67                 hb5efdd6_0    conda-forge
numpy                     1.20.3           py39hdbf815f_1    conda-forge
numpydoc                  1.1.0                      py_1    conda-forge
occt                      7.5.1                h7391655_2    conda-forge
ocp                       7.5.1beta               1_py3.9    cadquery
openexr                   2.5.5                hf817b99_0    conda-forge
openh264                  2.1.1                h780b84a_0    conda-forge
openjpeg                  2.4.0                hb52868f_1    conda-forge
openssl                   1.1.1k               h7f98852_0    conda-forge
packaging                 20.9               pyh44b312d_0    conda-forge
pandas                    1.3.0            py39hde0f152_0    conda-forge
pandoc                    2.14.0.3             h7f98852_0    conda-forge
pandocfilters             1.4.2                      py_1    conda-forge
parso                     0.7.0              pyh9f0ad1d_0    conda-forge
path                      16.0.0           py39hf3d152e_0    conda-forge
path.py                   12.5.0                        0    conda-forge
pathspec                  0.8.1              pyhd3deb0d_0    conda-forge
pcre                      8.44                 he1b5a44_0    conda-forge
pep517                    0.10.0                   pypi_0    pypi
pexpect                   4.8.0              pyh9f0ad1d_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pip                       21.2.4                   pypi_0    pypi
pluggy                    0.13.1           py39hf3d152e_4    conda-forge
proj                      7.2.0                h277dcde_2    conda-forge
prompt-toolkit            3.0.18             pyha770c72_0    conda-forge
psutil                    5.8.0            py39h3811e60_1    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pugixml                   1.11.4               h9c3ff4c_0    conda-forge
py                        1.10.0             pyhd3deb0d_0    conda-forge
pycodestyle               2.6.0              pyh9f0ad1d_0    conda-forge
pycparser                 2.20               pyh9f0ad1d_2    conda-forge
pydantic                  1.8.2                    pypi_0    pypi
pydocstyle                6.1.1              pyhd8ed1ab_0    conda-forge
pyflakes                  2.2.0              pyh9f0ad1d_0    conda-forge
pygments                  2.9.0              pyhd8ed1ab_0    conda-forge
pylint                    2.9.3              pyhd8ed1ab_0    conda-forge
pyls-black                0.4.6              pyh9f0ad1d_0    conda-forge
pyls-spyder               0.3.2              pyhd8ed1ab_0    conda-forge
pyopenssl                 20.0.1             pyhd8ed1ab_0    conda-forge
pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
pyqt                      5.12.3           py39hf3d152e_7    conda-forge
pyqt-impl                 5.12.3           py39h0fcd23e_7    conda-forge
pyqt5-sip                 4.19.18          py39he80948d_7    conda-forge
pyqtchart                 5.12             py39h0fcd23e_7    conda-forge
pyqtgraph                 0.12.2             pyhd8ed1ab_0    conda-forge
pyqtwebengine             5.12.1           py39h0fcd23e_7    conda-forge
pyrsistent                0.17.3           py39h3811e60_2    conda-forge
pysocks                   1.7.1            py39hf3d152e_3    conda-forge
pytest                    6.2.4            py39hf3d152e_0    conda-forge
pytest-cov                2.12.1             pyhd8ed1ab_0    conda-forge
python                    3.9.4           hffdb5ce_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-jsonrpc-server     0.4.0              pyh9f0ad1d_0    conda-forge
python-language-server    0.36.2             pyhd8ed1ab_0    conda-forge
python_abi                3.9                      1_cp39    conda-forge
pytz                      2021.1             pyhd8ed1ab_0    conda-forge
pyxdg                     0.27               pyhd8ed1ab_0    conda-forge
pyyaml                    5.4.1            py39h3811e60_0    conda-forge
pyzmq                     22.1.0           py39h37b5a0c_0    conda-forge
qdarkstyle                3.0.2              pyhd8ed1ab_0    conda-forge
qt                        5.12.9               hda022c4_4    conda-forge
qtawesome                 1.0.3              pyhd8ed1ab_0    conda-forge
qtconsole                 5.1.1              pyhd8ed1ab_0    conda-forge
qtpy                      1.9.0                      py_0    conda-forge
rapidjson                 1.1.0             he1b5a44_1002    conda-forge
readline                  8.1                  h46c0cb4_0    conda-forge
regex                     2021.7.6                 pypi_0    pypi
requests                  2.25.1             pyhd3deb0d_0    conda-forge
rope                      0.19.0             pyhd8ed1ab_0    conda-forge
rtree                     0.9.7            py39hb102c33_1    conda-forge
scipy                     1.6.3            py39hee8e79c_0    conda-forge
secretstorage             3.3.1            py39hf3d152e_0    conda-forge
setuptools                49.6.0           py39hf3d152e_3    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
snowballstemmer           2.1.0              pyhd8ed1ab_0    conda-forge
sortedcontainers          2.4.0              pyhd8ed1ab_0    conda-forge
sphinx                    4.0.3                    pypi_0    pypi
sphinx-autodoc-typehints  1.12.0             pyhd8ed1ab_0    conda-forge
sphinx_rtd_theme          0.5.2              pyhd8ed1ab_1    conda-forge
sphinxcadquery            1.3.3                    pypi_0    pypi
sphinxcontrib-applehelp   1.0.2                      py_0    conda-forge
sphinxcontrib-devhelp     1.0.2                      py_0    conda-forge
sphinxcontrib-htmlhelp    2.0.0              pyhd8ed1ab_0    conda-forge
sphinxcontrib-jsmath      1.0.1                      py_0    conda-forge
sphinxcontrib-qthelp      1.0.3                      py_0    conda-forge
sphinxcontrib-serializinghtml 1.1.5              pyhd8ed1ab_0    conda-forge
spyder                    4.2.1            py39hf3d152e_3    conda-forge
spyder-kernels            1.10.2           py39hf3d152e_0    conda-forge
sqlite                    3.35.5               h74cdb3f_0    conda-forge
sympy                     1.8              py39hf3d152e_0    conda-forge
tbb                       2020.2               h4bd325d_4    conda-forge
tbb-devel                 2020.2               h4bd325d_4    conda-forge
testpath                  0.5.0              pyhd8ed1ab_0    conda-forge
textdistance              4.2.1              pyhd8ed1ab_0    conda-forge
three-merge               0.1.1              pyh9f0ad1d_0    conda-forge
tk                        8.6.10               h21135ba_1    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tornado                   6.1              py39h3811e60_1    conda-forge
traitlets                 5.0.5                      py_0    conda-forge
typed-ast                 1.4.3            py39h3811e60_0    conda-forge
typing_extensions         3.10.0.0           pyha770c72_0    conda-forge
typish                    1.9.2              pyhd8ed1ab_0    conda-forge
tzdata                    2021a                he74cb21_0    conda-forge
ujson                     4.0.2            py39he80948d_0    conda-forge
urllib3                   1.26.5             pyhd8ed1ab_0    conda-forge
utfcpp                    3.2.1                ha770c72_0    conda-forge
vtk                       9.0.1           no_osmesa_py39h801044d_109    conda-forge
watchdog                  2.1.3            py39hf3d152e_0    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.36.2             pyhd3deb0d_0    conda-forge
wrapt                     1.12.1           py39h3811e60_3    conda-forge
wurlitzer                 2.1.0            py39hf3d152e_0    conda-forge
x264                      1!161.3030           h7f98852_0    conda-forge
xorg-kbproto              1.0.7             h7f98852_1002    conda-forge
xorg-libice               1.0.10               h7f98852_0    conda-forge
xorg-libsm                1.2.3             hd9c2040_1000    conda-forge
xorg-libx11               1.7.2                h7f98852_0    conda-forge
xorg-libxau               1.0.9                h7f98852_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xorg-libxext              1.3.4                h7f98852_1    conda-forge
xorg-libxt                1.2.1                h7f98852_2    conda-forge
xorg-xextproto            7.3.0             h7f98852_1002    conda-forge
xorg-xproto               7.0.31            h7f98852_1007    conda-forge
xz                        5.2.5                h516909a_1    conda-forge
yaml                      0.2.5                h516909a_0    conda-forge
yapf                      0.31.0             pyhd8ed1ab_0    conda-forge
zeromq                    4.3.4                h9c3ff4c_0    conda-forge
zipp                      3.5.0              pyhd8ed1ab_0    conda-forge
zlib                      1.2.11            h516909a_1010    conda-forge
zstd                      1.5.0                ha95c52a_0    conda-forge
lorenzncode commented 3 years ago

Hi, I tested this script. I see that CQ-Editor memory usage continues to increase until process exit.

CQ-Editor was able to display the part after increasing the Deviation value in 3D Viewer settings: Deviation: 0.01 Angular deviation: 0.1

The very large memory usage case for me was with default Deviation 1e-5.

gumyr commented 3 years ago

Thanks! When I change Deviation to 0.01 my "real" threads are visible in cq-editor again. I'll put a note in the documentation for my thread library that this value should be changed. Is the only downside a slight drop in viewing fidelity?

Cheers, Roger

On Thu, Aug 26, 2021 at 7:43 AM Lorenz @.***> wrote:

Hi, I tested this script. I see that CQ-Editor memory usage continues to increase until process exit.

CQ-Editor was able to display the part after increasing the Deviation value in 3D Viewer settings: Deviation: 0.01 Angular deviation: 0.1

The very large memory usage case for me was with default Deviation 1e-5.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/CadQuery/CQ-editor/issues/286#issuecomment-906334693, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUNL25SJJQH7JWZ2IA2LAADT6YSHDANCNFSM5CZN723A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

lorenzncode commented 3 years ago

Yes, I think that's right - it should be a render issue. The trace, while this is running, is in Tessellate, and @adam-urbanczyk mentioned increasing Deviation when a similar render problem came up in discord.

A few test results:

Deviation Time RSS peak
1.5e-5 ~1m45s ~8.3GB
2e-5 ~45s ~5GB
1e-4 ~10s ~1.4GB
1e-3 ~5s ~1GB
gumyr commented 3 years ago

Wow, that;s a big difference. I've used ray tracers that render pixelated images to start and then recursively refine the image to eventually get to the final result. If the same was done here those first few loops would take relatively no time at all.

Thanks for the help, Roger

On Thu, Aug 26, 2021 at 5:28 PM Lorenz @.***> wrote:

Yes, I think that's right - it should be a render issue. The trace, while this is running, is in Tessellate, and @adam-urbanczyk https://github.com/adam-urbanczyk mentioned increasing Deviation when a similar render problem came up in discord.

A few test results: Deviation Time RSS peak 1.5e-5 ~1m45s ~8.3GB 2e-5 ~45s ~5GB 1e-4 ~10s ~1.4GB 1e-3 ~5s ~1GB

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/CadQuery/CQ-editor/issues/286#issuecomment-906755575, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUNL25WLZU3M6F2NQH4QFZLT62WX5ANCNFSM5CZN723A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.