Public Group

# Creating an SFML Window causes my Application to crash

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

## Recommended Posts

Hello, I have been following the Beginner's Tutorial 2 of the OGRE wiki. I wanted to customize the code by trying to make the "ninja" in the scene move when I press the U button

The user-input is supposedly being handled by SFML.

As far as I know, the Project is able to Build without linker errors, however, the application crashes the moment It tries to load the 3d scene after the dialogue for setting the graphics.

It gets the Buffer Overrun error dialogue

I was able to deduce that the problem occurs when I try to create the window for SFML. With the sf::Window line of code gone, It is able to work properly, as shown in my code
(note: I placed the event-handling code within comments to prove that the application crashes on the line that is supposed to create the sfml window for user input)

 /* ----------------------------------------------------------------------------- Filename: TutorialApplication.cpp ----------------------------------------------------------------------------- This source file is part of the ___ __ __ _ _ _ /___\__ _ _ __ ___ / / /\ \ (_) | _(_) // // _ | '__/ _ \ \ \/ \/ / | |/ / | / \_// (_| | | | __/ \ /\ /| | <| | \___/ \__, |_| \___| \/ \/ |_|_|\_\_| |___/ Tutorial Framework http://www.ogre3d.org/tikiwiki/ ----------------------------------------------------------------------------- */ #include "TutorialApplication.h" //add SFML #include<SFML\System.hpp> #include<SFML\Window.hpp> //#include<SFML\Graphics.hpp> TutorialApplication::TutorialApplication(void) { } TutorialApplication::~TutorialApplication(void) { } //------------------------------------------------------------------------------------- void TutorialApplication::createScene(void) { mSceneMgr->setAmbientLight(Ogre::ColourValue(0,0,0)); mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); Ogre::Entity* entNinja = mSceneMgr->createEntity("Ninja","ninja.mesh"); entNinja->setCastShadows(true); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entNinja); //the plane Ogre::Plane plane(Ogre::Vector3::UNIT_Y,0); Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z); Ogre::Entity* entGround = mSceneMgr->createEntity("GroundEntity","ground"); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entGround); //materials for the floor entGround->setMaterialName("Examples/Rockwall"); entGround->setCastShadows(false); //lights Ogre::Light* pointLight = mSceneMgr->createLight("pointLight"); pointLight->setType(Ogre::Light::LT_POINT); pointLight->setPosition(Ogre::Vector3(0,150,250)); pointLight->setDiffuseColour(1.0,0.0,0.0); pointLight->setSpecularColour(1.0,0.0,0.0); //directional light Ogre::Light* directionalLight = mSceneMgr->createLight("directionalLight"); directionalLight->setType(Ogre::Light::LT_DIRECTIONAL); directionalLight->setDiffuseColour(.25,0.25,0.0); directionalLight->setSpecularColour(.25,0.25,0.0); directionalLight->setDirection(Ogre::Vector3(0,-1,1)); //spotlight Ogre::Light* spotLight = mSceneMgr->createLight("spotLight"); spotLight->setType(Ogre::Light::LT_SPOTLIGHT); spotLight->setDiffuseColour(0, 0, 1.0); spotLight->setSpecularColour(0, 0, 1.0); spotLight->setDirection(-1, -1, 0); spotLight->setPosition(Ogre::Vector3(300, 300, 0)); spotLight->setSpotlightRange(Ogre::Degree(35),Ogre::Degree(50)); //SFML STUFF (The bug occurs when I try to create the next line sf::Window App(sf::VideoMode(20, 20, 32), "SFML Window"); //Error occurs @ this line based on my deductions /* while(App.IsOpened()) { sf::Event Event; while (App.GetEvent(Event)) { if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::U)) mSceneMgr->getRootSceneNode()->translate(Ogre::Vector3(10,0,0)); } } */ //cout << system("cd"); } void TutorialApplication::createCamera(void) { mCamera = mSceneMgr->createCamera("PlayerCam"); mCamera->setPosition(Ogre::Vector3(0,10,500)); mCamera->lookAt(Ogre::Vector3(0,0,0)); mCamera->setNearClipDistance(5); mCameraMan = new OgreBites::SdkCameraMan(mCamera); } void TutorialApplication::createViewports(void) { Ogre::Viewport* vp = mWindow->addViewport(mCamera); vp->setBackgroundColour(Ogre::ColourValue(0,0,0)); mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth())/Ogre::Real(vp->getActualHeight())); } #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 #define WIN32_LEAN_AND_MEAN #include "windows.h" #endif #ifdef __cplusplus extern "C" { #endif #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) #else int main(int argc, char *argv[]) #endif { // Create application object TutorialApplication app; try { app.go(); } catch( Ogre::Exception& e ) { #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR| MB_TASKMODAL); #else std::cerr << "An exception has occured: " << e.getFullDescription().c_str() << std::endl; #endif } return 0; } #ifdef __cplusplus } #endif `

What is disabling my application from handling user input properly? Can it be solved? Do i even need to create an SFML window in the first place for user-input? How do I solve this problem?

I'm stumped, SFML has been a roadblock in my quest of handling user input. The OGRE tutorials are much more bearable since they teach me how to setup the project and insert the code, in my opinion. I wonder if i should still use SFML after this experiment of mine....

Cheers.

##### Share on other sites
First off, this is a really wierd use of SFML, it generally assumes it will do the rendering. There are much more light weight IO libraries out there.

That said, to your direct problem... any chance you are using an ATI card? It so, read this, there is a known bug with a relatively easy work around.

##### Share on other sites

First off, this is a really wierd use of SFML, it generally assumes it will do the rendering. There are much more light weight IO libraries out there.

That said, to your direct problem... any chance you are using an ATI card? It so, read this, there is a known bug with a relatively easy work around.

Can you recommend to me personally a good IO Library?

##### Share on other sites
Why not OIS built in to Ogre? Otherwise it all comes down to platforms

##### Share on other sites
If you really don't want to use the Ogre's standard, you can use Allegro, as it is cross-platform.
Allegro is actually am alpha-omega tool, but it's really modular, so you can actually include only the parts that you need.

It's input capacity allows you to verify if a button is being pressed or you can use event driven input system. It has support to mouse+keyboard and joystics.

##### Share on other sites

If you really don't want to use the Ogre's standard, you can use Allegro, as it is cross-platform.
Allegro is actually am alpha-omega tool, but it's really modular, so you can actually include only the parts that you need.

It's input capacity allows you to verify if a button is being pressed or you can use event driven input system. It has support to mouse+keyboard and joystics.

On the same level, splitting out just the IO portions of SDL ( while still using Ogre for rendering ) is probably a better idea. SDL is much more modular than SFML, and is as such better suited for using portions of it.

1. 1
2. 2
frob
12
3. 3
4. 4
5. 5
Rutin
10

• 13
• 14
• 65
• 14
• 15
• ### Forum Statistics

• Total Topics
632130
• Total Posts
3004283

×