Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh_runtime.c
| Show All 27 Lines | |||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "BLI_math_geom.h" | #include "BLI_math_geom.h" | ||||
| #include "BLI_threads.h" | #include "BLI_threads.h" | ||||
| #include "BKE_bvhutils.h" | #include "BKE_bvhutils.h" | ||||
| #include "BKE_library.h" | |||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_mesh_runtime.h" | #include "BKE_mesh_runtime.h" | ||||
| #include "BKE_subdiv_ccg.h" | #include "BKE_subdiv_ccg.h" | ||||
| #include "BKE_shrinkwrap.h" | #include "BKE_shrinkwrap.h" | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Mesh Runtime Struct Utils | /** \name Mesh Runtime Struct Utils | ||||
| * \{ */ | * \{ */ | ||||
| static ThreadRWMutex loops_cache_lock = PTHREAD_RWLOCK_INITIALIZER; | static ThreadRWMutex loops_cache_lock = PTHREAD_RWLOCK_INITIALIZER; | ||||
| /** | /** | ||||
| * Default values defined at read time. | * Default values defined at read time. | ||||
| */ | */ | ||||
| void BKE_mesh_runtime_reset(Mesh *mesh) | void BKE_mesh_runtime_reset(Mesh *mesh) | ||||
| { | { | ||||
| memset(&mesh->runtime, 0, sizeof(mesh->runtime)); | memset(&mesh->runtime, 0, sizeof(mesh->runtime)); | ||||
| mesh->runtime.eval_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime eval_mutex"); | |||||
| BLI_mutex_init(mesh->runtime.eval_mutex); | |||||
| } | } | ||||
| /* Clear all pointers which we don't want to be shared on copying the datablock. | /* Clear all pointers which we don't want to be shared on copying the datablock. | ||||
| * However, keep all the flags which defines what the mesh is (for example, that | * However, keep all the flags which defines what the mesh is (for example, that | ||||
| * it's deformed only, or that its custom data layers are out of date.) */ | * it's deformed only, or that its custom data layers are out of date.) */ | ||||
| void BKE_mesh_runtime_reset_on_copy(Mesh *mesh, const int UNUSED(flag)) | void BKE_mesh_runtime_reset_on_copy(Mesh *mesh, const int UNUSED(flag)) | ||||
| { | { | ||||
| Mesh_Runtime *runtime = &mesh->runtime; | Mesh_Runtime *runtime = &mesh->runtime; | ||||
| runtime->mesh_eval = NULL; | |||||
| runtime->edit_data = NULL; | runtime->edit_data = NULL; | ||||
| runtime->batch_cache = NULL; | runtime->batch_cache = NULL; | ||||
| runtime->subdiv_ccg = NULL; | runtime->subdiv_ccg = NULL; | ||||
| memset(&runtime->looptris, 0, sizeof(runtime->looptris)); | memset(&runtime->looptris, 0, sizeof(runtime->looptris)); | ||||
| runtime->bvh_cache = NULL; | runtime->bvh_cache = NULL; | ||||
| runtime->shrinkwrap_data = NULL; | runtime->shrinkwrap_data = NULL; | ||||
| mesh->runtime.eval_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime eval_mutex"); | |||||
| BLI_mutex_init(mesh->runtime.eval_mutex); | |||||
| } | } | ||||
| void BKE_mesh_runtime_clear_cache(Mesh *mesh) | void BKE_mesh_runtime_clear_cache(Mesh *mesh) | ||||
| { | { | ||||
| if (mesh->runtime.eval_mutex != NULL) { | |||||
| BLI_mutex_end(mesh->runtime.eval_mutex); | |||||
mont29: Aren’t you supposed to call `BLI_mutex_end()` first? | |||||
Done Inline ActionsThat is a very good point! sergey: That is a very good point! | |||||
| MEM_freeN(mesh->runtime.eval_mutex); | |||||
| mesh->runtime.eval_mutex = NULL; | |||||
| } | |||||
| if (mesh->runtime.mesh_eval != NULL) { | |||||
Not Done Inline ActionsPretty sure pointers should be set to NULL here? mont29: Pretty sure pointers should be set to NULL here? | |||||
Done Inline ActionsNot strictly speaking necessary i guess: the function is more like BKE_mesh_runtime_free. But think it's indeed better to zero stuff out. Not sure whether i should bother with clearing rest of the pointers though. sergey: Not strictly speaking necessary i guess: the function is more like `BKE_mesh_runtime_free`. But… | |||||
| mesh->runtime.mesh_eval->edit_mesh = NULL; | |||||
| BKE_id_free(NULL, mesh->runtime.mesh_eval); | |||||
| mesh->runtime.mesh_eval = NULL; | |||||
| } | |||||
| BKE_mesh_runtime_clear_geometry(mesh); | BKE_mesh_runtime_clear_geometry(mesh); | ||||
| BKE_mesh_batch_cache_free(mesh); | BKE_mesh_batch_cache_free(mesh); | ||||
| BKE_mesh_runtime_clear_edit_data(mesh); | BKE_mesh_runtime_clear_edit_data(mesh); | ||||
| } | } | ||||
| /* This is a ported copy of DM_ensure_looptri_data(dm) */ | /* This is a ported copy of DM_ensure_looptri_data(dm) */ | ||||
| /** | /** | ||||
| * Ensure the array is large enough | * Ensure the array is large enough | ||||
| ▲ Show 20 Lines • Show All 343 Lines • Show Last 20 Lines | |||||
Aren’t you supposed to call BLI_mutex_end() first?