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

Author Topic: SFML.net 2.1 - Failed to activate window's context  (Read 3911 times)

0 Members and 1 Guest are viewing this topic.

doomy23

  • Newbie
  • *
  • Posts: 3
    • View Profile
SFML.net 2.1 - Failed to activate window's context
« on: December 12, 2013, 05:01:38 am »
Hi everyone,

So far I've been working on my project without any problems everything works great, I can load images from memory using SQLite binaries I can make animations and everything ! It's almost perfect for a beginning !

But one thing is really messed up ; event though everything works fine I get the "Failed to activate window's context" error... not once .. but twice... I've read and tried different things but none of them have solved the problem. So here it goes :



At first I didnt mind because everything worked fine anyway but I noticed that when the windows is initialized in fullscreen, I can see my taskbar over it... and in windowed mod, the windows doesnt go in front, even if I free the console.

As you can see, I use Windows 8 and I'm developing on VS2012 Ultimate. Does it have anything to do with my specs ? I tried compiling the code in the samples that comes with the lib and got the same error... even though it worked perfectly (even the openGL exemple)...

Here is my main
        static void Main(string[] args)
        {
            _settings = new Settings();
            _game = new Game(ref _settings);
            _fw = new Framework(ref _settings, true);

            _game.state = Game.State.InGame;

            // Début du TEST
            Panorama _pan = new Panorama(1);
            simple_sprite _pan_test = _pan.getSimpleSprite();

            Character _char = new Character(1);
            simple_sprite _char_test = _char.getSimpleSprite(1, Util.topPourcent(12));

            _game.Animate(new Animation(_game.state, ref _char_test,
                new Vector2f(Program.settings.resolution.res.X + _char_test.sprite.GetGlobalBounds().Width, Util.heightPourcent(12)),
                Util.SpritePositionCentered(_char_test.sprite.GetGlobalBounds(), Util.heightPourcent(12)),
                2000)
            );
            _game.Animate(new Animation(_game.state, ref _char_test, 0, 255, 2100));
            _game.Animate(new Animation(_game.state, ref _pan_test,
                new Color(0, 0, 0, 255),
                new Color(255, 255, 255, 255),
                1000)
            );

            Text _text = new Text("Test de police", new Font("DigitalDisorder.ttf"), Util.heightPourcent(4));
            _text.Color = new Color(255, 0, 0);
            _text.Position = Util.SpritePositionCentered(_text.GetGlobalBounds(), Util.heightPourcent(75));

            while (_fw.opened)
            {
                fw.preRender();

                _game.run();

                fw.window.Draw(_pan_test.sprite);
                fw.window.Draw(_char_test.sprite);
                fw.window.Draw(_text);

                fw.postRender();
            };
        }
 

And here's how I initialize the window
       public Framework(ref Settings settings, Boolean ShowConsole = false)
        {
            if(!ShowConsole)
                FreeConsole();
           
            _desktopMode = VideoMode.DesktopMode;

            ContextSettings contextSettings = new ContextSettings(32, 32, 0, 2, 0);

            if (settings.windowed)
                window = new RenderWindow(new VideoMode(settings.resolution.res.X, settings.resolution.res.Y, _desktopMode.BitsPerPixel), settings.project, Styles.Default, contextSettings);
            else
                window = new RenderWindow(new VideoMode(settings.resolution.res.X, settings.resolution.res.Y, _desktopMode.BitsPerPixel), settings.project, Styles.Fullscreen, contextSettings);

            window.SetVisible(true);

            if (settings.vSync)
                window.SetVerticalSyncEnabled(true);

            if (settings.joysticks > 0)
                mKeyHandler.checkConnectedJoystick(settings.joysticks - 1);

            window.Closed += new EventHandler(OnClosed);
            window.Resized += new EventHandler<SizeEventArgs>(OnResized);
            window.KeyPressed += new EventHandler<KeyEventArgs>(mKeyHandler.OnKeyPressed);
            window.KeyReleased += new EventHandler<KeyEventArgs>(mKeyHandler.OnKeyReleased);

            if (settings.joysticks > 0)
            {
                window.JoystickConnected += new EventHandler<JoystickConnectEventArgs>(mKeyHandler.OnJoystickConnected);
                window.JoystickDisconnected += new EventHandler<JoystickConnectEventArgs>(mKeyHandler.OnJoystickDisconnected);
                window.JoystickButtonPressed += new EventHandler<JoystickButtonEventArgs>(mKeyHandler.OnJoystickButtonPressed);
                window.JoystickButtonReleased += new EventHandler<JoystickButtonEventArgs>(mKeyHandler.OnJoystickButtonRelease);
                window.JoystickMoved += new EventHandler<JoystickMoveEventArgs>(mKeyHandler.OnJoystickMoved);
            }

            if (settings.icon.Length != 0)
            {
                try
                {
                    Stream stream = new MemoryStream(settings.icon);
                    Image icon = new Image(stream);
                    window.SetIcon(32, 32, icon.Pixels);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Icon loading failed : {0}", e.ToString());
                    throw;
                }
            }

            window.SetActive(true);
            this.preRender();
            window.PushGLStates();
            this.postRender();
        }
 

I'm lost... normally it shouldnt work with this error, right ?

So at this point I have two options :
  • Make the game borderless (and fullcscreen borderless with 1px larger then screen) which is a bit annoying...
  • Try using SFML with C++ and translate all my project from C# to C++... even more anoying...

I'd appreciate some help ! Thank you.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: SFML.net 2.1 - Failed to activate window's context
« Reply #1 on: December 12, 2013, 02:47:52 pm »
window.SetActive(true);
this.preRender();
window.PushGLStates();
this.postRender();

Why are you doing this? None of this is required unless you are doing drawing with raw OpenGL.

Quote
Try using SFML with C++ and translate all my project from C# to C++... even more anoying...

Well considering SFML.NET binds directly to CSFML (which statically links SFML) it won't change anything (if your code uses SFML the same way)  :)


And on a side note, since you are using SFML.NET you may want to take a look at NetEXT (see my signature) for some helper classes to help reduce some boilerplate code  ;)
« Last Edit: December 13, 2013, 02:51:00 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

doomy23

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML.net 2.1 - Failed to activate window's context
« Reply #2 on: December 13, 2013, 04:41:52 am »
MMMMmmm yeah But without it it doesn't show up.. well I'll try without PushGLState. I'll give it a shot

and I just looked at your code on bitbucket... Really awesome ! The result is cleaner then mine I'll give it a try and give you feedback !  ;)

Thank you a lot for you fast answer !

doomy23

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML.net 2.1 - Failed to activate window's context
« Reply #3 on: December 13, 2013, 04:58:58 am »
I've tried as you said, I removed the useless stuff, and..

IT WORKED JUST FINE AFTER THAT !!!!!!!!!!!!!!!!!!!!!!!!!!!!  :D
I still get the cant activate context error but my problem is fixed... so I guess its alright

I'm so happy ! THANNNXXX MAN !! YOUR THE BEST!!!!!!

Now I can focus on making my code better and your library extension is so cool ! all the things I spent hours and hours working on you have them and more, is there a doc for it ? Thor's doc ?
« Last Edit: December 13, 2013, 05:07:16 am by doomy23 »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: SFML.net 2.1 - Failed to activate window's context
« Reply #4 on: December 13, 2013, 02:49:08 pm »
Just follow Thor's documentation, since NetEXT aims to be a direct port of Thor you can use the same documentation.

However there a just a few small differences (mainly from differences in the actual language) and if you have any trouble feel free to ask any questions  ;)
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor