Mercurial > sdl-ios-xcode
changeset 3485:e77a69aae239
Mason Wheeler to sdl
I updated SDL, and suddenly my SDL frames stopped working. They'd "initialize" full of gibberish, and I couldn't render anything to them. After a bit of digging, I found a problem: the renderer initialization routine in my SDL frame code wasn't getting called anymore.
procedure TSdlFrame.Paint;
begin
if SDL_SelectRenderer(FWindowID) = -1 then
CreateRenderer;
SDL_RenderPresent;
end;
function TSdlFrame.CreateRenderer: boolean;
const
pf: tagPIXELFORMATDESCRIPTOR = (nSize: sizeof(pf); nVersion: 1;
dwFlags: PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
iPixelType: PFD_TYPE_RGBA; cColorBits: 24; cAlphaBits: 8;
iLayerType: PFD_MAIN_PLANE);
RENDERERS: array[TRendererType] of AnsiString = ('software', 'gdi', 'opengl', 'd3d');
var
pFormat: integer;
begin
if (SDL_SelectRenderer(FWindowID) = 0) then
begin
result := true;
Exit;
end;
if FRendererType = rtOpenGL then
begin
pFormat := ChoosePixelFormat(canvas.Handle, @pf);
if not SetPixelFormat(canvas.Handle, pFormat, @pf) then
outputDebugString(PChar(SysErrorMessage(GetLastError)));
if wglCreateContext(canvas.Handle) = 0 then
outputDebugString(PChar(SysErrorMessage(GetLastError)));
end;
if (SDL_CreateRenderer(FWindowID, SDL_RendererIndex(RENDERERS[FRendererType]), [sdlrPresentFlip3, sdlrAccelerated]) = 0) then
begin
SDL_ShowWindow(FWindowID);
assert(SDL_SetRenderDrawColor(0, 0, 0, 255) = 0);
FFlags := SDL_GetWindowFlags(FWindowID);
if assigned(FOnAvailable) then
FOnAvailable(self);
end
else outputDebugString(pChar(format('SDL_CreateRenderer failed: %s', [sdl_GetError])));
result := SDL_SelectRenderer(FWindowID) = 0;
end;
This is a critical issue. The Paint method gets called when the control receives a WM_PAINT message from Windows. I can't create the renderer before then, or it will fail and cause trouble. And when I do create it, it needs to be created with certain parameters. So imagine my surprise when I started debugging into the DLL and found that SDL_SelectRenderer was trying to be "helpful" by creating the renderer for me if it didn't already exist! Now not only does my initialization code not get called, I end up with the wrong renderer and so things don't render as expected when I try to use the window.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 24 Nov 2009 04:48:12 +0000 |
parents | fed6d4c6c693 |
children | c87dbbde2bc2 |
files | src/video/SDL_video.c |
diffstat | 1 files changed, 26 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/video/SDL_video.c Sun Nov 22 20:53:53 2009 +0000 +++ b/src/video/SDL_video.c Tue Nov 24 04:48:12 2009 +0000 @@ -966,13 +966,17 @@ } static __inline__ SDL_Renderer * -SDL_GetCurrentRenderer() +SDL_GetCurrentRenderer(SDL_bool create) { if (!_this) { SDL_UninitializedVideo(); return NULL; } if (!SDL_CurrentRenderer) { + if (!create) { + SDL_SetError("Use SDL_CreateRenderer() to create a renderer"); + return NULL; + } if (SDL_CreateRenderer(0, -1, 0) < 0) { return NULL; } @@ -1549,25 +1553,23 @@ return -1; } renderer = window->renderer; - if (renderer) { - if (renderer->ActivateRenderer) { - if (renderer->ActivateRenderer(renderer) < 0) { - return -1; - } - } - SDL_CurrentDisplay.current_renderer = renderer; - } else { - if (SDL_CreateRenderer(windowID, -1, 0) < 0) { + if (!renderer) { + SDL_SetError("Use SDL_CreateRenderer() to create a renderer"); + return -1; + } + if (renderer->ActivateRenderer) { + if (renderer->ActivateRenderer(renderer) < 0) { return -1; } } + SDL_CurrentDisplay.current_renderer = renderer; return 0; } int SDL_GetRendererInfo(SDL_RendererInfo * info) { - SDL_Renderer *renderer = SDL_GetCurrentRenderer(); + SDL_Renderer *renderer = SDL_GetCurrentRenderer(SDL_FALSE); if (!renderer) { return -1; } @@ -1582,7 +1584,7 @@ SDL_Renderer *renderer; SDL_Texture *texture; - renderer = SDL_GetCurrentRenderer(); + renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return 0; } @@ -1636,7 +1638,7 @@ } fmt = surface->format; - renderer = SDL_GetCurrentRenderer(); + renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return 0; } @@ -2270,7 +2272,7 @@ { SDL_Renderer *renderer; - renderer = SDL_GetCurrentRenderer(); + renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } @@ -2290,7 +2292,7 @@ { SDL_Renderer *renderer; - renderer = SDL_GetCurrentRenderer(); + renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } @@ -2314,7 +2316,7 @@ { SDL_Renderer *renderer; - renderer = SDL_GetCurrentRenderer(); + renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } @@ -2331,7 +2333,7 @@ { SDL_Renderer *renderer; - renderer = SDL_GetCurrentRenderer(); + renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } @@ -2345,7 +2347,7 @@ SDL_Renderer *renderer; SDL_Window *window; - renderer = SDL_GetCurrentRenderer(); + renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } @@ -2371,7 +2373,7 @@ return SDL_RenderPoint(x1, y1); } - renderer = SDL_GetCurrentRenderer(); + renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } @@ -2398,7 +2400,7 @@ SDL_Window *window; SDL_Rect real_rect; - renderer = SDL_GetCurrentRenderer(); + renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } @@ -2430,7 +2432,7 @@ SDL_Rect real_srcrect; SDL_Rect real_dstrect; - renderer = SDL_GetCurrentRenderer(); + renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } @@ -2493,7 +2495,7 @@ SDL_Window *window; SDL_Rect real_rect; - renderer = SDL_GetCurrentRenderer(); + renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } @@ -2537,7 +2539,7 @@ SDL_Window *window; SDL_Rect real_rect; - renderer = SDL_GetCurrentRenderer(); + renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } @@ -2578,7 +2580,7 @@ { SDL_Renderer *renderer; - renderer = SDL_GetCurrentRenderer(); + renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer || !renderer->RenderPresent) { return; }