SFML community forums

Help => General => Topic started by: Regen on June 25, 2008, 09:06:07 am

Title: Anoying problem
Post by: Regen on June 25, 2008, 09:06:07 am
Hi, I have been playing around with SFML for a while and now I wanted to start up again, so i checked out the tutorials and tested some code. But on the render-window-tutorial i get a wierd error. The program runs smooth until you shut it down, then an error dialoge appears:

"Run-Time Check Failure #2 - Stack around the variable 'App' was corrupted."

I dont thinks you have made a typo, and the code i have is copy-pasted so it must be some setting i have in visual studio 2008 that is wrong?

Thanks for any help in advance!
Title: Anoying problem
Post by: workmad3 on June 25, 2008, 09:28:55 am
I had that for a while... it turned out to be I was linking a bedug build of my program to the release build of the library, which alters memory layouts etc :)
Title: Anoying problem
Post by: Regen on June 25, 2008, 09:52:04 am
okej, sorry If the is a stuipid question, but how do i solve it?:P
Title: Anoying problem
Post by: Laurent on June 25, 2008, 11:19:23 am
Just link debug libraries (with "-d" suffix) in debug build. Isn't explained in the tutorial ?
Title: Anoying problem
Post by: Regen on June 25, 2008, 11:22:25 am
working fine now! But I still wonder, i have never linked the -d libraries, why do I have to do that now?

thanks!

p.s. point taken about the tutorial
Title: Anoying problem
Post by: workmad3 on June 25, 2008, 11:52:58 am
Not sure why you didn't get the problem before. I started with 1.2 (built myself with VS2008) and always had it if I link incorrectly.

I guess it is up to Laurent to reveal if he has added any particularly interesting stuff in debug builds that would cause this now :)
Title: Anoying problem
Post by: Laurent on June 25, 2008, 12:16:10 pm
There are two things to know about it :

1/ It crashes because of different versions of the standard libraries mixed together, so it's always been there and it will always be, with any library you'll use. This is a very common issue.

2/ The behaviour is everything but predictable, it can crash, freeze, format your computer, corrupt the memory in your music player, or work fine depending on what's inside the standard libraries and how you use it. So I'm not surprised you didn't notice it before.
Title: Anoying problem
Post by: workmad3 on June 25, 2008, 12:41:24 pm
About the only extra thing I know is that if you are using collections from the standard library (and sometimes even raw arrays) then a frequent debug feature is for them to be padded so as to detect things like overflows. If these are allocated with the release allocator and then released with the debug destructor (it can happen. Getting the correct destructor called when there are 2 versions in different dlls is difficult to say the least) then the memory appears corrupted because the padding characters aren't correct and you get that lovely error.
Title: Anoying problem
Post by: Regen on June 27, 2008, 03:18:21 pm
Something wierd just happend, i was working on another project, then i went back to my old code (the one that before had problems) and now it doesnt work! i have not done a thing with it....
this time the error message is:
"Run-Time Check Failure #2 - Stack around the variable 'State' was corrupted."

