Sign in to follow this  

Annoying Problem (SDL Related?)

This topic is 4531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been using SDL with code::blocks but can't seem to launch programs from windows. They compile and run as expected from within the compiler and they run fine when ran from a command prompt but do nothing when ran from the explorer. If I put the command to launch them in a batch file they run fine too. Any idea what the problem might be?

Share this post


Link to post
Share on other sites
If you run them via a shortcut does it work? Does changing the working directory affect it?

For that matter, if you make an app which doesn't use SDL, can you run it from explorer?

Share this post


Link to post
Share on other sites
Quote:
Original post by Squirm
If you run them via a shortcut does it work? Does changing the working directory affect it?

For that matter, if you make an app which doesn't use SDL, can you run it from explorer?


Shortcuts do not work either. I created a console Hello World app and it ran as expected.

Share this post


Link to post
Share on other sites
This couldn't be a problem with the code could it? I don't have the slightest idea what would make it not run from the GUI but launch fine from the CLI.

Share this post


Link to post
Share on other sites
It launched correctly through Windows 98. I'd suggest messing around with it a bit more. Write a message to a log file after each line of code in main, so you can see where it goes off the rails. Try cutting the xml file and doing the bare minimum to create the window. Try using a different version of the SDL library if they're available.

Share this post


Link to post
Share on other sites
The only additional dll it seems to need is SDL, and that does give you a message if it can't be located. I got that first, as I didn't have SDL on this machine. The only external file it appears to use is config.xml, but that just crashes if it can't be located, which is bad, but not the cause of this problem. I thought it might be a path issue too, but I tried quite a few things, and that doesn't seem to be the case.

Share this post


Link to post
Share on other sites
Yeah, no error checking for that yet. I've got the SDL dll in my system folder. I'll try a basic SDL windows and see what I can get.

Edit: Regular SDL app ran as expected. Any suggestions?

Share this post


Link to post
Share on other sites
Quote:
Original post by Nemesis2k2
Write a message to a log file after each line of code in main, so you can see where it goes off the rails.


I tried writing something to a log file right after main() and it doesn't write anything at all when I run it from the GUI. Still behaves as normal from CLI or batch.

Share this post


Link to post
Share on other sites
Your program has the same problem on my machine, but it worked fine when I compiled your code with VS.NET, at least after I added a return value to se_window::InitWindow() (can't compile otherwise).

Is there a file called Makefile that wasn't included. I couldn't find a file that specified linker options but I noticed <Option makefile="Makefile"/> in SDL_Engine.cbp. In any case, what are your linker options?

Share this post


Link to post
Share on other sites
Hi!

I was able to reproduce your problem. The program ran fine from Code::Blocks and via .bat but didn't show up after starting from explorer.
After removing the stdout and stderr redirection in the method se_window::InitWindow it worked from explorer.

int se_window::InitWindow()
{
//FILE * ctt = fopen("CON", "w" );
SDL_Init(SDL_INIT_VIDEO);
//freopen("CON", "w", stdout);
//freopen("con", "w", stderr);
//fclose( ctt );
}




I don't have an explanation for this only assumptions:
Maybe by starting through the IDE or a .bat file a console window is created explicitly so your redirection works. But by starting in the explorer something is missing...
In such a case I used to build my own SDL libraries from source and disabled the stdout redirection using the provided configure.sh.

Edit:
This makes sense considering what the above poster said (it worked when compiling wirh MSVC++) because the VC++ libraries don't have the redirection enabled.

Share this post


Link to post
Share on other sites
Thank you all very much. I'm stuck doing PHP development during the day and my new son only leaves me a few hours a week to work on any "fun" project so I really appreciate the help since I've got quite a limited time to work on this stuff. I'll have to look into the redirection thing.

Quote:
Original post by baumep
In such a case I used to build my own SDL libraries from source and disabled the stdout redirection using the provided configure.sh.

Edit:
This makes sense considering what the above poster said (it worked when compiling wirh MSVC++) because the VC++ libraries don't have the redirection enabled.


Do you know of a way to disable redirection in Code::Blocks without having to compile your own dll? I had to add that stuff (hack) in there to be able to write anything to stdout.

I'd like to keep writing to the console window while working out the bulk of the code because it's quite easy to see what you need to see. At some point I'd like to redirect stdout to a console window or logfile.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ternary
I added a return value to se_window::InitWindow() (can't compile otherwise).


I can't believe Code::Blocks didn't catch that! I thought if you specified a return type that a return value was required. Is this a standards compliance issure with Code::Blocks?

Share this post


Link to post
Share on other sites
I don't know of a way to avoid that without recompiling. But a quick workaround is to add a check in se_window::InitWindow() so the program doesn't crash. The effect is that console output will still work via IDE and .bat and if started from Explorer the program doesn't crash anymore and writes to stdout.txt instead.

int se_window::InitWindow()
{
FILE * ctt = fopen("CON", "w" );
SDL_Init(SDL_INIT_VIDEO);
if (ctt)
{
freopen("CON", "w", stdout);
freopen("con", "w", stderr);
fclose( ctt );
}
}




[Edited by - baumep on July 21, 2005 4:24:06 PM]

Share this post


Link to post
Share on other sites

This topic is 4531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this