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

Author Topic: sfml2.0-rc pushStates/poStates crash (with Horde3d)  (Read 4445 times)

0 Members and 1 Guest are viewing this topic.

mystb

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
sfml2.0-rc pushStates/poStates crash (with Horde3d)
« on: April 10, 2013, 11:30:11 am »
Hi all,

 I'm trying to run a c++ + lua + sfml + horde3D environment.
Everything is running, e.g., I can draw 2D stuff with sfml and I can draw 3D stuff with Horde3D... but not at the same time. If I enable both it just crashes.

I've asked for help on gamedev (http://www.gamedev.net/topic/641539-mixing-sfml-and-horde3d-operation-not-allowed-in-current-state/ ) but thinking about it, I might have a better chance of finding some help here.

Window Creation:
function window:create(cfg)
  ...
  ...
  llwindow.set_window_style(style)
  llwindow.create_window(title)               -- SFML::RenderWindow

  self:pushStates() -- [1]
end
 
So, here is my main render loop:
function render:tick()
   self:setWireFrameMode(self.d3doptions.WireFrameMode)    -- HORDE3D specific
   self:setDebugViewMode(self.d3doptions.DebugViewMode)    -- HORDE3D specific
   window:clear()                                          -- SFML::RenderWindow
   self.camera.object:update()                             -- HORDE3D specific
   llrender.render(self.camera.object) --[2]               -- HORDE3D specific

   window:popStates() --[3]                                -- SFML::Window
   window:resetStates() --[4]                              -- SFML::Window
   overlaymanager:tick(self.dimensions) --[5]              -- SFML::Text, SFML::Sprite, etc....
   window:pushStates() --[6]                               -- SFML::Window
   
   llrender.finalize()   --[7]                             -- HORDE3D specific
   window:display()                                        -- SFML::Window
end
 
With 1,3,4,5,6 enabled and 2,7 commented out, SFML outputs ok, but outputs this message once:
 An internal OpenGL call failed in RenderTarget.cpp (269) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
 
With 1,3,4,5,6 commented and 2,7 enabled Horde3d outputs ok.
With any combination of these... app crashes first time that llrender.render(self.camera.object)  is called or after outputting several GL_INVALID_OPERATION messages like above.

Any help would be appreciated  :)
P.S: sorry for my spelling/grammar, I'm portuguese.
(Edited for formatting)
« Last Edit: April 10, 2013, 02:07:37 pm by mystb »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sfml2.0-rc pushStates/poStates crash (with Horde3d)
« Reply #1 on: April 10, 2013, 11:44:34 am »
Your usage of push/popGLStates is incorrect, please read the doc carefully, there are examples.

Try to call this after drawing with SFML (and popping the GL states):
glCheck(glDisableClientState(GL_VERTEX_ARRAY));
glCheck(glDisableClientState(GL_COLOR_ARRAY));
glCheck(glDisableClientState(GL_TEXTURE_COORD_ARRAY));

But do you really need to use SFML to draw 2D stuff? A sprite is just a square rendered with an orthographic projection. It's straight-forward stuff for a 3D API.
Laurent Gomila - SFML developer

mystb

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: sfml2.0-rc pushStates/poStates crash (with Horde3d)
« Reply #2 on: April 10, 2013, 11:52:58 am »
I'll look at the docs, and try your suggestion.

About the 2D,3D question: I know that Horde3D also has overlay support, but my intention here is to learn and have fun. For starters, I might do a pong clone with it  :P I know that I could code something in two days, without lua, tolua and horde3d, but maybe I can learn something in the process.

Thanks for your help, I'll give feedback.

mystb

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: sfml2.0-rc pushStates/poStates crash (with Horde3d)
« Reply #3 on: April 10, 2013, 12:23:07 pm »
My sfml version doesn't have glcheck.hpp/cpp, so I hacked one.

With this function:
function c:tick()
        self:setWireFrameMode(self.d3doptions.WireFrameMode)
        self:setDebugViewMode(self.d3doptions.DebugViewMode)
        c.handlers.window:clear()
        self.camera.object:update()
        llrender.render(self.camera.object)

        print("BEFORE PUSHSTATES")
        c.handlers.window:pushStates()
        print("BEFORE 2DTICK")
        c.handlers.overlaymanager:tick(self.dimensions)
        print("AFTER 2DTICK")
        c.handlers.window:popStates()
        print("AFTER POPSTATES")
        print(testgl())
        print("AFTER GLTEST")
        llrender.finalize()    
        c.handlers.window:display()
end
 
I get this output:
BEFORE PUSHSTATES
An internal OpenGL call failed in RenderTarget.cpp (252) : GL_INVALID_OPERATION, the specified operation is not allowed in the current stat

BEFORE 2DTICK
An internal OpenGL call failed in Texture.cpp (469) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Texture.cpp (469) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Texture.cpp (469) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Texture.cpp (469) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Texture.cpp (469) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
AFTER 2DTICK
An internal OpenGL call failed in RenderTarget.cpp (269) : GL_INVALID_OPERATION, the specified operation is not allowed in the current stat

AFTER POPSTATES
GL_VERTEX_ARRAY:no error
GL_COLOR_ARRAY:no error
GL_TEXTURE_COORD_ARRAY:no error

 
and this on screen (image is small but what I get is just colored blocks):


