| 101 | const uint32_t INVALID_SCRIPT_ID = 0xFFFFFFFF; |
| 102 | |
| 103 | HContext NewContext(const ContextParams& params) |
| 104 | { |
| 105 | Context* context = new Context(); |
| 106 | context->m_Modules.SetCapacity(127, 256); |
| 107 | context->m_PathToModule.SetCapacity(127, 256); |
| 108 | context->m_HashInstances.SetCapacity(443, 256); |
| 109 | context->m_ScriptExtensions.SetCapacity(8); |
| 110 | context->m_ConfigFile = params.m_ConfigFile; |
| 111 | context->m_ResourceFactory = params.m_Factory; |
| 112 | context->m_GraphicsContext = params.m_GraphicsContext; |
| 113 | context->m_LuaState = lua_open(); |
| 114 | #if defined(DM_SANITIZE_THREAD) && defined(__linux__) && !defined(ANDROID) && defined(__aarch64__) |
| 115 | // Linux arm64 TSan reserves large shadow-memory ranges. This can make |
| 116 | // LuaJIT's mmap probe fail to reserve a valid Lua state range, so retry |
| 117 | // state creation before treating it as a real allocation failure. |
| 118 | for (int i = 0; context->m_LuaState == 0 && i < 16; ++i) |
| 119 | { |
| 120 | context->m_LuaState = lua_open(); |
| 121 | } |
| 122 | #endif |
| 123 | if (context->m_LuaState == 0) |
| 124 | { |
| 125 | dmLogFatal("Failed to create Lua state."); |
| 126 | assert(context->m_LuaState != 0); |
| 127 | } |
| 128 | context->m_ContextTableRef = LUA_NOREF; |
| 129 | context->m_ContextWeakTableRef = LUA_NOREF; |
| 130 | return context; |
| 131 | } |
| 132 | |
| 133 | void DeleteContext(HContext context) |
| 134 | { |