Problems using Video and CDROM together

Well I gave up and started working on learning C++ again but this time
in conjunction with SDL. I was experimenting with the CD functions
when I encountered a strange problem and I’m not sure why this
happens.

If I initialize the CD subsystem, only, the use of SDL_CDNumDrives()
gives me 1 drive. SDL_CDName(0); gets me E:\ as is expected. It even
opens the CD with SDL_CDOpen as expected allowing me access to the
status and all of that.

However if I also initialize the video subsystem

SDL_Init(SDL_INIT_VIDEO||SDL_INIT_CDROM);

the use of SDL_CDNumDrives() returns a -1 and SDL_CDOpen(0) causes an
error that forces the program to shut down. And so far only when I
activate the video subsystem does this occur. When I use
SDL_INIT_EVERYTHING it works fine. So obviously I’m not in a bind
here. However I am curious as to why this would be. If it’s
something with SDL or the way I’ve been doing things.

All code displayed here is as is in my program. But for the sake of
not being asked to show it here’s the complete code.

#include “sdl.h”
#include <stdlib.h>

SDL_Event mainEvent;
SDL_Surface* mainScreen= NULL;
SDL_CD* cdToPlay;

int main(int argc, char* argv[])
{

SDL_Init(SDL_INIT_VIDEO||SDL_INIT_CD);
atexit(SDL_Quit);

mainScreen = SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT);

fprintf(stdout, “Number of drives: %d \n”, SDL_CDNumDrives());
for(int CDIndex = 0; CDIndex < SDL_CDNumDrives(); CDIndex++)
{
fprintf(stdout, “The name of Drive # %d is %s \n”, CDIndex,
SDL_CDName(CDIndex));
}

for(;:wink:
{
SDL_WaitEvent(&mainEvent);

  if(mainEvent.type == SDL_KEYDOWN)
     break;

  if(mainEvent.type == SDL_QUIT)
     break;

}

}

Double || is logical OR (which will equate to 1),
you want binary OR, a single |On Wed August 22 2007 21:46, Matthew Johnson wrote:

However if I also initialize the video subsystem

SDL_Init(SDL_INIT_VIDEO||SDL_INIT_CDROM);

Hi,

I think that there is something wrong with your library initialzation code:
you use a logical OR instead of a binary one…

try using SDL_Init(SDL_INIT_VIDEO | SDL_INIT_CDROM); instead, and it should
works fine.

---------- Message transf?r? ----------> From: “Matthew Johnson”

To: "A list for developers using the SDL library. (includes SDL-announce)"

Date: Wed, 22 Aug 2007 23:46:51 -0500
Subject: [SDL] Problems using Video and CDROM together…
Well I gave up and started working on learning C++ again but this time
in conjunction with SDL. I was experimenting with the CD functions
when I encountered a strange problem and I’m not sure why this
happens.

If I initialize the CD subsystem, only, the use of SDL_CDNumDrives()
gives me 1 drive. SDL_CDName(0); gets me E:\ as is expected. It even
opens the CD with SDL_CDOpen as expected allowing me access to the
status and all of that.

However if I also initialize the video subsystem

SDL_Init(SDL_INIT_VIDEO||SDL_INIT_CDROM);

the use of SDL_CDNumDrives() returns a -1 and SDL_CDOpen(0) causes an
error that forces the program to shut down. And so far only when I
activate the video subsystem does this occur. When I use
SDL_INIT_EVERYTHING it works fine. So obviously I’m not in a bind
here. However I am curious as to why this would be. If it’s
something with SDL or the way I’ve been doing things.

All code displayed here is as is in my program. But for the sake of
not being asked to show it here’s the complete code.

#include “sdl.h”
#include <stdlib.h>

SDL_Event mainEvent;
SDL_Surface* mainScreen= NULL;
SDL_CD* cdToPlay;

int main(int argc, char* argv[])
{

SDL_Init(SDL_INIT_VIDEO||SDL_INIT_CD);
atexit(SDL_Quit);

mainScreen = SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT);

fprintf(stdout, “Number of drives: %d \n”, SDL_CDNumDrives());
for(int CDIndex = 0; CDIndex < SDL_CDNumDrives(); CDIndex++)
{
fprintf(stdout, “The name of Drive # %d is %s \n”, CDIndex,
SDL_CDName(CDIndex));
}

for(;:wink:
{
SDL_WaitEvent(&mainEvent);

  if(mainEvent.type == SDL_KEYDOWN)
     break;

  if(mainEvent.type == SDL_QUIT)
     break;

}

}

Ah, okay. Thanks guys I knew I was doing something wrong. Now onto
the next challenge. Text. I don’t expect to be back for that one so
rest easy.

Have a great day everyone.On 8/23/07, Sebastien Dieu <dieu.j.sebastien at gmail.com> wrote:

Hi,

I think that there is something wrong with your library initialzation code:
you use a logical OR instead of a binary one…

try using SDL_Init(SDL_INIT_VIDEO | SDL_INIT_CDROM); instead, and it should
works fine.

---------- Message transf?r? ----------
From: “Matthew Johnson” < @Matthew_Johnson>
To: "A list for developers using the SDL library. (includes SDL-announce)"

Date: Wed, 22 Aug 2007 23:46:51 -0500
Subject: [SDL] Problems using Video and CDROM together…
Well I gave up and started working on learning C++ again but this time
in conjunction with SDL. I was experimenting with the CD functions
when I encountered a strange problem and I’m not sure why this
happens.

If I initialize the CD subsystem, only, the use of SDL_CDNumDrives()
gives me 1 drive. SDL_CDName(0); gets me E:\ as is expected. It even
opens the CD with SDL_CDOpen as expected allowing me access to the
status and all of that.

However if I also initialize the video subsystem

SDL_Init(SDL_INIT_VIDEO||SDL_INIT_CDROM);

the use of SDL_CDNumDrives() returns a -1 and SDL_CDOpen(0) causes an
error that forces the program to shut down. And so far only when I
activate the video subsystem does this occur. When I use
SDL_INIT_EVERYTHING it works fine. So obviously I’m not in a bind
here. However I am curious as to why this would be. If it’s
something with SDL or the way I’ve been doing things.

All code displayed here is as is in my program. But for the sake of
not being asked to show it here’s the complete code.

#include "sdl.h "
#include <stdlib.h>

SDL_Event mainEvent;
SDL_Surface* mainScreen= NULL;
SDL_CD* cdToPlay;

int main(int argc, char* argv[])
{

SDL_Init(SDL_INIT_VIDEO||SDL_INIT_CD);
atexit(SDL_Quit);

mainScreen =
SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT);

fprintf(stdout, “Number of drives: %d \n”, SDL_CDNumDrives());
for(int CDIndex = 0; CDIndex < SDL_CDNumDrives(); CDIndex++)
{
fprintf(stdout, “The name of Drive # %d is %s \n”, CDIndex,
SDL_CDName(CDIndex));
}

for(;:wink:
{
SDL_WaitEvent(&mainEvent);

  if(mainEvent.type == SDL_KEYDOWN)
     break;

  if(mainEvent.type == SDL_QUIT)
     break;

}

}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org