Skip to content

Commit dc3f8b1

Browse files
committed
deliberately leak InteropContext to make sure it outlives all the players it manages
1 parent b808cb5 commit dc3f8b1

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/Win32/AX-MediaPlayerWin32DXGIRenderPath.cxx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace AX::Video
2727
{
2828
public:
2929

30+
static void StaticInitialize ( );
3031
static InteropContext & Get ( );
3132

3233
~InteropContext ( );
@@ -50,15 +51,23 @@ namespace AX::Video
5051
bool _isValid{ false };
5152
};
5253

53-
// @note(andrew): Lazily initialize this but make sure
54-
// it hangs around for the remainer of the application
55-
// so that it outlives any of the players that depend on
56-
// it being alive and valid
54+
// @leak(andrew): Lazily initialize and deliberately leak this
55+
// to make sureit hangs around for the remainder of the application
56+
// It has to outlive any of the players that depend on it being alive and valid
57+
// @todo(andrew): Find a less gross way to manage this lifetime
58+
59+
static InteropContext * kInteropContext{ nullptr };
60+
void InteropContext::StaticInitialize ( )
61+
{
62+
if ( !kInteropContext )
63+
{
64+
kInteropContext = new InteropContext ( );
65+
}
66+
}
5767

58-
static std::unique_ptr<InteropContext> kInteropContext{ nullptr };
5968
InteropContext & InteropContext::Get ( )
6069
{
61-
if ( !kInteropContext ) kInteropContext.reset ( new InteropContext ( ) );
70+
assert ( kInteropContext );
6271
return *kInteropContext;
6372
}
6473

@@ -234,6 +243,8 @@ namespace AX::Video
234243

235244
bool DXGIRenderPath::Initialize ( IMFAttributes & attributes )
236245
{
246+
InteropContext::StaticInitialize ( );
247+
237248
auto & interop = InteropContext::Get ( );
238249
if ( !interop.IsValid ( ) ) return false;
239250

@@ -285,6 +296,6 @@ namespace AX::Video
285296

286297
DXGIRenderPath::~DXGIRenderPath ( )
287298
{
288-
299+
_sharedTexture = nullptr;
289300
}
290301
}

0 commit comments

Comments
 (0)