cadquery icon indicating copy to clipboard operation
cadquery copied to clipboard

One line that simply crashes all RAM memory

Open filaPro opened this issue 1 year ago • 7 comments

import cadquery as cq
cq.Workplane().sketch().push([(48.5800789794081,-3.3737790291878085)]).rect(3.0,87.6847679284009).rect(3.0,88.65465934289723).polygon([(0,0),(1,1),(2,2)],mode="s").finalize().extrude(1)

cadquery==2.4.0 is installed throw pip

filaPro avatar Sep 11 '24 15:09 filaPro

Please show the output of pip list and tell us which OS you're on.

jmwright avatar Sep 11 '24 15:09 jmwright

thank you for quick response. i'm inside docker with ubuntu 22.04.3. the host os outside docker is ubuntu 20.04.6

Package                   Version
------------------------- --------------
accelerate                0.31.0
addict                    2.4.0
aiohttp                   3.9.5
aiosignal                 1.3.1
anaconda-anon-usage       0.4.4
antlr4-python3-runtime    4.9.3
anyio                     4.4.0
archspec                  0.2.3
argon2-cffi               23.1.0
argon2-cffi-bindings      21.2.0
arrow                     1.3.0
asttokens                 2.0.5
astunparse                1.6.3
async-lru                 2.0.4
async-timeout             4.0.3
attrs                     23.1.0
Babel                     2.15.0
beautifulsoup4            4.12.3
bleach                    6.1.0
blinker                   1.8.2
boltons                   23.0.0
Brotli                    1.0.9
cadquery                  2.4.0
cadquery-ocp              7.7.2
casadi                    3.6.5
certifi                   2024.6.2
cffi                      1.16.0
chardet                   4.0.0
charset-normalizer        2.0.4
click                     8.1.7
comm                      0.2.2
conda                     24.5.0
conda-build               24.3.0
conda-content-trust       0.2.0
conda_index               0.5.0
conda-libmamba-solver     24.1.0
conda-package-handling    2.3.0
conda_package_streaming   0.10.0
ConfigArgParse            1.7
contourpy                 1.2.1
cryptography              42.0.5
cycler                    0.12.1
Cython                    3.0.10
dash                      2.17.1
dash-core-components      2.0.0
dash-html-components      2.0.0
dash-table                5.0.0
datasets                  2.20.0
debugpy                   1.8.2
decorator                 5.1.1
defusedxml                0.7.1
dill                      0.3.8
distro                    1.9.0
dnspython                 2.6.1
easydict                  1.13
einops                    0.8.0
exceptiongroup            1.2.0
executing                 0.8.3
expecttest                0.2.1
ezdxf                     1.3.1
fastjsonschema            2.20.0
filelock                  3.13.1
flash-attn                2.5.9.post1
Flask                     3.0.3
fonttools                 4.53.0
fqdn                      1.5.1
frozendict                2.4.2
frozenlist                1.4.1
fsspec                    2024.5.0
gmpy2                     2.1.2
h11                       0.14.0
httpcore                  1.0.5
httpx                     0.27.0
huggingface-hub           0.23.4
hypothesis                6.103.0
idna                      3.7
importlib_metadata        8.0.0
ipykernel                 6.29.4
ipython                   8.20.0
ipywidgets                8.1.3
isoduration               20.11.0
itsdangerous              2.2.0
jedi                      0.18.1
Jinja2                    3.1.4
joblib                    1.4.2
json5                     0.9.25
jsonpatch                 1.33
jsonpointer               2.1
jsonschema                4.19.2
jsonschema-specifications 2023.7.1
jupyter                   1.0.0
jupyter_client            8.6.2
jupyter-console           6.6.3
jupyter_core              5.7.2
jupyter-events            0.10.0
jupyter-lsp               2.2.5
jupyter_server            2.14.1
jupyter_server_terminals  0.5.3
jupyterlab                4.2.3
jupyterlab_pygments       0.3.0
jupyterlab_server         2.27.2
jupyterlab_widgets        3.0.11
kiwisolver                1.4.5
lark                      1.1.9
libarchive-c              2.9
libmambapy                1.5.8
lightning                 2.3.1
lightning-utilities       0.11.3.post0
MarkupSafe                2.1.3
matplotlib                3.9.0
matplotlib-inline         0.1.6
menuinst                  2.1.0
michelangelo              0.4.1
mistune                   3.0.2
mkl-fft                   1.3.8
mkl-random                1.2.4
mkl-service               2.4.0
more-itertools            10.1.0
mpmath                    1.3.0
multidict                 6.0.5
multimethod               1.9.1
multiprocess              0.70.16
nbclient                  0.10.0
nbconvert                 7.16.4
nbformat                  5.10.4
nest-asyncio              1.6.0
networkx                  3.2.1
nlopt                     2.7.1
notebook                  7.2.1
notebook_shim             0.2.4
nptyping                  2.0.1
numpy                     1.26.4
omegaconf                 2.3.0
open3d                    0.18.0
optree                    0.11.0
overrides                 7.7.0
packaging                 23.2
pandas                    2.2.2
pandocfilters             1.5.1
parso                     0.8.3
path                      16.14.0
peft                      0.11.1
pexpect                   4.8.0
pillow                    10.3.0
pip                       24.0
pkginfo                   1.10.0
platformdirs              3.10.0
plotly                    5.22.0
pluggy                    1.0.0
pointnet2_cuda            0.0.0
prometheus_client         0.20.0
prompt-toolkit            3.0.43
psutil                    5.9.0
ptyprocess                0.7.0
pure-eval                 0.2.2
pyarrow                   16.1.0
pyarrow-hotfix            0.6
pycosat                   0.6.6
pycparser                 2.21
Pygments                  2.15.1
pyparsing                 3.1.2
pyquaternion              0.9.9
PySocks                   1.7.1
python-dateutil           2.9.0.post0
python-etcd               0.4.5
python-json-logger        2.0.7
pytorch-lightning         2.3.1
pytz                      2024.1
PyYAML                    6.0.1
pyzmq                     26.0.3
qtconsole                 5.5.2
QtPy                      2.4.1
referencing               0.30.2
regex                     2024.5.15
requests                  2.32.2
retrying                  1.3.4
rfc3339-validator         0.1.4
rfc3986-validator         0.1.1
rpds-py                   0.10.6
ruamel.yaml               0.17.21
ruamel.yaml.clib          0.2.6
safetensors               0.4.3
scikit-learn              1.5.0
scipy                     1.14.0
Send2Trash                1.8.3
setuptools                69.5.1
shortuuid                 1.0.13
six                       1.16.0
sniffio                   1.3.1
sortedcontainers          2.4.0
soupsieve                 2.5
stack-data                0.2.0
svgwrite                  1.4.3
sympy                     1.12.1
tenacity                  8.4.2
termcolor                 2.4.0
terminado                 0.18.1
threadpoolctl             3.5.0
tinycss2                  1.3.0
tokenizers                0.19.1
tomli                     2.0.1
torch                     2.3.1
torchaudio                2.3.1
torchelastic              0.2.2
torchmetrics              1.4.0.post0
torchvision               0.18.1
tornado                   6.4.1
tqdm                      4.66.4
traitlets                 5.14.3
transformers              4.42.3
trimesh                   4.4.9
triton                    2.3.1
truststore                0.8.0
types-dataclasses         0.6.6
types-python-dateutil     2.9.0.20240316
typing_extensions         4.11.0
typish                    1.9.3
tzdata                    2024.1
uri-template              1.3.0
urllib3                   2.2.2
wcwidth                   0.2.5
webcolors                 24.6.0
webencodings              0.5.1
websocket-client          1.8.0
Werkzeug                  3.0.3
wheel                     0.43.0
widgetsnbextension        4.0.11
xxhash                    3.4.1
yarl                      1.9.4
zipp                      3.19.2
zstandard                 0.22.0

