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

Author Topic: OpenGL error INVALID_OPERATION occurring for no reason?  (Read 1219 times)

0 Members and 1 Guest are viewing this topic.

NipIsTrue

  • Newbie
  • *
  • Posts: 15
    • View Profile
OpenGL error INVALID_OPERATION occurring for no reason?
« on: February 07, 2020, 01:49:58 pm »
I am working on a simple 2d game in sfml, and I recently ran into a problem when trying to write a mod system for the game. Basically, the mod system works by loading a dll into memory, and calling functions from it that return a subclass of one defined in my game. The loading works fine and the object is instantiated correctly, but it appears to have broken part of my rendering code that worked before, namely this part:


void Environment::render(sf::RenderWindow& window) {
        for (Spawner* spawner : m_spawners) {
                spawner->render(window);
        }

        for (Enemy* enemy : m_enemies) {
                enemy->render(window);
        }

        m_player.render(window);

        sf::RectangleShape shape(sf::Vector2f(20, 400));
        shape.setFillColor(sf::Color::Black);
        window.draw(shape);

        shape.setPosition(420, 0);
        window.draw(shape);

        shape.setSize(sf::Vector2f(400, 20));
        shape.setPosition(0, 0);
        window.draw(shape);

        shape.setPosition(20, 420);
        window.draw(shape);
}

While the spawners are rendering, the console prints a bunch of opengl errors. After further investigation with the debugger (visual studio). It appears that my spawner->render() function is never being called, which is odd. I'm not entirely sure what is happening here as this code works fine with spawners that are instantiated in the executable and not loaded from the dll. I'm new to loading a dll at runtime, is there some sort of problem I'm missing here?

Fx8qkaoy

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: OpenGL error INVALID_OPERATION occurring for no reason?
« Reply #1 on: February 08, 2020, 08:55:55 pm »
I am working on a simple 2d game in sfml, and I recently ran into a problem when trying to write a mod system for the game. Basically, the mod system works by loading a dll into memory, and calling functions from it that return a subclass of one defined in my game. The loading works fine and the object is instantiated correctly, but it appears to have broken part of my rendering code that worked before, namely this part:


void Environment::render(sf::RenderWindow& window) {
        for (Spawner* spawner : m_spawners) {
                spawner->render(window);
        }

        for (Enemy* enemy : m_enemies) {
                enemy->render(window);
        }

        m_player.render(window);

        sf::RectangleShape shape(sf::Vector2f(20, 400));
        shape.setFillColor(sf::Color::Black);
        window.draw(shape);

        shape.setPosition(420, 0);
        window.draw(shape);

        shape.setSize(sf::Vector2f(400, 20));
        shape.setPosition(0, 0);
        window.draw(shape);

        shape.setPosition(20, 420);
        window.draw(shape);
}

While the spawners are rendering, the console prints a bunch of opengl errors. After further investigation with the debugger (visual studio). It appears that my spawner->render() function is never being called, which is odd. I'm not entirely sure what is happening here as this code works fine with spawners that are instantiated in the executable and not loaded from the dll. I'm new to loading a dll at runtime, is there some sort of problem I'm missing here?

It is quite hard to see what's happening, but before I would ask for info about what does what, the fact that spawner->render is not called when it should be is enough to start debugging the problem urself. Put a break pointer on the for loop and look into the memory at m_spawners

NipIsTrue

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: OpenGL error INVALID_OPERATION occurring for no reason?
« Reply #2 on: February 12, 2020, 04:53:41 am »
I am working on a simple 2d game in sfml, and I recently ran into a problem when trying to write a mod system for the game. Basically, the mod system works by loading a dll into memory, and calling functions from it that return a subclass of one defined in my game. The loading works fine and the object is instantiated correctly, but it appears to have broken part of my rendering code that worked before, namely this part:


void Environment::render(sf::RenderWindow& window) {
        for (Spawner* spawner : m_spawners) {
                spawner->render(window);
        }

        for (Enemy* enemy : m_enemies) {
                enemy->render(window);
        }

        m_player.render(window);

        sf::RectangleShape shape(sf::Vector2f(20, 400));
        shape.setFillColor(sf::Color::Black);
        window.draw(shape);

        shape.setPosition(420, 0);
        window.draw(shape);

        shape.setSize(sf::Vector2f(400, 20));
        shape.setPosition(0, 0);
        window.draw(shape);

        shape.setPosition(20, 420);
        window.draw(shape);
}

While the spawners are rendering, the console prints a bunch of opengl errors. After further investigation with the debugger (visual studio). It appears that my spawner->render() function is never being called, which is odd. I'm not entirely sure what is happening here as this code works fine with spawners that are instantiated in the executable and not loaded from the dll. I'm new to loading a dll at runtime, is there some sort of problem I'm missing here?

It is quite hard to see what's happening, but before I would ask for info about what does what, the fact that spawner->render is not called when it should be is enough to start debugging the problem urself. Put a break pointer on the for loop and look into the memory at m_spawners

I did do this when testing with the debugger, the memory at these locations was normal, a vector of valid spawner objects that were not null pointers.

In the end, I was not able to figure this out, and decided to take a different approach to modding and embed the lua interpreter in my game instead, and that has been working great. So I guess consider this solved.