Open qaisjp opened 4 years ago
Seeing the same issue in an standalone C++ app. I want my app to be able to handle discord closing and restarting, so I need to recreate the core as well.
I use mitigation policies to disallow invalid handles as well, so the issue is present even without a debugger.
If only the library was open source and we could submit a pull request fixing this 🙃
Here's a minimum, 100% reliable repro (on Windows):
#include <iostream>
#include <discord-game-sdk/discord.h>
#include <Windows.h>
int main()
{
PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY handle_policy{};
handle_policy.RaiseExceptionOnInvalidHandleReference = true;
handle_policy.HandleExceptionsPermanentlyEnabled = true;
SetProcessMitigationPolicy(ProcessStrictHandleCheckPolicy, &handle_policy, sizeof(handle_policy));
discord::Core* core{};
auto response = discord::Core::Create(461618159171141643, DiscordCreateFlags_Default, &core);
if (!core) {
std::cout << "Failed to instantiate Discord! " << (int)response;
std::exit(-1);
}
delete core; // crashes here for me
}
@msciotti can you please take a look, or forward this to someone who can?
The only solution currently is intentionally leaking the core :(
Please fix this
For some reason, calling the destructor explicitly core->~Core();
doesn't raise the error, while delete core;
does. (at least for me it didn't)
A similar error (InternalError) is thrown if you open your game without having Discord opened. And since there is no way of detecting if Discord is opened mid session there is no way on using the SDK in a proper way.
I mean you can try like you said every X amount of seconds to create a new Discord instance to see if "hey, did you opened this time?" but really that's extremely inefficient (specially if the user literally never opens Discord, it's going to be trying to recreate something that the player never intends to do).
InternalError isn't even remotely similar. The exception here is triggered by Windows because the SDK uses an invalid handle and completely and irrecoverably crashes your program, while InternalError is recoverable and only thrown in C# (it's a return value in C++)
Can confirm this issue is still happening, will this be fixed anytime soon?
Describe the bug
Where
discord::Core* m_DiscordCore
, runningdelete m_DiscordCore
will cause a Windows exception:Steps to reproduce
delete m_DiscordCore
, but only if a debugger is attachedExpected behavior
No exception should be thrown.
Screenshots
Implementation specifics
C++, Windows
Additional context
We delete the discord core, non-blocking wait 15s, and recreate the core. This handles the scenario where the user restarts discord whilst our game is running.
Someone on the discord-gamesdk guild said we shouldn't delee the core, but we keep getting
discord::Result::NotRunning
fromRunCallbacks
, despite the user starting Discord again. It seems the only way to get the game sdk to connect to the new instance of discord is to recreatediscord::Core
?Is that a different bug?