diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index 701e024093d..16304ee073c 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -782,6 +782,18 @@ BOOL context_set_current(struct wined3d_context *ctx) return TlsSetValue(wined3d_context_tls_idx, ctx); } +static void context_validate(struct wined3d_context *context) +{ + HWND wnd = WindowFromDC(context->hdc); + + if (wnd != context->win_handle) + { + WARN("DC %p belongs to window %p instead of %p.\n", + context->hdc, wnd, context->win_handle); + context->valid = 0; + } +} + /***************************************************************************** * Context_MarkStateDirty * @@ -1247,6 +1259,7 @@ struct wined3d_context *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceI } goto out; } + ret->valid = 1; ret->gl_info = &This->adapter->gl_info; ret->surface = (IWineD3DSurface *) target; ret->current_rt = (IWineD3DSurface *)target; @@ -1771,6 +1784,7 @@ static inline struct wined3d_context *FindContext(IWineD3DDeviceImpl *This, IWin if (current_context && current_context->current_rt == target) { + context_validate(current_context); return current_context; } @@ -1858,6 +1872,8 @@ retry: context->render_offscreen = TRUE; } + context_validate(context); + if (context->render_offscreen != old_render_offscreen) { Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION), StateTable); @@ -2007,6 +2023,7 @@ struct wined3d_context *ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurfac TRACE("(%p): Selecting context for render target %p, thread %d\n", This, target, tid); context = FindContext(This, target, tid); + if (!context->valid) return context; gl_info = context->gl_info; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 4b6cb4ca679..9c4bd5e3347 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1055,6 +1055,7 @@ struct wined3d_context WORD num_untracked_materials : 2; /* Max value 2 */ WORD current : 1; WORD destroyed : 1; + WORD valid : 1; BYTE texShaderBumpMap; /* MAX_TEXTURES, 8 */ BYTE lastWasPow2Texture; /* MAX_TEXTURES, 8 */ DWORD numbered_array_mask;