any idea?
« Last Edit: April 10, 2013, 02:09:12 pm by mystb »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sfml2.0-rc pushStates/poStates crash (with Horde3d)
« Reply #4 on: April 10, 2013, 12:27:56 pm »
Which version of SFML are you using? Or maybe you can directly tell me which are the OpenGL calls that fail at lines 252, 269 and 469.

Quote
About the 2D,3D question: I know that Horde3D also has overlay support, but my intention here is to learn and have fun
I'm not sure that mixing SFML with a 3D engine is a good thing to learn. I couldn't even tell you what behaviour to expect from such a combination. To me it's more a hack than a cool thing to try. And it's not fun.
Laurent Gomila - SFML developer

mystb

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: sfml2.0-rc pushStates/poStates crash (with Horde3d)
« Reply #5 on: April 10, 2013, 12:47:12 pm »
Which version of SFML are you using? Or maybe you can directly tell me which are the OpenGL calls that fail at lines 252, 269 and 469.

251: glCheck(glMatrixMode(GL_TEXTURE));
252: glCheck(glPushMatrix());

268: glCheck(glMatrixMode(GL_TEXTURE));
269: glCheck(glPopMatrix());

468: glCheck(glMatrixMode(GL_TEXTURE));
469: glCheck(glLoadMatrixf(matrix));

Oops... I had glCheck... sorry. I was searching for SFML/Graphics/GLcheck.hpp, that's why I couldn't find it.

my tgz file with sfml source is named: LaurentGomila-SFML-2.0-rc-114-g03b8a1c.tar.gz

I'm not sure that mixing SFML with a 3D engine is a good thing to learn. I couldn't even tell you what behaviour to expect from such a combination. To me it's more a hack than a cool thing to try. And it's not fun.
I'm really starting on this 2D or 3D stuff and as many people, I don't have a clear objective, so I just started to collect some stuff that I *though* it should be useful some day. Maybe its time to lay down some plans and stay on track. But, if you don't mind helping out, I would like to track this down :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sfml2.0-rc pushStates/poStates crash (with Horde3d)
« Reply #6 on: April 10, 2013, 01:30:59 pm »
It's funny that the texture matrix always fails, and nothing else. Do you get the same error with a SFML-only program?

Quote
I'm really starting on this 2D or 3D stuff and as many people, I don't have a clear objective, so I just started to collect some stuff that I *though* it should be useful some day. Maybe its time to lay down some plans and stay on track.
You can test many graphics API, but... one at a time ;)
« Last Edit: April 10, 2013, 02:05:25 pm by Laurent »
Laurent Gomila - SFML developer

mystb

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: sfml2.0-rc pushStates/poStates crash (with Horde3d)
« Reply #7 on: April 10, 2013, 02:02:08 pm »
It's funny that the texture matrix always fails, and nothing else. Do you get the same error with a SFML-only program?

Not at all. No errors, no warnings. Everything is correct. I just tried something now... I commented out every piece of horde3d interaction, but not h3dInit(), and I get this behavior too. Commenting it, everything works, enabling it, it gives the same results as with everything in.

Quote
You can test many graphics API, but... one at a time ;)

I've seen that it's a recurring subject on the forum :) It says something (good) about SFML, doesn't it?  ;)
« Last Edit: April 10, 2013, 02:05:32 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sfml2.0-rc pushStates/poStates crash (with Horde3d)
« Reply #8 on: April 10, 2013, 02:06:05 pm »
Quote
It says something (good) about SFML, doesn't it?
Or something bad about users ;D
Laurent Gomila - SFML developer

Skwint

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: sfml2.0-rc pushStates/poStates crash (with Horde3d)
« Reply #9 on: June 01, 2013, 12:59:21 am »
I have exactly the same issue - after calling h3dInit all SFML sprites become single colour blocks.  However, I also then crash shortly afterwards.  :-\

I think taking a working 3D engine and implementing 2D yourself is probably easier than taking the 2D SFML and trying to make a 3D engine play nicely with it.  Infact, the only reason I'm attempting this atall is that I have a lot of work complete using SFML and SFGUI which I don't want to redo.

ColinDuquesnoy

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: sfml2.0-rc pushStates/poStates crash (with Horde3d)
« Reply #10 on: December 20, 2013, 09:46:47 am »
I had the exact same issue. I managed to fix it by turning on the texture unit 0 before calling window.resetGLStates()

pSfmlWindow->clear();

// Render horde3D scene
app->mainLoop( benchmark ? 60 : fps );

// Explicitely enable texture unit 0!
glClientActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
pSfmlWindow->resetGLStates();

// render SFML scene
pSfmlWindow->draw(text);  // text is a sf::Text
pSfmlWindow->draw(sprite); // sprite is a sf::Sprite

ColinDuquesnoy

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: sfml2.0-rc pushStates/poStates crash (with Horde3d)
« Reply #11 on: December 20, 2013, 12:07:14 pm »
The above fix works and have been tested on Windows Xp and Linux Mint 16.

However I am not sure where to report the bug/fix? Should I submit a pull request that add glClientActiveTexture to sf::RenderTarget::resetGLStates or should I report it on the Horde3D issue tracker?