diff --git a/DDrawCompat/Common/CompatQueryInterface.h b/DDrawCompat/Common/CompatQueryInterface.h index 24a3548..bc8849b 100644 --- a/DDrawCompat/Common/CompatQueryInterface.h +++ b/DDrawCompat/Common/CompatQueryInterface.h @@ -106,6 +106,13 @@ namespace Compat getOrigVtable(&origIntf).QueryInterface(&origIntf, getIntfId(), reinterpret_cast(&newIntf)); } + template + void queryInterface(Intf& origIntf, Intf*& newIntf) + { + newIntf = &origIntf; + getOrigVtable(newIntf).AddRef(newIntf); + } + template NewIntf* queryInterface(OrigIntf* origIntf) { diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp index c0bd07d..2505795 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp @@ -163,7 +163,8 @@ namespace DDraw while (SUCCEEDED(surface->GetAttachedSurface(surface, &caps, &nextSurface.getRef())) && nextSurface != g_primarySurface) { - surface = nextSurface; + surface.swap(nextSurface); + nextSurface.release(); } return surface;