<commit_before>#include "pch.h"
#include "aiInternal.h"
#include "aiContext.h"
#include "aiObject.h"
#include "aiAsync.h"


std::string ToString(const aiConfig &v)
{
    std::ostringstream oss;

    oss << "{swapHandedness: " << (v.swap_handedness ? "true" : "false");
    oss << ", swapFaceWinding: " << (v.swap_face_winding ? "true" : "false");
    oss << ", normalsMode: " << (v.normals_mode == aiNormalsMode::ReadFromFile
        ? "read_from_file"
        : (v.normals_mode == aiNormalsMode::ComputeIfMissing
            ? "compute_if_missing"
            : (v.normals_mode == aiNormalsMode::AlwaysCompute
                ? "always_compute"
                : "ignore")));
    oss << ", tangentsMode: " << (v.tangents_mode == aiTangentsMode::None
        ? "none"
        : (v.tangents_mode == aiTangentsMode::Compute
            ? "smooth"
            : "split"));
    oss << ", aspectRatio: " << v.aspect_ratio;

    return oss.str();
}

aiContextManager aiContextManager::s_instance;

aiContext* aiContextManager::getContext(int uid)
{
    auto it = s_instance.m_contexts.find(uid);
if (it != s_instance.m_contexts.end()) {
        DebugLog("Using already created context for gameObject with ID %d", uid);
        return it->second.get();
    }

    auto ctx = new aiContext(uid);
    s_instance.m_contexts[uid].reset(ctx);
    DebugLog("Register context for gameObject with ID %d", uid);
    return ctx;
}

void aiContextManager::destroyContext(int uid)
{
    auto it = s_instance.m_contexts.find(uid);
    if (it != s_instance.m_contexts.end()) {
        DebugLog("Unregister context for gameObject with ID %d", uid);
        s_instance.m_contexts.erase(it);
    }
}

void aiContextManager::destroyContextsWithPath(const char* assetPath)
{
    auto path = aiContext::normalizePath(assetPath);
    for (auto it = s_instance.m_contexts.begin(); it != s_instance.m_contexts.end(); ++it) {
        if (it->second->getPath() == path) {
            DebugLog("Unregister context for gameObject with ID %s", it->second->getPath().c_str());
            s_instance.m_contexts.erase(it);
        }
    }
}

aiContextManager::~aiContextManager()
{
    if (m_contexts.size()) {
        DebugWarning("%lu remaining context(s) registered", m_contexts.size());
    }
    m_contexts.clear();
}



aiContext::aiContext(int uid)
    : m_uid(uid)
{
}
<commit_msg>fix crash when reimport instantiated asset on Mac<commit_after>#include "pch.h"
#include "aiInternal.h"
#include "aiContext.h"
#include "aiObject.h"
#include "aiAsync.h"


std::string ToString(const aiConfig &v)
{
    std::ostringstream oss;

    oss << "{swapHandedness: " << (v.swap_handedness ? "true" : "false");
    oss << ", swapFaceWinding: " << (v.swap_face_winding ? "true" : "false");
    oss << ", normalsMode: " << (v.normals_mode == aiNormalsMode::ReadFromFile
        ? "read_from_file"
        : (v.normals_mode == aiNormalsMode::ComputeIfMissing
            ? "compute_if_missing"
            : (v.normals_mode == aiNormalsMode::AlwaysCompute
                ? "always_compute"
                : "ignore")));
    oss << ", tangentsMode: " << (v.tangents_mode == aiTangentsMode::None
        ? "none"
        : (v.tangents_mode == aiTangentsMode::Compute
            ? "smooth"
            : "split"));
    oss << ", aspectRatio: " << v.aspect_ratio;

    return oss.str();
}

aiContextManager aiContextManager::s_instance;

aiContext* aiContextManager::getContext(int uid)
{
    auto it = s_instance.m_contexts.find(uid);
if (it != s_instance.m_contexts.end()) {
        DebugLog("Using already created context for gameObject with ID %d", uid);
        return it->second.get();
    }

    auto ctx = new aiContext(uid);
    s_instance.m_contexts[uid].reset(ctx);
    DebugLog("Register context for gameObject with ID %d", uid);
    return ctx;
}

void aiContextManager::destroyContext(int uid)
{
    auto it = s_instance.m_contexts.find(uid);
    if (it != s_instance.m_contexts.end()) {
        DebugLog("Unregister context for gameObject with ID %d", uid);
        s_instance.m_contexts.erase(it);
    }
}

void aiContextManager::destroyContextsWithPath(const char* assetPath)
{
    auto path = aiContext::normalizePath(assetPath);
    for (auto it = s_instance.m_contexts.begin(); it != s_instance.m_contexts.end(); ++it) {
        if (it->second->getPath() == path) {
            DebugLog("Unregister context for gameObject with ID %s", it->second->getPath().c_str());
            s_instance.m_contexts.erase(it);
            break;
        }
    }
}

aiContextManager::~aiContextManager()
{
    if (m_contexts.size()) {
        DebugWarning("%lu remaining context(s) registered", m_contexts.size());
    }
    m_contexts.clear();
}



aiContext::aiContext(int uid)
    : m_uid(uid)
{
}

{'fraction_non_alphanumeric': 0.14982139104853961, 'fraction_numerical': 0.0, 'mean_word_length': 3.2086648983200705, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2344017', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1581, 'n_words': 300}