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

Author Topic: "Internal OpenGL call" help  (Read 11185 times)

0 Members and 1 Guest are viewing this topic.

Solluxx

  • Newbie
  • *
  • Posts: 19
    • View Profile
"Internal OpenGL call" help
« on: January 10, 2013, 07:16:35 am »
Hi everyone, first I must say what a great community! anyways so I recently started with sfml and am self taught in c++ so don't get too technical on me if possible :)

So in my program I have a game class, player class, and graphics class(among others). The program runs fine but I get this error in the console >

An internal OpenGL call failed in Texture.cpp (95) : GL_INVALID_OPERATION, the s
pecified operation is not allowed in the current state
An internal OpenGL call failed in Texture.cpp (95) : GL_INVALID_OPERATION, the s
pecified operation is not allowed in the current state

Process returned 0 (0x0)   execution time : 1.947 s
Press any key to continue.

The strange thing is the program seems to run fine. the code just loads up a texture, turns it in to a sprite then draws it to the screen.

Game class...(part of it)
void Game::GameLoop()
{
    Graphics graphics;
    Player player1;

    while (isRunning)
    {

        player1.Update();

        graphics.ClearWindow();
        graphics.Draw(player1.xposition,player1.yposition,player1.direction);
        graphics.DrawWindow();

        //Close out of the window
        isRunning = graphics.QueryWindow();

    }

    graphics.~Graphics();
}
 
Graphics.h
#ifndef GRAPHICS_H
#define GRAPHICS_H


#include <SFML/Graphics.hpp>

class Graphics
{
    public:
        Graphics();
        ~Graphics();
        void Load();
        void Draw(int xposition,int yposition,char direction);
        void DrawWindow();
        void ClearWindow();
        bool QueryWindow();
        sf::RenderWindow window;
        sf::Texture chartexture;
        sf::Sprite charsprite;
    protected:
    private:
};

#endif // GRAPHICS_H
 
Graphics.cpp
#include "Graphics.h"

Graphics::Graphics()
{
    window.create(sf::VideoMode(800, 600, 32), "SFML works!");
    Load();
}
void Graphics::Load()
{
    chartexture.loadFromFile("data/graphics/characters/old man.bmp");
    charsprite.setTexture(chartexture);
}
void Graphics::Draw(int xposition,int yposition,char direction)
{
    window.draw(charsprite);
}
void Graphics::DrawWindow()
{
    window.display();
}
void Graphics::ClearWindow()
{
    window.clear(sf::Color::Red);
}
bool Graphics::QueryWindow()
{
    sf::Event windowstate;
    while (window.pollEvent(windowstate))
    {
        if(windowstate.type == sf::Event::Closed)return false;
    }
    return true;
}
Graphics::~Graphics()
{
        chartexture.~Texture();
        window.close();

}
 

Any help on how to do away with this would be great. It does't hamper the program but I can see it being problematic down the line...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: "Internal OpenGL call" help
« Reply #1 on: January 10, 2013, 07:28:53 am »
Welcome! :)

Can you please specify what OS, which exact compiler you use and from where you got SFML from?

Additionally you should provide a minimal (as less code as possible) and complete (everything is contained, so one can directly compile it) example, that reproduces the problem, so we can be 100% sure it's not caused by your code.

Blind guess: Is you're graphics driver uptodate?
« Last Edit: January 10, 2013, 06:00:27 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: "Internal OpenGL call" help
« Reply #2 on: January 10, 2013, 09:34:43 am »
graphics.~Graphics();
chartexture.~Texture();
This is undefined behavior. Do not call destructors explicitly!

In your example, you need neither call nor define destructors, RAII does everything automatically.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Solluxx

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: "Internal OpenGL call" help
« Reply #3 on: January 10, 2013, 05:53:46 pm »
Thanks Nexus! that did it. Here is an example of my shaky self taught programming techniques :P so if the destructor of the graphics class is automatically called what do I put in it to de-allocate the textures and sprites so I don't cause memory leaks?

> Thanks eXpl0it3r for the tips i'll keep them in mind next time I post :)

edit: object destruction is something I'm not totally familiar with but i'll look it up. The exact syntax for de-allocating textures and sprites(if you even have to for sprites since they are just pointing to data) would still be helpful.
« Last Edit: January 10, 2013, 06:05:15 pm by Solluxx »

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Re: "Internal OpenGL call" help
« Reply #4 on: January 10, 2013, 06:52:02 pm »
Quote
what do I put in it to de-allocate the textures and sprites so I don't cause memory leaks?
You may want to read a basic C++ book and also do a search for RAII, and read the documentation for SFML.

int main()
{
    // ...

    {
        sf::Texture t ;
        t.loadFromFile(/**/) ;     // resource is loaded.
        // ...
    }                                        // resource is freed.

    {
         sf::Texture * t = new sf::Texture ;
         t->loadFromFile( /**/ ) ;   // resource is loaded.
         // ...
         delete t ;                          // resource is freed.
    }

    {
         std::unique_ptr<sf::Texture> t = new sf::Texture ;
         t->loadFromFile( /**/ ) ;     // resource is loaded.
         // ...
    }                                             // resource is freed.
}

[Edit:  Oops.  Missed the cpp tag somehow.]
« Last Edit: January 10, 2013, 09:29:06 pm by cire »

Solluxx

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: "Internal OpenGL call" help
« Reply #5 on: January 10, 2013, 07:13:23 pm »
Thanks for the help! since my whole program(all the classes and everything) are in the scope of main won't everything just automatically clean itself up? All my textures are in class headers so I feel like making everything a pointer and having to clean up after it would be a pain in the ***.

this post is getting way off topic...

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: "Internal OpenGL call" help
« Reply #6 on: January 10, 2013, 08:11:06 pm »
All my textures are in class headers so I feel like making everything a pointer and having to clean up after it would be a pain in the ***.
Right, that's why you don't do it ;)

A lot of people constantly use new and delete, but this is very bad practice. Especially with C++11, there are almost no cases left where memory must be managed manually. RAII describes the principle that resources (and memory is a resource) can be managed automatically, which is possible because of deterministic destructors. It is basically just that:
void function()
{
    sf::Texture t;
    ...
} // t destroyed when the variable goes out of scope
  // sf::Texture uses RAII internally, so it cleans up its own resources

class MyClass
{
    sf::Texture t; // t destroyed in the destructor (compiler-generated)
};

In this thread, I described the advantages of RAII in details.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Solluxx

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: "Internal OpenGL call" help
« Reply #7 on: January 10, 2013, 10:00:49 pm »
Oh cool thanks! Long live RAII  ;D

 

anything