Cycles: Fix guarded allocator issues on Windows
The issue was caused by static vectors allocating some internal data using rebound element allocator for them, which was causing access to a non-initialized statistics objects and was failing a lot when switching Blender to a fully guarded allocation. Additionally, we were not able to free that internal memory before Blender exits, which was causing false-positive memory leak prints. Now we're not using GuardedAllocator for those proxy containers. Ideally this should be done as a GuardedAllocator::rebind, but it didn't work for vector<bool> because it seems some internal parts are converting bool to char32_t, which either makes it so we can't use GuardedAllocator for those vectors or the compiler get's confused when we're trying explicitly allow GuardedAllocator for rebind<char32_t>. This with current approach we should be fine for the release.
This commit is contained in:
parent
318d3b9ab4
commit
6371fccdbe
@ -123,6 +123,34 @@ public:
|
||||
|
||||
inline bool operator==(GuardedAllocator const& /*other*/) { return true; }
|
||||
inline bool operator!=(GuardedAllocator const& other) { return !operator==(other); }
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/* Welcome to the black magic here.
|
||||
*
|
||||
* The issue is that MSVC C++ allocates container proxy on any
|
||||
* vector initialization, including static vectors which don't
|
||||
* have any data yet. This leads to several issues:
|
||||
*
|
||||
* - Static objects initialization fiasco (global_stats from
|
||||
* util_stats.h might not be initialized yet).
|
||||
* - If main() function changes allocator type (for example,
|
||||
* this might happen with `blender --debug-memory`) nobody
|
||||
* will know how to convert already allocated memory to a new
|
||||
* guarded allocator.
|
||||
*
|
||||
* Here we work this around by making it so container proxy does
|
||||
* not use guarded allocation. A bit fragile, unfortunately.
|
||||
*/
|
||||
template<>
|
||||
struct rebind<std::_Container_proxy> {
|
||||
typedef std::allocator<std::_Container_proxy> other;
|
||||
};
|
||||
|
||||
operator std::allocator<std::_Container_proxy>() const
|
||||
{
|
||||
return std::allocator<std::_Container_proxy>();
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Get memory usage and peak from the guarded STL allocator. */
|
||||
|
Loading…
Reference in New Issue
Block a user