Cycles: some tweaks to silence msvc assertions in debug mode.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 3 Oct 2011 15:31:45 +0000 (15:31 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 3 Oct 2011 15:31:45 +0000 (15:31 +0000)
intern/cycles/blender/blender_mesh.cpp
intern/cycles/bvh/bvh.cpp
intern/cycles/device/device_network.h
intern/cycles/render/attribute.h
intern/cycles/render/mesh.cpp
intern/cycles/util/util_cache.h

index f981be66eb41041407d6499f8b8143d881edc899..6e99b380c295a984815151150c037304385d6055 100644 (file)
@@ -268,9 +268,10 @@ Mesh *BlenderSync::sync_mesh(BL::Object b_ob, bool object_updated)
 
        vector<Mesh::Triangle> oldtriangle = mesh->triangles;
 
 
        vector<Mesh::Triangle> oldtriangle = mesh->triangles;
 
+
        mesh->clear();
        mesh->used_shaders = used_shaders;
        mesh->clear();
        mesh->used_shaders = used_shaders;
-       mesh->name = ustring(b_ob_data.name());
+       mesh->name = ustring(b_ob_data.name().c_str());
 
        if(b_mesh) {
                if(cmesh.data && RNA_boolean_get(&cmesh, "use_subdivision"))
 
        if(b_mesh) {
                if(cmesh.data && RNA_boolean_get(&cmesh, "use_subdivision"))
@@ -299,8 +300,10 @@ Mesh *BlenderSync::sync_mesh(BL::Object b_ob, bool object_updated)
 
        if(oldtriangle.size() != mesh->triangles.size())
                rebuild = true;
 
        if(oldtriangle.size() != mesh->triangles.size())
                rebuild = true;
-       else if(memcmp(&oldtriangle[0], &mesh->triangles[0], sizeof(Mesh::Triangle)*oldtriangle.size()) != 0)
-               rebuild = true;
+       else if(oldtriangle.size()) {
+               if(memcmp(&oldtriangle[0], &mesh->triangles[0], sizeof(Mesh::Triangle)*oldtriangle.size()) != 0)
+                       rebuild = true;
+       }
        
        mesh->tag_update(scene, rebuild);
 
        
        mesh->tag_update(scene, rebuild);
 
index 3be1f822ed77bf5669c91cca5f3904d74a72e846..cd3ad70981251871d6aaabe2e909e9281462d386 100644 (file)
@@ -314,11 +314,11 @@ void BVH::pack_instances(size_t nodes_size)
        pack.nodes.resize(nodes_size);
        pack.object_node.resize(objects.size());
 
        pack.nodes.resize(nodes_size);
        pack.object_node.resize(objects.size());
 
-       int *pack_prim_index = &pack.prim_index[0];
-       int *pack_prim_object = &pack.prim_object[0];
-       uint *pack_prim_visibility = &pack.prim_visibility[0];
-       float4 *pack_tri_woop = &pack.tri_woop[0];
-       int4 *pack_nodes = &pack.nodes[0];
+       int *pack_prim_index = (pack.prim_index.size())? &pack.prim_index[0]: NULL;
+       int *pack_prim_object = (pack.prim_object.size())? &pack.prim_object[0]: NULL;
+       uint *pack_prim_visibility = (pack.prim_visibility.size())? &pack.prim_visibility[0]: NULL;
+       float4 *pack_tri_woop = (pack.tri_woop.size())? &pack.tri_woop[0]: NULL;
+       int4 *pack_nodes = (pack.nodes.size())? &pack.nodes[0]: NULL;
 
        /* merge */
        foreach(Object *ob, objects) {
 
        /* merge */
        foreach(Object *ob, objects) {
@@ -355,7 +355,7 @@ void BVH::pack_instances(size_t nodes_size)
                mesh_map[mesh] = pack.object_node[object_offset-1];
 
                /* merge primitive and object indexes */
                mesh_map[mesh] = pack.object_node[object_offset-1];
 
                /* merge primitive and object indexes */
-               {
+               if(bvh->pack.prim_index.size()) {
                        size_t bvh_prim_index_size = bvh->pack.prim_index.size();
                        int *bvh_prim_index = &bvh->pack.prim_index[0];
                        uint *bvh_prim_visibility = &bvh->pack.prim_visibility[0];
                        size_t bvh_prim_index_size = bvh->pack.prim_index.size();
                        int *bvh_prim_index = &bvh->pack.prim_index[0];
                        uint *bvh_prim_visibility = &bvh->pack.prim_visibility[0];
@@ -369,14 +369,14 @@ void BVH::pack_instances(size_t nodes_size)
                }
 
                /* merge triangle intersection data */
                }
 
                /* merge triangle intersection data */
-               {
+               if(bvh->pack.tri_woop.size()) {
                        memcpy(pack_tri_woop+pack_tri_woop_offset, &bvh->pack.tri_woop[0],
                                bvh->pack.tri_woop.size()*sizeof(float4));
                        pack_tri_woop_offset += bvh->pack.tri_woop.size();
                }
 
                /* merge nodes */
                        memcpy(pack_tri_woop+pack_tri_woop_offset, &bvh->pack.tri_woop[0],
                                bvh->pack.tri_woop.size()*sizeof(float4));
                        pack_tri_woop_offset += bvh->pack.tri_woop.size();
                }
 
                /* merge nodes */
-               {
+               if( bvh->pack.nodes.size()) {
                        size_t nsize_bbox = (use_qbvh)? nsize-2: nsize-1;
                        int4 *bvh_nodes = &bvh->pack.nodes[0];
                        size_t bvh_nodes_size = bvh->pack.nodes.size(); 
                        size_t nsize_bbox = (use_qbvh)? nsize-2: nsize-1;
                        int4 *bvh_nodes = &bvh->pack.nodes[0];
                        size_t bvh_nodes_size = bvh->pack.nodes.size(); 
index 775517586d328ce490a7a5a32907ce2cf17a155c..3cdb70bb4dfccab6646996969ed857f1cefaa38a 100644 (file)
@@ -125,7 +125,7 @@ typedef struct RPCReceive {
                                size_t len = boost::asio::read(socket, boost::asio::buffer(data));
 
                                if(len == data_size) {
                                size_t len = boost::asio::read(socket, boost::asio::buffer(data));
 
                                if(len == data_size) {
-                                       archive_str = string(&data[0], data.size());
+                                       archive_str = (data.size())? string(&data[0], data.size()): string("");
                                        /*istringstream archive_stream(archive_str);
                                        boost::archive::text_iarchive archive(archive_stream);*/
                                        archive_stream = new istringstream(archive_str);
                                        /*istringstream archive_stream(archive_str);
                                        boost::archive::text_iarchive archive(archive_stream);*/
                                        archive_stream = new istringstream(archive_str);
index a1c3d2b6ae7045f1b4125e19177719748eccca2c..aef215d6c0c77f1d4969e1981bced22ae3e09ef1 100644 (file)
@@ -73,13 +73,13 @@ public:
        size_t element_size(int numverts, int numfaces);
        size_t buffer_size(int numverts, int numfaces);
 
        size_t element_size(int numverts, int numfaces);
        size_t buffer_size(int numverts, int numfaces);
 
-       char *data() { return &buffer[0]; };
-       float3 *data_float3() { return (float3*)&buffer[0]; }
-       float *data_float() { return (float*)&buffer[0]; }
+       char *data() { return (buffer.size())? &buffer[0]: NULL; };
+       float3 *data_float3() { return (float3*)data(); }
+       float *data_float() { return (float*)data(); }
 
 
-       const char *data() const { return &buffer[0]; }
-       const float3 *data_float3() const { return (float3*)&buffer[0]; }
-       const float *data_float() const { return (float*)&buffer[0]; }
+       const char *data() const { return (buffer.size())? &buffer[0]: NULL; }
+       const float3 *data_float3() const { return (float3*)data(); }
+       const float *data_float() const { return (float*)data(); }
 
        static bool same_storage(TypeDesc a, TypeDesc b);
        static ustring standard_name(Attribute::Standard std);
 
        static bool same_storage(TypeDesc a, TypeDesc b);
        static ustring standard_name(Attribute::Standard std);
index 7a6ce547486f6515d4525baa649509d633d246fb..ac07ee8e89f87e518488c9a82b839fa6eac262c9 100644 (file)
@@ -115,17 +115,20 @@ void Mesh::add_face_normals()
        float3 *fN = attr_fN->data_float3();
 
        /* compute face normals */
        float3 *fN = attr_fN->data_float3();
 
        /* compute face normals */
-       float3 *verts_ptr = &verts[0];
        size_t triangles_size = triangles.size();
        size_t triangles_size = triangles.size();
-       Triangle *triangles_ptr = &triangles[0];
 
 
-       for(size_t i = 0; i < triangles_size; i++) {
-               Triangle t = triangles_ptr[i];
-               float3 v0 = verts_ptr[t.v[0]];
-               float3 v1 = verts_ptr[t.v[1]];
-               float3 v2 = verts_ptr[t.v[2]];
+       if(triangles_size) {
+               float3 *verts_ptr = &verts[0];
+               Triangle *triangles_ptr = &triangles[0];
+
+               for(size_t i = 0; i < triangles_size; i++) {
+                       Triangle t = triangles_ptr[i];
+                       float3 v0 = verts_ptr[t.v[0]];
+                       float3 v1 = verts_ptr[t.v[1]];
+                       float3 v2 = verts_ptr[t.v[2]];
 
 
-               fN[i] = normalize(cross(v1 - v0, v2 - v0));
+                       fN[i] = normalize(cross(v1 - v0, v2 - v0));
+               }
        }
 }
 
        }
 }
 
@@ -143,15 +146,18 @@ void Mesh::add_vertex_normals()
        float3 *vN = attr_vN->data_float3();
 
        /* compute vertex normals */
        float3 *vN = attr_vN->data_float3();
 
        /* compute vertex normals */
-       memset(&vN[0], 0, verts.size()*sizeof(float3));
+       memset(vN, 0, verts.size()*sizeof(float3));
 
        size_t verts_size = verts.size();
        size_t triangles_size = triangles.size();
 
        size_t verts_size = verts.size();
        size_t triangles_size = triangles.size();
-       Triangle *triangles_ptr = &triangles[0];
 
 
-       for(size_t i = 0; i < triangles_size; i++)
-               for(size_t j = 0; j < 3; j++)
-                       vN[triangles_ptr[i].v[j]] += fN[i];
+       if(triangles_size) {
+               Triangle *triangles_ptr = &triangles[0];
+
+               for(size_t i = 0; i < triangles_size; i++)
+                       for(size_t j = 0; j < 3; j++)
+                               vN[triangles_ptr[i].v[j]] += fN[i];
+       }
 
        for(size_t i = 0; i < verts_size; i++)
                vN[i] = normalize(vN[i]);
 
        for(size_t i = 0; i < verts_size; i++)
                vN[i] = normalize(vN[i]);
@@ -169,7 +175,7 @@ void Mesh::pack_normals(Scene *scene, float4 *normal, float4 *vnormal)
        bool last_smooth = false;
 
        size_t triangles_size = triangles.size();
        bool last_smooth = false;
 
        size_t triangles_size = triangles.size();
-       uint *shader_ptr = &shader[0];
+       uint *shader_ptr = (shader.size())? &shader[0]: NULL;
 
        for(size_t i = 0; i < triangles_size; i++) {
                normal[i].x = fN[i].x;
 
        for(size_t i = 0; i < triangles_size; i++) {
                normal[i].x = fN[i].x;
@@ -195,24 +201,30 @@ void Mesh::pack_normals(Scene *scene, float4 *normal, float4 *vnormal)
 void Mesh::pack_verts(float4 *tri_verts, float4 *tri_vindex, size_t vert_offset)
 {
        size_t verts_size = verts.size();
 void Mesh::pack_verts(float4 *tri_verts, float4 *tri_vindex, size_t vert_offset)
 {
        size_t verts_size = verts.size();
-       float3 *verts_ptr = &verts[0];
 
 
-       for(size_t i = 0; i < verts_size; i++) {
-               float3 p = verts_ptr[i];
-               tri_verts[i] = make_float4(p.x, p.y, p.z, 0.0f);
+       if(verts_size) {
+               float3 *verts_ptr = &verts[0];
+
+               for(size_t i = 0; i < verts_size; i++) {
+                       float3 p = verts_ptr[i];
+                       tri_verts[i] = make_float4(p.x, p.y, p.z, 0.0f);
+               }
        }
 
        size_t triangles_size = triangles.size();
        }
 
        size_t triangles_size = triangles.size();
-       Triangle *triangles_ptr = &triangles[0];
 
 
-       for(size_t i = 0; i < triangles_size; i++) {
-               Triangle t = triangles_ptr[i];
+       if(triangles_size) {
+               Triangle *triangles_ptr = &triangles[0];
 
 
-               tri_vindex[i] = make_float4(
-                       __int_as_float(t.v[0] + vert_offset),
-                       __int_as_float(t.v[1] + vert_offset),
-                       __int_as_float(t.v[2] + vert_offset),
-                       0);
+               for(size_t i = 0; i < triangles_size; i++) {
+                       Triangle t = triangles_ptr[i];
+
+                       tri_vindex[i] = make_float4(
+                               __int_as_float(t.v[0] + vert_offset),
+                               __int_as_float(t.v[1] + vert_offset),
+                               __int_as_float(t.v[2] + vert_offset),
+                               0);
+               }
        }
 }
 
        }
 }
 
@@ -428,7 +440,8 @@ void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene,
                        /* todo: get rid of this exception */
                        if(!mattr && req.std == Attribute::STD_GENERATED) {
                                mattr = mesh->attributes.add(Attribute::STD_GENERATED);
                        /* todo: get rid of this exception */
                        if(!mattr && req.std == Attribute::STD_GENERATED) {
                                mattr = mesh->attributes.add(Attribute::STD_GENERATED);
-                               memcpy(mattr->data_float3(), &mesh->verts[0], sizeof(float3)*mesh->verts.size());
+                               if(mesh->verts.size())
+                                       memcpy(mattr->data_float3(), &mesh->verts[0], sizeof(float3)*mesh->verts.size());
                        }
 
                        /* attribute not found */
                        }
 
                        /* attribute not found */
index 25b1f2e7a51663eb65ac5f5ee3db9383aefcd112..91e8a94a58423ebd0fbc11a9be68dfbf2a42b8c9 100644 (file)
@@ -57,20 +57,26 @@ public:
 
        template<typename T> void add(const vector<T>& data)
        {
 
        template<typename T> void add(const vector<T>& data)
        {
-               CacheBuffer buffer(&data[0], data.size()*sizeof(T));
-               buffers.push_back(buffer);
+               if(data.size()) {
+                       CacheBuffer buffer(&data[0], data.size()*sizeof(T));
+                       buffers.push_back(buffer);
+               }
        }
 
        template<typename T> void add(const array<T>& data)
        {
        }
 
        template<typename T> void add(const array<T>& data)
        {
-               CacheBuffer buffer(&data[0], data.size()*sizeof(T));
-               buffers.push_back(buffer);
+               if(data.size()) {
+                       CacheBuffer buffer(&data[0], data.size()*sizeof(T));
+                       buffers.push_back(buffer);
+               }
        }
 
        void add(void *data, size_t size)
        {
        }
 
        void add(void *data, size_t size)
        {
-               CacheBuffer buffer(data, size);
-               buffers.push_back(buffer);
+               if(size) {
+                       CacheBuffer buffer(data, size);
+                       buffers.push_back(buffer);
+               }
        }
 
        void add(int& data)
        }
 
        void add(int& data)
@@ -94,6 +100,9 @@ public:
                        return;
                }
 
                        return;
                }
 
+               if(!size)
+                       return;
+
                data.resize(size/sizeof(T));
 
                if(!fread(&data[0], size, 1, f)) {
                data.resize(size/sizeof(T));
 
                if(!fread(&data[0], size, 1, f)) {