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
SDL2 programs compile but don't run on Windows 7
PPeter


Joined: 24 May 2014
Posts: 5
Hello,

I'm just trying to get SDL2 running on my Windows 7 laptop. I've been following the lazyfoo tutorials for windows development using Mingw, since I normally program on Linux. My issue is that his tutorial 1 code will compile perfectly fine, but when I run the executable which is created, there is no absolutely no output.

If executed from within an msys session, sometimes a new console window will pop up quickly and exit, but normally it just has no output and exits normally as far as I can tell. If I run the executable directly, same thing. A console window quickly opens then closes.

I've tried putting in cout statements at different points within the program, but it never outputs any of these. I've never experienced anything like this before, and I can't find anything about it online.

I would greatly appreciate any help as this has been bugging me for a few weeks now. I've even tried using MSVC 2013, but it has issues of its own as well.

Thanks in advance.
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
If you run the program from DOS, do you get messages stating that DLL's are missing ?
SDL2 programs compile but don't run on Windows 7
neoaggelos


Joined: 02 Jan 2013
Posts: 138
Try copying the SDL dll in your program's directory
-- Aggelos Kolaitis On Jan 3, 2015 1:08 PM, "MrTAToad" wrote:
Quote:
If you run the program from DOS, do you get messages stating that DLL's are missing ?


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

PPeter


Joined: 24 May 2014
Posts: 5
I don't have the laptop with me right now, but I don't think DOS outputs anything either. Also the dll is in the correct directory.
mr_tawan


Joined: 13 Jan 2014
Posts: 161
I'd suggest you to try using MSYS2 + Mingw64 build of SDL. In MSYS2, you can install the toolchain + SDL2 library by :

Code:
$pacman -S mingw-w64-i686-gcc mingw-w64-i686-SDL


replace i686 with x86_64 for 64bit version Smile.

But before that, why won't you tell us what is the code you're working with. Probably it just failed to load some image resource file and that error is not handled properly Smile. If you're using some resource loading function (eg. IMG_Load()) please double check if the resource file is in the correct path.
SDL2 programs compile but don't run on Windows 7
neoaggelos


Joined: 02 Jan 2013
Posts: 138
Furthermore, consider using SDL_Log instead of cout.
cout << "hello";
SDL_Log("hello");
I remember having some issues with cout+SDL a while back, and using SDL_Log() resolved them
mr_tawan


Joined: 13 Jan 2014
Posts: 161
I've just looked at the tutorial. From the code the expected output would be to have a window with 640x480 display area shows up for 2 seconds. The display area of the window would be painted in white.

Do you have anything of those shows up ?

Have you put some debugging text in between lines of code ? Is there anything shows up in the console ?
PPeter


Joined: 24 May 2014
Posts: 5
mr_tawan wrote:
I've just looked at the tutorial. From the code the expected output would be to have a window with 640x480 display area shows up for 2 seconds. The display area of the window would be painted in white.

Do you have anything of those shows up ?

Have you put some debugging text in between lines of code ? Is there anything shows up in the console ?


Here's the code for others to reference (sorry I didn't put it up in the first place)
Code:
/*This source code copyrighted by Lazy Foo' Productions (2004-2013)
and may not be redistributed without written permission.*/

//Using SDL and standard IO
#include <SDL2/SDL.h>
#include <stdio.h>
#include <iostream>

//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

int main(int argc, char** argv)
{
   //The window we'll be rendering to
   SDL_Window* window = NULL;
   
   //The surface contained by the window
   SDL_Surface* screenSurface = NULL;
   //Initialize SDL
   if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
   {
      printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
   }
   else
   {
      //Create window
           std::cout << "Hello" << std::endl;
      window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );    //SEG FAULT HERE
      if( window == NULL )
      {
         printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
      }
      else
      {
         //Get window surface
         screenSurface = SDL_GetWindowSurface( window );

         //Fill the surface white
         SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );
         
         //Update the surface
         SDL_UpdateWindowSurface( window );

         //Wait two seconds
         SDL_Delay( 2000 );
      }
   }

   //Destroy window
   SDL_DestroyWindow( window );

   //Quit SDL subsystems
   SDL_Quit();

   return 0;
}


I just remembered that gdb is already installed, so I ran the program through that and found out that it runs into a seg fault at:
Code:
window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );

For some reason, it doesn't say anything when a sig fault occurs. I checked before that line to make sure that everything was initialized properly using SDL_WasInit, it said everything was fine.
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
I presume it is actually crashing in SDL_CreateWindow, rather than returning NULL and there being a problem with, say, SDL_DestroyWindow (although that should check NULL values).
PPeter


Joined: 24 May 2014
Posts: 5
MrTAToad wrote:
I presume it is actually crashing in SDL_CreateWindow, rather than returning NULL and there being a problem with, say, SDL_DestroyWindow (although that should check NULL values).


Yep. It doesn't get to the check if window is still NULL or not, and gdb won't step into the function. I tried the code with v2.0.2, and it crashed in the same spot as well.

I'm currently trying to build v2.0.3 myself to see if I can find anything else out.[/img]
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
I wonder if SDL2 is unable to use either DirectX or OpenGL, reverting to software mode and then crashing for some reason.
PPeter


Joined: 24 May 2014
Posts: 5
MrTAToad wrote:
I wonder if SDL2 is unable to use either DirectX or OpenGL, reverting to software mode and then crashing for some reason.


I think it's related to that, and possibly how the laptop is setup. This is on my work laptop, which was setup to run a certain way (use certain software only, encryption, and so on). So it maybe doing something which restricts use behind the scenes (not sure, don't know a lot about Windows 7 OS).

Either way, when I was trying to build the src for 2.0.3, I kept running into an issue where some dxgi.h header file was not found and it would just stop from there. I've only found people having problems when they were trying to compile v2.0.2, and those were fixed by them change
Code:
#include <DXGI.h>
to
Code:
#include <dxgi.h>


After that, I was planning on running a VM of Arch and just using that instead, but to my chagrin, it would BSOD my computer as soon as I try running it. I appreciate you trying to help, but I think I'll just bite the bullet and work on things which only rely on the std c++ libs when I'm bored at work.[/code]
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Fair enough!
SDL2 programs compile but don't run on Windows 7
Jonny D


Joined: 12 Sep 2009
Posts: 932
I believe this is a bug specific to builds with MinGW32.  If you install MinGW-w64, you might be better off until this is figured out.

Jonny D






On Thu, Jan 8, 2015 at 2:46 PM, MrTAToad wrote:
Quote:
Fair enough!


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL2 programs compile but don't run on Windows 7
Sik


Joined: 26 Nov 2011
Posts: 905
2015-01-08 21:37 GMT-03:00, Jonathan Dearborn:
Quote:
I believe this is a bug specific to builds with MinGW32. If you install
MinGW-w64, you might be better off until this is figured out.

For what's worth, SDL2 already had problems with the original MinGW
for quite a long ago (last time I tried, using the threading functions
would result in a linker error, while MinGW-w64 has no such problem).
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org