Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Access Violation.  (Read 3804 times)

0 Members and 1 Guest are viewing this topic.

Glue

  • Newbie
  • *
  • Posts: 10
    • View Profile
Access Violation.
« on: January 24, 2011, 05:57:14 pm »
Hello so, I downloaded the SFML SDK and got it set up etc. Linked the correct libraries to the configuration (release to release,debug to debug etc) and tried to compile the source code from the "Integrating with Win32" example.

This gives me an access violation during runtime and it points me at
Code: [Select]
sf::RenderWindow SFMLView2;

So, i decide to remove that certain line and run it, now it gives me another error during runtime:
"A buffer overrun has occurred in sfmltesting.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.

For more details please see Help topic 'How to debug Buffer Overrun Issues'."

The whole source code:
Code: [Select]
#include "global.h"

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lp,int nCmdShow)
{
WNDCLASS WindowClass;
WindowClass.style         = 0;
WindowClass.lpfnWndProc   = &WndProc;
WindowClass.cbClsExtra    = 0;
WindowClass.cbWndExtra    = 0;
WindowClass.hInstance     = hInstance;
WindowClass.hIcon         = NULL;
WindowClass.hCursor       = 0;
WindowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND);
WindowClass.lpszMenuName  = NULL;
WindowClass.lpszClassName = L"testclass";
RegisterClass(&WindowClass);

// Let's create the main window
HWND Window = CreateWindow(L"testclass", L"Orly", WS_SYSMENU | WS_VISIBLE, 0, 0, 800, 600, NULL, NULL, hInstance, NULL);

DWORD Style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
HWND  View1 = CreateWindow(L"STATIC", NULL, Style, 50,  100, 300, 400, Window, NULL, hInstance, NULL);

sf::RenderWindow SFMLView1;
SFMLView1.Create(View1);

MSG Message;
Message.message = ~WM_QUIT;
while (Message.message != WM_QUIT)
{
if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
else
{
// SFML rendering code goes here
}
}

DestroyWindow(Window);

UnregisterClass(L"testclass", hInstance);

return EXIT_SUCCESS;
}


As you can see I am merely trying to create those so-called "sfmlviews". It works fine if I remove the


Code: [Select]

sf::RenderWindow SFMLView1;
SFMLView1.Create(View1);


It shows me one box to the left.

I am using VC++ Express 2010 and i have recompiled the library without errors and i have told the linker where to find the lib's. Anyone wants to shed some more light on this?

P.S. global.h only contains the declaration for WndProc and  #include <SFML\Graphics.hpp>  + the definition for WndProc is inside another .cpp file.

I am running Windows 7 atm.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Access Violation.
« Reply #1 on: January 24, 2011, 06:20:52 pm »
What version of SFML are you using. The libs, which and how are you linking them?(In what order)
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Glue

  • Newbie
  • *
  • Posts: 10
    • View Profile
Access Violation.
« Reply #2 on: January 24, 2011, 06:23:13 pm »
Code: [Select]
#pragma comment(lib,"sfml-graphics.lib")
#pragma comment(lib,"sfml-window.lib")


This is inside the global.h and I'm using SFML 1.6.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Access Violation.
« Reply #3 on: January 24, 2011, 06:25:11 pm »
you've forgotten to link sfml-system. link that one first. Remember, you have to link the libraries after their dependencies.

Though don't know if this will fix it but it's a huge error and you won't be able to do anything at all without it ;)
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Glue

  • Newbie
  • *
  • Posts: 10
    • View Profile
Access Violation.
« Reply #4 on: January 24, 2011, 06:29:29 pm »
I did as you said and this is my order now:
1.System
2.Window
3.Graphics

However the buffer overrun error still shows up whenever I exit the application.

Code: [Select]
#if defined (_CRTBLD) && !defined (_SYSCRT)
    DebuggerWasPresent = IsDebuggerPresent();
    _CRT_DEBUGGER_HOOK(_CRT_DEBUGGER_GSFAILURE); // This line.
From "gs_report.c"

This is what it shows me.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Access Violation.
« Reply #5 on: January 24, 2011, 06:35:27 pm »
Are you possibly running on an ATI card with the latest drivers? The ATI drivers doesn't like SFML's dynamic library. Quick fix is using static instead. (Laurent will have this fixed in SFML2 some time in the future)