filaPro avatar Sep 11 '24 15:09 filaPro

if you are not able to reproduce this, i can try to make minimal reproducible docker image

filaPro avatar Sep 11 '24 15:09 filaPro

It does not look like the polygon is closed, so the cause could be extruding an open/invalid sketch. If you remove the polygon call, and leave everything else, it works fine. One of the core devs who has worked more directly on the sketch feature can tell you more.

jmwright avatar Sep 11 '24 16:09 jmwright

thank you again for your response. i also investigated that the problem is about the polygon with zero area. what i expect is to get an exception, but not like dying os due to out of memory. for example this line cq.Worplane().sketch().polygon([(0,0),(1,1),(2,2)],mode="s").finalize().extrude(1) produces ValueError: Null TopoDS_Shape object, and it is fine.

filaPro avatar Sep 11 '24 16:09 filaPro

Sometimes you'll get these kind of issues with invalid models. Here is a workaround:

import cadquery as cq
res = (
       cq.Workplane()
       .sketch()
       .push([(48.5800789794081,-3.3737790291878085)])
       .rect(3.0,87.6847679284009)
       .rect(3.0,88.65465934289723)
       .polygon([(0,0),(1,1),(2,2)],mode="s")
       .finalize()
       .extrude(1, clean=False)
)

Note that:

import OCP
OCP.BRepAlgoAPI.BRepAlgoAPI_Check(res.val().wrapped).IsValid()

results in

Out[8]: False

adam-urbanczyk avatar Sep 12 '24 18:09 adam-urbanczyk

Thank you, i didn't know about this clean=False. Believe the memory leak will be fixed in future releases of cadquery or occ.

filaPro avatar Sep 13 '24 11:09 filaPro