how to check for an event

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to check for an event

speartip
Hi, wanted to know how to code for an error state in the following code. I am new to SDL. I simply want a true to some value if a window was successfully created. I've made this window generation a subroutine:








Code:

#include
#include "make_Window.h"

void make_Window(int horizontal, int vertical)   //SDL_Window *window)
{

   SDL_Init(SDL_INIT_EVERYTHING);

// Create a Window in the middle of the screen
      SDL_Window *window = 0;
        window = SDL_CreateWindow("Hello World!",
                                  SDL_WINDOWPOS_CENTERED,
                                  SDL_WINDOWPOS_CENTERED,
                                  horizontal, vertical,
                                  SDL_WINDOW_SHOWN);
        // Delay so that we can see the window appear
        SDL_Delay(2000);

}

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to check for an event

Brian Puthuff
https://wiki.libsdl.org/SDL_CreateWindow

SDL_CreateWindow will return NULL if failed.

Not sure if that's what you are asking.

On Feb 13, 2017 8:15 AM, "speartip" <[hidden email]> wrote:
Hi, wanted to know how to code for an error state in the following code. I am new to SDL. I simply want a true to some value if a window was successfully created. I've made this window generation a subroutine:




Code:


#include
#include "make_Window.h"

void make_Window(int horizontal, int vertical)   //SDL_Window *window)
{

   SDL_Init(SDL_INIT_EVERYTHING);

// Create a Window in the middle of the screen
      SDL_Window *window = 0;
        window = SDL_CreateWindow("Hello World!",
                                  SDL_WINDOWPOS_CENTERED,
                                  SDL_WINDOWPOS_CENTERED,
                                  horizontal, vertical,
                                  SDL_WINDOW_SHOWN);
        // Delay so that we can see the window appear
        SDL_Delay(2000);

}



_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to check for an event

speartip
In reply to this post by speartip
Thats it. Thx!! I am just getting use to their library.

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to check for an event

speartip
In reply to this post by speartip
Well, a bit premature!








Code:

if (window == NULL) {
                // In the case that the window could not be made...
              printf("Could not create window: %s\n", SDL_GetError());
                return 1;


I experienced problems with printf only to find out my IDE Eclipse is problematic with printf. After adding #include the printf was printing
the "Could not create window:" portion, but not the rest. Can anyone please tell me what is supposed to be printed after it : %s\n",SDL_GetError()
and how to get printf functional?

Thank you.

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to check for an event

speartip
In reply to this post by speartip
logically its working; in the braces within the printf is not functioning correctly.

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to check for an event

speartip
In reply to this post by speartip
I wanted to update, to focus the problem at hand and make sure nobody thought I was asking them to fix my compiler. No way!

This line initializes.







Code:


if (SDL_Init(SDL_INIT_EVERYTHING) == 0) {                  
              printf("SDL_Init failed: %s\n", SDL_GetError());
              return 1;}


Here I've purposely induced an error state by changing







Code:
 (SDL_Init(SDL_INIT_EVERYTHING) != 0) to (SDL_Init(SDL_INIT_EVERYTHING) == 0)


The error is then thrown and 1/2 of the statement is printed from printf above see bold below:

SDL_Init failed: . But the other half of the statement isn't printed.

But no value for







Code:
SDL,GetError()
is returned on the same line
.


In short my printf statement is cut in half.

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to check for an event

speartip
In reply to this post by speartip
printf("SDL_Init failed: %s\n", SDL_GetError())

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to check for an event

Jonathan Dearborn-2
It doesn't sound like you've actually induced an error state, but instead are printing regardless of whether or not there is an error.

If there is not an actual error, you might expect SDL_GetError() to return an empty string (not sure if that is specified by the API).  So you would see:

SDL_Init failed:

Because the %s was replaced by nothing.

Jonny D


On Wed, Feb 15, 2017 at 1:04 PM, speartip <[hidden email]> wrote:
printf("SDL_Init failed: %s\n", SDL_GetError())

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to check for an event

speartip
In reply to this post by speartip
It will only print if







Code:
SDL_Init(SDL_INIT_EVERYTHING) == 0)
. But won't print error info.
Program proceeds normally if I change it to:







Code:
SDL_Init(SDL_INIT_EVERYTHING) != 0)


It won't print under just any circumstance.

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to check for an event

speartip
In reply to this post by speartip
sorry, in reply to this:

are printing regardless of whether or not there is an error.

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to check for an event

Jonathan Dearborn-2
Yes, but do you understand my point?  There is no error to print, so SDL_GetError() will not return an error message.  Since there is no error, go ahead and keep working on the rest of the program.

Jonny D


On Wed, Feb 15, 2017 at 4:07 PM, speartip <[hidden email]> wrote:
sorry, in reply to this:

are printing regardless of whether or not there is an error.

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to check for an event

speartip
In reply to this post by speartip
There is no error to print, so SDL_GetError()

No, I got you. Thanks for your patience. I was just experimenting b/c I wanted to see some of the error codes produced, etc.

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to check for an event

speartip
In reply to this post by speartip
Oh, ad I wanted a code so I could make sure the printf function was working. Right now I just get 1/2 back:

printf("SDL_Init failed: %s\n", SDL_GetError())

That's ok, I just want to make the code does work, and without an error hard to say.

But I've beat this topic up, so I am just going to move on here ...

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to check for an event

Jonathan Dearborn-2
Well, you could use SDL_SetError() to at least show something.


Jonny D


On Wednesday, February 15, 2017, speartip <[hidden email]> wrote:
Oh, ad I wanted a code so I could make sure the printf function was working. Right now I just get 1/2 back:

printf("SDL_Init failed: %s\n", SDL_GetError())

That's ok, I just want to make the code does work, and without an error hard to say.

But I've beat this topic up, so I am just going to move on here ...

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Loading...