Advertisement

SDL Permission denied

Started by May 16, 2014 11:24 PM
7 comments, last by rip-off 10 years, 6 months ago

Hello All,

I am using Code Blocks IDE and SDL. When I was coding in SDL for putting images on the screen and run the program. It worked fine. I decide to change window size then I run the program again but It say SDL Permission denied !

How can I fixed that?

Post your actual error message.

Likely, you were compiling, but your previous build was still running in the background, so your compiler couldn't erase the old exe and write the new exe, because you can't delete an exe that the OS is currently running.

tldr: Make sure your executable is closed before recompiling.

Advertisement

SDL FOLDER

118hi54.jpg

SDL >> BIN Folder

ngzz3d.jpg

SDL >> BIN >> Debug Folder

2q1827a.jpg

SDL >> BIN >> Release

2qnwok4.jpg

Code Block IDE with SDL Code

v3ke94.jpg

What Do I need to do to stop from Happening again because I always changing code every time I run the program to make better and adding some stuffs on screen

tldr: Make sure your executable is closed before recompiling.

Hmmm...how do I do that?

Let's break down the error. The source is ld.exe, which is the Linker. The Linker's job is to produce an executable from the various object files, and any libraries. The message mentions C:\Users\DMC\Desktop\SDL\main.exe, so this would be the executable you're building. The message says it cannot open the file due to a permission error. Windows is designed such that any executable file which currently has a running process cannot be modified or deleted. A very likely source of this error is that your program is still running, but you're trying to recompile. There are other ways you could get this error but they are less likely.

How do you avoid this error? The simplest case is where you can see the program's UI Window - simply exit the program, perhaps using the red X in the corner, or hitting the Escape key if you've written your program to close in response to this. It can be handy to implement such a key in Debug mode to speed up development.

You might have a problem if you've introduced a bug in your code where it will not exit when told, or you might be running a program that enters an infinite loop / deadlocks before there is any Window to close.

In this case, if the process is launched from your IDE you may be able to "break into" it using the Debugger to investigate the source of the bug, or simple terminate it if you believe you know what is wrong.

If you cannot see a UI, and your IDE isn't running the process, you can open the Task Manager and try to locate the process there and terminate it. Be careful - if you terminate the wrong process, such as your IDE, you may lose any unsaved work!

If that still doesn't work, there are other possible causes, but as mentioned they are not very likely.

Thanks for reply and I know what you mean....

My code

#include "SDL/SDL.h"

//The images
SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;

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

//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );

//Set up screen
screen = SDL_SetVideoMode(640, 320, 32, SDL_SWSURFACE );

//Load image
hello = SDL_LoadBMP( "STARFIELDS.BMP" );

//Apply image to screen
SDL_BlitSurface( hello, NULL, screen, NULL );

//Update Screen
SDL_Flip( screen );

//Pause
SDL_Delay( 2000 );

//Free the loaded image
SDL_FreeSurface( hello );

//Quit SDL
SDL_Quit();

return 0;
}

Advertisement

Thanks for reply and I know what you mean....

To me, this reads like you understand the problem and how to solve it in future ... but then you also posted your code, do you have another question?

I was showing what my code but is there where key can press by user if he/she want press escape key to quit?

That program looks like it would quit automatically after about two seconds, provided no errors occur which would cause it to behave otherwise. If you want it to respond to the close window button, or to the escape key, you'd need to add a little input loop.

While in practise an error (e.g. no STARFIELDS.BMP file is found) may either be compensated for by checks in the rest of the code, or may cause a segfault, that you are doing no error checking and recovery means that it is possible that your program invokes undefined behaviour, which means that your process might do unexpected things (such as hang).

Here is your program but with error checking added to the initialisation functions:

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

//The images
SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;

int main( int argc, char* args[] )
{
    //Start SDL
    if(SDL_Init( SDL_INIT_EVERYTHING ) < 0) {
        std::cerr << "Failed to initialise SDL: " << SDL_GetError() << std::endl;
        return 1;
    }

    //Set up screen
    screen = SDL_SetVideoMode(640, 320, 32, SDL_SWSURFACE );
    if(!screen) {
        std::cerr << "Failed to set video mode: " << SDL_GetError() << std::endl;
        SDL_Quit();
        return 1;
    }

    //Load image
    hello = SDL_LoadBMP( "STARFIELDS.BMP" );
    if(!hello) {
        std::cerr << "Failed to load image: " << SDL_GetError() << std::endl;
        SDL_Quit();
        return 1;
    }

    //Apply image to screen
    SDL_BlitSurface( hello, NULL, screen, NULL );

    //Update Screen
    SDL_Flip( screen );

    //Pause
    SDL_Delay( 2000 );

    //Free the loaded image
    SDL_FreeSurface( hello );

    //Quit SDL
    SDL_Quit();

    return 0;
}
SDL_BlitSurface() and SDL_Flip() can also fail, so for full correctness you'd need to add similar logic at these points too.

This topic is closed to new replies.

Advertisement