If it's not that then I have no idea. You'll have to wait for someone who is more experienced working with Win32 than me.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Glue

  • Newbie
  • *
  • Posts: 10
    • View Profile
Access Violation.
« Reply #6 on: January 24, 2011, 06:39:46 pm »
Well, I'm using Nvidia so I dont know about that. I could try using the static, but first I'm gonna have to figure how to do that.

And thank you for atleast trying to help me. :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Access Violation.
« Reply #7 on: January 24, 2011, 08:06:56 pm »
Quote
#pragma comment(lib,"sfml-graphics.lib")
#pragma comment(lib,"sfml-window.lib")

Can we see the full code? Are you sure that the debug versions are linked in debug? Is the error showing in debug or release?
Laurent Gomila - SFML developer

Glue

  • Newbie
  • *
  • Posts: 10
    • View Profile
Access Violation.
« Reply #8 on: January 24, 2011, 08:17:43 pm »
This shows up in release and that is the full code, globalfuncs.cpp simply contains the WndProc definition and global.h:

Code: [Select]
#pragma once

#include <SFML/Graphics.hpp>

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg,WPARAM wParam,LPARAM lParam);


I put the dependencies into the Linker->Input->Additional Dependencies in the same order as i said before so the #pragma comments is no longer in the code.

Also the sfml-stuff-s.lib's are the static libraries or?

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Access Violation.
« Reply #9 on: January 24, 2011, 08:23:46 pm »
Quote from: "Glue"
Also the sfml-stuff-s.lib's are the static libraries or?


Yepp but don't think it will change anything.

Quick question, are you capable of creating a normal SFML window without the win32 interface? Or you get the same result?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Glue

  • Newbie
  • *
  • Posts: 10
    • View Profile
Access Violation.
« Reply #10 on: January 24, 2011, 08:38:00 pm »
Well, I can create a window using SFML if that's what youre asking.



Code: [Select]
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML\Window.hpp>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main window
    sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window");

    // Start main loop
    bool Running = true;
    while (Running)
    {
        App.Display();
    }

    return EXIT_SUCCESS;
}


This works fine after I link the proper libraries.

Glue

  • Newbie
  • *
  • Posts: 10
    • View Profile
Access Violation.
« Reply #11 on: January 24, 2011, 09:09:25 pm »
SO I decided to create window using the
Code: [Select]
Window var(sf::VideoMode(800,600,32), "windowname");

However when it got to this point it gave me another access violation. I guess there is something with the Win32 API and SFML?

NOTE: I commented out the code relevant to creating a window with CreateWindow and such alike.

Code: [Select]

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lp,int nCmdShow)
{ /*
WNDCLASS WindowClass;
WindowClass.style         = 0;
WindowClass.lpfnWndProc   = &WndProc;
WindowClass.cbClsExtra    = 0;
WindowClass.cbWndExtra    = 0;
WindowClass.hInstance     = hInstance;
WindowClass.hIcon         = NULL;
WindowClass.hCursor       = 0;
WindowClass.hbrBackground = reinterpret_cast<HBRUSH>(2);
WindowClass.lpszMenuName  = NULL;
WindowClass.lpszClassName = L"testclass";
RegisterClass(&WindowClass);
*/
// Let's create the main window
//HWND Window = CreateWindow(L"testclass", L"Orly", WS_SYSMENU | WS_VISIBLE, 0, 0, 800, 600, NULL, NULL, hInstance, NULL);

//DWORD Style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
//HWND View1 = CreateWindow(L"STATIC", NULL, Style, 50,  25, 700, 515, Window, NULL, hInstance, NULL);
sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window");


MSG Message;
Message.message = ~WM_QUIT;
while (Message.message != WM_QUIT)
{
if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
else
{
//for(unsigned int index = 0;index > Oblist.size();index++)
//{
App.Display();
//}
}
}

//DestroyWindow(Window);

// Don't forget to unregister the window class
//UnregisterClass(L"testclass", hInstance);

return EXIT_SUCCESS;
}


EDIT:

Well apparently i can create a window in debug, release gives the access violation and now when i try the original application in debug i get (0xc0150002) And i find that extremely funny.  :cry:

EDIT1:

I got the SVN and compiled it. Apparently it likes the static debug so I'm gonna try the static release later too.  8)