Qt: Add comment on ODR violation workaround

This commit is contained in:
TellowKrinkle 2022-08-25 22:37:56 -05:00 committed by tellowkrinkle
parent ddf839beb0
commit 8975f2d92c
1 changed files with 7 additions and 0 deletions

View File

@ -1786,6 +1786,13 @@ static void RegisterTypes()
{
qRegisterMetaType<std::optional<bool>>();
qRegisterMetaType<std::optional<WindowInfo>>("std::optional<WindowInfo>()");
// Bit of fun with metatype names
// On Windows, the real type name here is "std::function<void __cdecl(void)>"
// Normally, the fact that we `Q_DECLARE_METATYPE(std::function<void()>);` in QtHost.h would make it also register under "std::function<void()>"
// The metatype is a pointer to `QMetaTypeInterfaceWrapper<std::function<void()>>::metaType`, which contains a pointer to the function that would register the alternate name
// But to anyone who can't see QtHost.h, that pointer should be null, opening us up to ODR violations
// Turns out some of our automoc files also instantiate that metaType (with the null pointer), so if we try to rely on it, everything will break if we get unlucky with link order
// Instead, manually register under the desired name:
qRegisterMetaType<std::function<void()>>("std::function<void()>");
qRegisterMetaType<std::shared_ptr<VMBootParameters>>();
qRegisterMetaType<GSRendererType>();