And this time i have linked to the "-d" libs! :(

edit: Probably I have done something to it but just dont remember:P
Title: Anoying problem
Post by: Avency on June 27, 2008, 03:35:56 pm
Try to rebuild the whole project.
Title: Anoying problem
Post by: Regen on June 27, 2008, 03:38:06 pm
ofcourse tried that, even tried it all in VS2005 to (wanted to test some other stuff there aswell)
Title: Anoying problem
Post by: Avency on June 27, 2008, 03:55:13 pm
It could be a code related problem.
Maybe a buffer overflow.
Make sure that all pointers point to a valid location.
Title: Anoying problem
Post by: Regen on June 30, 2008, 08:08:03 am
dont think it is, the code is the same as before (when it worked) must be some settings that's screwed up, I'l keep on testing foreward.

edit: The most annoying thing now is that the application wont start at all, before I atleast got the error message after closing it:(

edit again: Can't get this to work:(
Title: Anoying problem
Post by: workmad3 on June 30, 2008, 12:00:06 pm
have you done something like build a release build of your code with the debug libraries linked this time?
Title: Anoying problem
Post by: Regen on June 30, 2008, 12:20:19 pm
nope, building debug with debug libraries:(

edit: for some reason i cant create either a renderwindow or a "normal" window at all in any way, in any project.....get the same error:(

Even this code:
#include <SFML/WINDOW.HPP>

int main() {

   sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window");

   return 0;
}
 :(
Title: Anoying problem
Post by: Regen on July 07, 2008, 08:27:02 am
is it sure that not anyone have a clue? can for some reason dont do a thing in sfml with any kind of window:( been so for over a week now:(
Title: Anoying problem
Post by: SirJulio on July 07, 2008, 02:34:41 pm
Hi Regen,

do you use SVN versions or the 1.3 ? Some threading stuffs in your app ? If you use visual, make you use the crt corresponding to your config (/MDd => debug, /MD else).
Title: Anoying problem
Post by: Regen on July 07, 2008, 03:12:23 pm
hi!

I use the 1.3 versions, and it all worked great for some time, then i must have made somthing with my settings or so.

with threading, do you mean sf::tread? in that case, no.

i use VS2008 (and have tried the code with VS2005 to), so how do i change/check the setting you talked about?
Title: Anoying problem
Post by: SirJulio on July 07, 2008, 03:28:18 pm
For runtime lib, see in your project properties (C/C++ => code generation), debug config must be /MDd (multithread debug DLL) and release /MD (multithread DLL).

Can you upload somewhere an archive with your project to see if we can reproduce the bug ? =)
Title: Anoying problem
Post by: Regen on July 07, 2008, 03:39:24 pm
ah, well i found out that debug was on /MD but sadly.....it didnt help:(

hmm, i will try to find a way to upload it somewhere!

thanks for caring about me  :D

edit: project is here:
http://w17.easy-share.com/1700843849.html

(a lot of comersial and you have to see it for 15 secs....)
Title: Anoying problem
Post by: SirJulio on July 07, 2008, 04:26:20 pm
I see that you don't use project properties to specify your library and include paths (additional lib and include paths are empty). Try to erase all paths related to SFML you have specified in visual studio global options (tools => options => project and solutions => vc++ directories), and fill, in your project settings, "C/C++ => General => other include directories" ([SFML_1.3_path]/include/), "Linker => general => other libraries directories" ([SFML_1.3_path]/lib/).

My point is ,maybe, you link against old version of SFML and use 1.3 DLL which could cause the bug.

Anyway, i tried your project, and i couldn't reproduce your problem.

PS : Not sure about settings name, I use VS in french. =p
Title: Anoying problem
Post by: Regen on July 08, 2008, 09:17:26 am
I took away all settings in "tools -> options -> projects and solutions -> VC++ directories. All inc and lib have been taken away (even older inc/libs from other projects then SFML)

Not a thing changed :cry:  :cry:

I have been using other libraries such as delta3d and openscenegraph, when i did so I added som things in the path in windowssystem enviroment-variables..... can it have something to do with that? but if I only added?

thanks alot SirJulio for takin your time to test the thing! :D

edit: now I'm sick of this...resetting VS2008

edit again: I have now taken drastic messures and took another computer with a fresh copy of windows XP, installed VS2008, downloaded sfml 1.3.
I cheered when the code above worked and started to expand it, after about 15 i had some larger code to compile......then the error occured, so i took away everything i added the past 15 minutes, but the the error is STIL there! :evil: How is that even possible?!?!
Title: Anoying problem
Post by: Mindiell on July 08, 2008, 12:23:13 pm
Can you give us a sample code with this error ?

AMHA : The problem is between the keyboard and the chair  :wink:
Title: Anoying problem
Post by: Regen on July 08, 2008, 12:33:25 pm
Quote from: "Mindiell"
Can you give us a sample code with this error ?

AMHA : The problem is between the keyboard and the chair  :wink:


The simple sample-code is on page one at the bottom of this thread.
and yup, no doubt the biggest problem with the code is between the keyboard and the chair :lol:
Title: Anoying problem
Post by: SirJulio on July 08, 2008, 02:45:39 pm
Ok, some things :

- Could you try to compile your code with MinGW or another C++ compiler to see if you can reproduce the problem ?

- Make sure you use VS2008 library (and not the VS2005).

- Could you compile a very simple windows in WinApi

Code: [Select]
#include <windows.h>

LRESULT CALLBACK mainCallback(HWND mainWin, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;

        default:
            return DefWindowProc(mainWin, message, wParam, lParam);
    }
}

int WINAPI WinMain (HINSTANCE current, HINSTANCE previous, LPSTR comm, int mode)
{
    HWND mainWin;
    MSG message;
    WNDCLASS windowClass;

    windowClass.style = 0;
    windowClass.lpfnWndProc = mainCallback;
    windowClass.cbClsExtra = 0;
    windowClass.cbWndExtra = 0;
    windowClass.hInstance = NULL;
    windowClass.hIcon = NULL;
    windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    windowClass.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
    windowClass.lpszMenuName =  NULL;
    windowClass.lpszClassName = "test";

    // On prévoit quand même le cas où ça échoue
    if(!RegisterClass(&windowClass)) return FALSE;

    mainWin = CreateWindow( "test", "SFML test", WS_OVERLAPPEDWINDOW,
                            CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                            NULL, NULL, current, NULL);

    if (!mainWin) return FALSE;

    ShowWindow(mainWin, mode);
    UpdateWindow(mainWin);

    while (GetMessage(&message, NULL, 0, 0))
    {
        TranslateMessage(&message);
        DispatchMessage(&message);
    }
    return message.wParam;
}


Finally, if nothing worked, maybe you can try that (http://en.wikipedia.org/wiki/Exorcism). =D
Title: Anoying problem
Post by: Regen on July 08, 2008, 03:30:42 pm
Tried the winApi prog, works verry well (exeptions of just boxes instead of text in the upper left corner)

And I checked once again so i used the 2008 libs, and.....I did.

Have tried minigw a little but hate those long commands to compile, so I guess i try with:
"The power of christ compels juh!" :wink:

the most annoying thing is that it works for a little while, then stops without me changing even one setting:(
Title: Anoying problem
Post by: SirJulio on July 08, 2008, 04:28:53 pm
Damn ! though one !

Forgot to ask but did you use static or dynamic libs ? Have you tried both ?

You said that debug config works but not the release. Try to deactivate all optimisations (C/C++ => optimisation) of release cfg to see if that changes something.
Title: Anoying problem
Post by: Regen on July 09, 2008, 09:45:53 am
I maybe should tell you that now when i have my libs/includes in the VC-dir, when i refer to them both for the project additional and in the general extra includes/libs I still have a wierd problem... I still have to go to "controlpanel->system->EnviromentVariables", and there i have to add the searchpath to the sfml-dlls, if i dont do this...VS can't find them..'

but anyway, when i do that, I still get the other error, even if i have static/dynamic och both:S

Quote

You said that debug config works but not the release. Try to deactivate all optimisations (C/C++ => optimisation) of release cfg to see if that changes something.

When i took a new computer with a fresh copy of windows/VS2008 release works as good (read bad) as debug.
Title: Anoying problem
Post by: Laurent on July 09, 2008, 10:23:05 am
Which version of Visual C++ 2008 are you using ?
Title: Anoying problem
Post by: Regen on July 09, 2008, 10:24:08 am
Quote from: "Laurent"
Which version of Visual C++ 2008 are you using ?


Version 9.0 is there some problems with that?
Title: Anoying problem
Post by: Laurent on July 09, 2008, 10:36:44 am
Visual Studio 2008 uses Visual C++ 9.0, I already know that ;)

What I want to know is whether you're using the professional or express version, beta or stable, etc... If you're not sure you can give the full version number that you can find in the "About" dialog box.
Title: Anoying problem
Post by: Regen on July 09, 2008, 10:42:57 am
:oops:

microsoft Visual stuido 2008 professional edition
version 9.0.21022.8 RTM

sufficient? :)
Title: Anoying problem
Post by: Laurent on July 09, 2008, 11:05:05 am
Thanks ;)

Sorry if you already said it, but have you tried to recompile SFML yourself ?
Title: Anoying problem
Post by: Regen on July 09, 2008, 11:12:57 am
No I have not, if your not terrible tired of me by now, could you go trough the steps to do it? :roll:

and now some whining:
It all have worked sooo smoooooth before:( why wont it play with me now?:(
Title: Anoying problem
Post by: Laurent on July 09, 2008, 11:28:25 am
It's explained in the tutorial ("How to start" -> "Visual C++") ;)

Actually, all you have to do is to open SFML.sln, choose the configuration you want to build, and click "build".
Title: Anoying problem
Post by: Regen on July 09, 2008, 11:50:04 am
oki, now i have recompiled with every configuration there is...and stil....the same:(
Title: Anoying problem
Post by: Regen on July 10, 2008, 10:44:07 am
After some exorsism recomended by SirJulio it now works as clockwork.
I have no idea what so ever why it does and how it was done, but it sure works..

bows to the higher powers.

and thanks everyone