Packaging solution: (ana)conda

I find the decision a bit strange of these commits
https://github.com/looooo/netgen/commit/335148a503876d4a32ffe875977772e8e2144cdf#diff-f7119c8415a40c338427c480bffff981
https://github.com/looooo/netgen/commit/69429c6e09506111054c13a753f2c7f3a630c30c#diff-f7119c8415a40c338427c480bffff981
because it causes quite some problems on code depending on it.

Especially the removal of creating a new mesh inside OCCGenerateMesh changes its semantic. You should re-enable the change to create a new mesh.

// delete mesh;
mesh = make_shared<Mesh>();

But isn’t the old way more strange? (Creating a new mesh inside of netgen which is used outside the library.) When should the mesh be deleted?
Why not create an instance of the mesh inside of smesh netgen-plugin? something like this:

#if NETGEN_VERSION >=6
        _ngMesh = new netgen::Mesh();
        std::shared_ptr<netgen::Mesh> mesh_ptr(_ngMesh,  [](netgen::Mesh*){});
        err = netgen::OCCGenerateMesh(occgeo, mesh_ptr, mparams, startWith, endWith);

The proper solution would be to transform all _ngMesh to shared pointers, but I don’t want to get too deep into this smesh stuff.

ps.: the delete would be also needed. So you’r solution should be the better one. I will ask the creator of netgen to make this change.

I have tried to un-un-comment the line you have mentioned. No crash but also no mesh.
Could it be that the pointer used in smesh netgen plugin is still a Nullptr?


_ngMesh=NULL;
shared_ptr<Mesh> mesh_ptr(_ngMesh,  [](Mesh*){});
mesh_ptr = make_shared<Mesh>();
mesh_ptr.get() == _ngMesh //????

Could it be that the pointer used in smesh netgen plugin is still a Nullptr?

Unlikely. What I can imagine is that netgen itself is broken and never fills up the mesh or that an non-empty mesh is replaced with an empty mesh somewhere in the smesh sources.

Hmm, but have a look at this example: creating a shared pointer with std::make_shared seems to create not only a new instance but also a new raw-pointer.

#include <memory>
#include <iostream>

class A
{
};

int main()
{
	A* a;
	a = NULL;
	std::shared_ptr<A> a_ptr(a,  [](A*){});
	a_ptr =  std::make_shared<A>();
	std::cout << (a_ptr.get() == a) << ", " << (a == NULL) << std::endl;
	return 0;
}

save as test.cpp and build with:

 g++ -std=c++11 -o test test.cpp

this will return:

 0, 1

trying the other method cause a crash. This is how I have tried to solve the problem:
https://github.com/looooo/FreeCAD/blob/occ_patch/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_Mesher.cpp#L2507

#0  0x00007ffff3d28418 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007ffff3d2a01a in __GI_abort () at abort.c:89
#2  0x00007ffff3d6a72a in __libc_message (do_abort=2, fmt=fmt@entry=0x7ffff3e836b0 "*** Error in `%s': %s: 0x%s ***\n")
    at ../sysdeps/posix/libc_fatal.c:175
#3  0x00007ffff3d749be in malloc_printerr (ar_ptr=0x7ffff40b6b20 <main_arena>, ptr=0x2ab2a50, str=0x7ffff3e8051f "malloc(): memory corruption", 
    action=<optimized out>) at malloc.c:5007
#4  _int_malloc (av=av@entry=0x7ffff40b6b20 <main_arena>, bytes=bytes@entry=184) at malloc.c:3475
#5  0x00007ffff3d765a4 in __GI___libc_malloc (bytes=184) at malloc.c:2914
#6  0x00007ffff4360be8 in operator new(unsigned long) () from /home/lo/anaconda/envs/fc_2/bin/../lib/libstdc++.so.6
#7  0x00007fff5c506aff in netgen::Mesh::Mesh (this=0x2ab26e0)
    at /home/lo/anaconda/conda-bld/._1473527418209/work/libsrc/meshing/meshclass.cpp:31
