AttachIl2Cpp
Hi,
I noticed that the AttachIl2Cpp feature was removed in BNM 2.0.4. I really liked using this feature to call methods outside the Il2cpp thread. Is there any chance you could bring it back in a future update? Thanks!
Even using it, calling unity/il2cpp methods outside main thread is dangerous. This method don't syncs threads. You can call some math unity methods safely, some other will crash after call.
If i don't use AttachIl2Cpp or il2cpp_thread_attach on the current thread, the app will crash. However, if i use it on a thread before calling a method, the app runs smoothly. For example, in my code below, I call a method on the ImGui thread. When I don't use AttachIl2Cpp, the app crashes, but it works fine when I do
ImGui::Spacing();
auto currencyManager = SDK::CurrencyManager::instance<SDK::CurrencyManager*>().Get();
if (currencyManager && BNM::IsUnityObjectAlive(currencyManager)) {
ImGui::Checkbox(OBFUSCATE("Debug"), &config.profile.debug);
if (config.profile.debug) {
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
ImGui::Text(OBFUSCATE("Current Money: "));
if (ImGui::InputInt(OBFUSCATE("##currentMoney"), currencyManager->currentGold<int>().GetPointer())) {
if (BNM::AttachIl2Cpp()) {
auto OnGoldChanged = currencyManager->OnGoldChanged<Action<int>*>().Get();
if (OnGoldChanged) OnGoldChanged->Invoke(currencyManager->currentGold<int>().Get());
BNM::DetachIl2Cpp();
}
}
}
}
ImGui::Spacing();
ImGui::End();
You have own thread for imgui?
i am using GLSurfaceView.Renderer for IMGUI
After reanalyzing il2cpp src, I see that code attaching to. I will return methods it in next patch if it really useful.