Using a custom C++ extension with python
<p>I have a problem with this code:
</p>

<pre><code>#include "PolyVoxCore/MaterialDensityPair.h"
#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h"
#include "PolyVoxCore/SurfaceMesh.h"
#include "PolyVoxCore/SimpleVolume.h"

#include "geomVertexData.h"
#include "geomVertexWriter.h"
#include "geomTriangles.h"
#include "py_panda.h"
#include "pandaNode.h"
#include "geomNode.h"

//Use the PolyVox namespace
using namespace PolyVox;
using namespace std;

static void createSphereInVolume(SimpleVolume&lt;MaterialDensityPair44&gt;&amp; volData, float fRadius)
{
        //This vector hold the position of the center of the volume
        Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);

        //This three-level for loop iterates over every voxel in the volume
        for (int z = 0; z &lt; volData.getWidth(); z++)
        {
                for (int y = 0; y &lt; volData.getHeight(); y++)
                {
                        for (int x = 0; x &lt; volData.getDepth(); x++)
                        {
                                //Store our current position as a vector...
                                Vector3DFloat v3dCurrentPos(x,y,z);    
                                //And compute how far the current position is from the center of the volume
                                float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();

                                uint8_t uDensity = 0;
                                uint8_t uMaterial = 0;

                                //If the current voxel is less than 'radius' units from the center then we make it solid.
                                if(fDistToCenter &lt;= fRadius)
                                {
                                        //Our new density value
                                        uDensity = VoxelTypeTraits&lt;MaterialDensityPair44&gt;::maxDensity();
                                        uMaterial = 1;
                                }

                                //Get the old voxel
                                MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z);

                                //Modify the density and material
                                voxel.setDensity(uDensity);
                                voxel.setMaterial(uMaterial);

                                //Write the voxel value into the volume
                                volData.setVoxelAt(x, y, z, voxel);
                        }
                }
        }
}

static PyObject* CreateSphere(PyObject* self, PyObject* args)
{
        PyObject* pandaNodeWrapper;
        if (!PyArg_ParseTuple(args, "0", &amp;pandaNodeWrapper))
                return NULL;


        //Create an empty volume and then place a sphere in it
        SimpleVolume&lt;MaterialDensityPair44&gt; volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
        createSphereInVolume(volData, 30);

        //Extract the surface
        SurfaceMesh&lt;PositionMaterialNormal&gt; mesh;
        CubicSurfaceExtractorWithNormals&lt;SimpleVolume, MaterialDensityPair44 &gt; surfaceExtractor(&amp;volData, volData.getEnclosingRegion(), &amp;mesh);
        surfaceExtractor.execute();
        const vector&lt;PositionMaterialNormal&gt;&amp; vertices = mesh.getVertices();
        const vector&lt;uint32_t&gt;&amp; indices = mesh.getIndices();

        CPT(GeomVertexFormat) vertexFormat = GeomVertexFormat::get_v3n3();
        PT(GeomVertexData) vertexData = new GeomVertexData("ProceduralMesh", vertexFormat, GeomEnums::UH_static);

        GeomVertexWriter vertex, normal;

        vertex = GeomVertexWriter(vertexData, "vertex");
        normal = GeomVertexWriter(vertexData, "normal");

        for(vector&lt;PositionMaterialNormal&gt;::const_iterator it = vertices.begin(); it != vertices.end(); ++it)
        {
                vertex.add_data3f(it-&gt;position.getX(), it-&gt;position.getY(), it-&gt;position.getZ());
                normal.add_data3f(it-&gt;normal.getX(), it-&gt;position.getY(), it-&gt;position.getZ());
        }

        PT(GeomTriangles) chunk = new GeomTriangles(GeomEnums::UH_static);

        for(int i = 0; i &lt; indices.size(); ++i)
        {
                chunk-&gt;add_vertex(indices[i]);
        }

        PT(Geom) geom = new Geom(vertexData);
        geom-&gt;add_primitive(chunk);

        PT(GeomNode) geomNode = new GeomNode("chunk");

        PandaNode* node = ((PandaNode*)((Dtool_PyInstDef*)pandaNodeWrapper)-&gt;_ptr_to_object);
        node-&gt;add_child(geomNode);

        Py_RETURN_NONE;
}

static PyMethodDef module_methods[] = {
        {"CreateSphere", CreateSphere, METH_VARARGS, "CreateSphere"},
        {NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC
initpolyvox(void)
{
        (void) Py_InitModule("polyvox", module_methods);
}
</code></pre>

<p>It's a c++ extension module i'm trying to write, i used the setup.py method to compile it and install it, the problem is that when i import it in python and run it, python says "SystemError: dynamic module not initialized properly".</p>

<p>I know that this error should be that module name doesn't correspond with the init function name, but it isn't like that if you see the code. So what could be the problem?</p>

<p>I'm on Windows 7, using python 2.7.2, the module is compiled on VS2008 but it requires some .lib i had to compile with vs2010 since some modern c++ features are required.</p>