#8  0x00007fff5e4ecd23 in NETGENPlugin_Mesher::Compute (this=0x7fffffff9570) from /home/lo/anaconda/envs/fc_2/lib/./libNETGENPlugin.so
#9  0x00007fff5e5212c0 in NETGENPlugin_NETGEN_2D::Compute (this=0x2815220, aMesh=..., aShape=...)
   from /home/lo/anaconda/envs/fc_2/lib/./libNETGENPlugin.so

Whats wrong with the new statement?

it’s not possible to call new netgen::Mesh inside of the smesh netgen-plugin. This will always have memory corruption. But with the new netgen interface we will have to construct the mesh within the smesh netgen-plugin. I have no idea how to make this work. Maybe there is missing an include??? https://github.com/looooo/FreeCAD/blob/master/src/3rdParty/salomesmesh/inc/NETGENPlugin_Mesher.hxx#L42

PS.: with the addition from wmayer to netgen I have now a working netgen6.1 :smiley:

Thanks guys for this.
@looo is this the correct netgen sources? https://github.com/looooo/netgen

@sgrogan, this version should work.
I am compiling with this options:

 
      -DUSE_OCC=ON \
      -DUSE_PYTHON=OFF \
      -DUSE_GUI=ON \

And then your FreeCAD until your pull request is merged? https://github.com/looooo/FreeCAD/commits/netgen6.1_interface

It should also work to disable GUI of netgen because it won’t be used anyway.

      -DUSE_OCC=ON \
      -DUSE_PYTHON=OFF \
      -DUSE_GUI=OFF \

exactly.

In the meanwhile I have uploaded a new conda-freecad package with all the new stuff: https://anaconda.org/freecad/freecad
There is one problem that some libraries are used from the distro. And if a distro uses a too old libstdc library the conda approach won’t work. So for example debian jessie wasn’t working the last time I have tried this. A solution could be to use an older distro (eg. debian jessie) to compile freecad…

version info for the current freecad conda package:
OS: Ubuntu 16.04.1 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.8432 (Git)
Build type: Release
Branch: netgen6.1_interface
Hash: 6a962c9bc686ff970ede0ceac9b3423227ede236
Python version: 2.7.12
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.0.0

I have tried this too, but disabling the gui wasn’t working for me. (Linking errors, or something like this) I had the feeling that disabling the gui isn’t really tested.

