The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL 2.0.4 application window does not show up
FMS


Joined: 21 Jan 2016
Posts: 2
Hey there!

Since switching to SDL 2.0.4 I have a strange problem on my Windows 7 machine: the application-window does not show up at all but the program is otherwise running normally. Here's a stripped-down example:

Code:

#include <iostream>
#include "SDL.h"


int main(int argc, char *argv[]){
  SDL_Init(SDL_INIT_VIDEO);
  SDL_Window *app_window = SDL_CreateWindow("SDL2-window",
         SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600,
                                                 SDL_WINDOW_RESIZABLE
  //                                           | SDL_WINDOW_MINIMIZED //!hack!
                                                                     );

  if(app_window == NULL){
    std::cout << "error: SDL_CreateWindow failed!" << std::endl;
    return 1;
  }
  SDL_Renderer *renderer = SDL_CreateRenderer(app_window, -1,
                       SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
  //SDL_RestoreWindow(app_window); //!hack!
  SDL_RenderPresent(renderer);

  SDL_Delay(5000);

  SDL_DestroyRenderer(renderer);
  SDL_DestroyWindow(app_window);
  SDL_Quit();
  return 0;
}


If I uncomment the two lines with //!hack! at the end then the window does show up (but it warps in like you would expect from a window being restored from minimized state, which is not what I want). In rare cases the window does not show up even with the SDL_WINDOW_MINIMIZED / SDL_RestoreWindow hack. Then I need to restart the application until it does show up...

Creating the window with SDL_WINDOW_FULLSCREEN_DESKTOP does work normally and the window can then be switched to window-mode and is still displayed just fine.

I am using "g++ -Wall -o test test.cc -Isdl/sdl2/include -Lsdl/sdl2/lib -lmingw32 -lSDL2main -lSDL2 -mwindows" to compile my program with mingw32 using the "i686-w64-mingw32" branch of the mingw-development-libraries (SDL2-devel-2.0.4-mingw.tar.gz).

With former versions of SDL2 I did not have this issue. Also on Linux this is not a problem. I currently do not have a Windows 8 or Windows 10 machine for testing this but on Windows 7 and Vista the problem does occur. Am I missing something?

Any help would be greatly appreciated.
FMS


Joined: 21 Jan 2016
Posts: 2
ok, sorry for having bothered you all with this. It's not really a SDL problem (although SDL behaves strangely here). It is a problem with my editor Notepad++ and its console plugin NppExec. If you have the same problem or are interested in why I think SDL behaves strangely in this respect read on.

If I compile my program and run it from the console in Notepad++, NppExec calls "CreateProcess" like so:

Code:

PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi));
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE;
si.hStdInput = m_hStdInReadPipe;
si.hStdOutput = m_hStdOutWritePipe;
si.hStdError = m_hStdOutWritePipe;
CreateProcess(NULL,                     //_In_opt_    LPCTSTR               lpApplicationName,
              cmd_str,                  //_Inout_opt_ LPTSTR                lpCommandLine,
              NULL,                     //_In_opt_    LPSECURITY_ATTRIBUTES lpProcessAttributes,
              NULL,                     //_In_opt_    LPSECURITY_ATTRIBUTES lpThreadAttributes,
              true,                     //_In_        BOOL                  bInheritHandles,
              CREATE_NEW_PROCESS_GROUP, //_In_        DWORD                 dwCreationFlags,
              NULL,                     //_In_opt_    LPVOID                lpEnvironment,
              NULL,                     //_In_opt_    LPCTSTR               lpCurrentDirectory,
              &si,                      //_In_        LPSTARTUPINFO         lpStartupInfo,
              &pi);                     //_Out_       LPPROCESS_INFORMATION lpProcessInformation


This makes the application window hidden on startup. (I wonder why it did not do so for older versions of SDL2...) What I consider strange is that calling "SDL_ShowWindow" in my SDL-application does not show the window. Probably SDL thinks the window is currently shown, because if I call "SDL_HideWindow" and then "SDL_ShowWindow" directly afterwards the window is actually made visible. Is this a bug in SDL? Shouldn't SDL realize the state of the window on startup?

Anyways, this is a minor issue, sorry if you feel like I have wasted your time.
Best, FMS