some updates:

  • the linux conda packages are now created with a virgin ubuntu 14.04 and should run on most linux version. Tested are 14.04, 16.04, arch. Still looking for testers on other platforms…

  • as the python3 branch from yorik was currently updated, and hopefully get merged soon I have tried to get into building this branch. Python3 still make some troubles, but the python2 builds from the python3 branch is also available on conda (package:freecad_py3 but build with py2)

  • conda-forge will make python3.5 pyside windows builds available: (https://github.com/conda-forge/qt-feedstock/issues/6). This are very good news for us as it will solve some problems with python and windows. Also it makes the port to python3 not dependent on pyside2/qt5. And current problems with netgen should be solved with the python3 port…

  • Started with windows builds. But I need help with this. Maybe some one familiar with building latest source with vtk7 occt7 on windows could help with this. Trying to build occt7 (https://github.com/looooo/FreeCAD_Conda/blob/master/occt/bld.bat) failed with this error:

CMake Error at CMakeLists.txt:559 (message):
  NOT FOUND: 3RDPARTY_VTK_INCLUDE_DIR 3RDPARTY_VTK_LIBRARY_DIR
  3RDPARTY_VTK_DLL_DIR

We don’t need vtk visualization stuff with OCCT. use

-DUSE_VTK=OFF ^

which is the default I think.

thanks.
Now I get some errors with cmake:

CMake Error: INSTALL(EXPORT) given unknown export "OpenCASCADEFoundationClassesTargets"
CMake Error: INSTALL(EXPORT) given unknown export "OpenCASCADEModelingDataTargets"
CMake Error: INSTALL(EXPORT) given unknown export "OpenCASCADEModelingAlgorithmsTargets"
CMake Error: INSTALL(EXPORT) given unknown export "OpenCASCADEVisualizationTargets"
CMake Error: INSTALL(EXPORT) given unknown export "OpenCASCADEDataExchangeTargets"
CMake Error: INSTALL(EXPORT) given unknown export "OpenCASCADEDrawTargets"

Do you have access to CmakeCache.txt in the build folder?
Can you detail the whole build environment?
(ana/mini)conda
Win version, native or VM
python 2.7 or 3.5
C++ compiler
Are you building locally or on a build server?

You are definitely drawing me in :slight_smile: The whole build system looks like what PeterL94 was doing with CLBundler. The more I learn about this the more I like it!

-(ana/mini)conda
I am using miniconda3.5 but it is not important which conda version is used. You can always specify the python version (conda build . --python=3.5). But for windows only python3 makes sense so it’s simpler to use the python3.5 conda…

-channels:
with adding the conda-forge channels more packages are available:
conda config --add channels conda-forge

-win_vesion:
Windows 8.1 enterprise 64 bit. builds are made locally on a university pc. I would like to get the builds running first locally for all systems and then try to get all packages we need one by one into the conda-forge project… I don’t know if it is possible with the bigger ones (freecad, occt), but coin, pivy and others should work.

-compiler:

-- The C compiler identification is MSVC 17.0.50727.1
-- The CXX compiler identification is MSVC 17.0.50727.1

-package list for occt:

certifi:        2016.8.31-py35_0  conda-forge
expat:          2.1.0-vc14_2      conda-forge [vc14]
freetype:       2.6.3-vc14_1      conda-forge [vc14]
future:         0.15.2-py35_0     conda-forge
jpeg:           9b-vc14_0         conda-forge [vc14]
libiconv:       1.14-vc14_3       conda-forge [vc14]
libpng:         1.6.24-vc14_0     conda-forge [vc14]
libtiff:        4.0.6-vc14_6      conda-forge [vc14]
libxml2:        2.9.4-vc14_1      conda-forge [vc14]
ninja:          1.7.1-0           conda-forge
pip:            8.1.2-py35_0      conda-forge
python:         3.5.2-2           conda-forge
setuptools:     26.1.1-py35_0     conda-forge
tk:             8.6.6-vc14_3      conda-forge [vc14]
vc:             14-0              conda-forge
vs2008_runtime: 9.00.30729.1-2
vs2015_runtime: 14.0.25420-0      conda-forge
vtk:            7.0.0-py35_vc14_2 conda-forge [vc14]
wheel:          0.29.0-py35_0     conda-forge
wincertstore:   0.2-py35_0        conda-forge
zlib:           1.2.8-vc14_3      conda-forge [vc14]

I can’t find any cmakecache file. (First time on windows after 4 years :smiley: . locate doesn’t work)

Maybe the error occurs because tk isn’t found.

-- src/TKernel directory is not included
-- src/TKMath directory is not included
-- src/TKG2d directory is not included
-- src/TKG3d directory is not included...

I have now added tk as dependency of occt but still no success.

ps.: forund the cmake_cache:
CMakeCache.txt (20.2 KB)

tcl is also a dependency and I don’t see a tcl package. Is it possible tcl is included in the tk package? They seem to always go together. They are separate in the libpack.

Also in cmakecache.txt line 187

CMAKE_LINKER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/link.exe

tcl is also a dependency and I don’t see a tcl package. Is it possible tcl is included in the tk package? They seem to always go together. They are separate in the libpack.

tcl is included with tk. https://github.com/conda-forge/tk-feedstock/issues/3

I think there is no linker provided by conda. So cmake uses the default one. This is the same on linux. But I have no idea if the linker should have the same version.