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

Author Topic: Return code 234 on multithreading and Radeon  (Read 3830 times)

0 Members and 1 Guest are viewing this topic.

Zeeno

  • Newbie
  • *
  • Posts: 5
    • View Profile
Return code 234 on multithreading and Radeon
« on: November 13, 2013, 06:53:28 pm »
Hi,
I am switching from SDL2 to SFML2 and I've found a possible bug, but I am new to SFML, so I am not sure.
I've tried to google and read many topics so I think this is only a ATI driver problem.

My specification of Lenovo G585 notebook is
AMD APU E1-1200 with Radeon HD 7310
Lubuntu 13.10
Proprietary drivers (due to OpenCL support).

I am using SFML2.1 . Tried both, downloading libraries from http://www.sfml-dev.org/download/sfml/2.1/ and compiling from source with latest commit 4cddde79fe606e22a4327a8ec26ad62fc4a9b7f7 . Same result.

Program compile just fine, but when destroying RenderWindow object, program crash with 234 return code. Tried to allocate and destruct using new and delete (shown in the code) and creating RenderWindow as local variable as shown in tutorials, no change. In this example, stdout writes only "One" and "Two", than it crashes.
Compiled on Intel platform with Kubuntu 13.10 and program quits normally with exit code 0.

Do not know whether this problem is only multithreading-specific, in simple monothread application never crashed. I also tried to activate and deactivate window in threads, same result.

Can be this fixed? If no, is there any workaround like managing OpenGL context manually or inheriting RenderWindow and reimplementing deallocating and freeing resources?

#include <iostream>
#include <SFML/Graphics.hpp>
#include <thread>

using namespace sf;
using namespace std;

RenderWindow * gw;

void draw() {
    gw->clear(Color(0, 0, 0, 128));

    CircleShape c;
    c.setPosition(300, 200);
    c.setRadius(100);
    c.setFillColor(Color::Red);

    gw->draw(c);
    gw->display();
    gw->setActive(false);
}

int main(int argc, char** argv) {    
    gw = new RenderWindow(VideoMode(800, 600), "My window");
   
    gw->setActive(false);
    thread t(&draw);

    t.join();
    cout << "One" << endl;
    gw->close();
    cout << "Two" << endl;
    delete gw; //crashes here
    cout << "Three" << endl;

    return 0;
}
 

Thank you for your help and time.

etixpp

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
    • FoxFire Development Website
    • Email
Re: Return code 234 on multithreading and Radeon
« Reply #1 on: November 13, 2013, 07:05:28 pm »
Why would you create the render window dynamicly? If u want to use a pointer make a pointer, create the render Window on normal way and do stuff like pointer = &Window .

If u dont want to use global variable, give the function the parameter and dont create a global pointer

At least what i would do :D

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Return code 234 on multithreading and Radeon
« Reply #2 on: November 13, 2013, 07:16:15 pm »
You might be able to over come the crash with a better scope handling and it's most likely an issue with OpenGL contexts and order of destruction, but I'm lacking the knowledge how SFML has implemented things.

Generally speaking: Don't use global variables and don't use manual memory management.
You should also avoid "using namespace", because while it makes things easier to type at first, it will make everything more complicated later on, when you're trying to figure out, from where which class/type originates from, plus you avoid name clashes.

This works perfectly fine for me:
#include <iostream>
#include <SFML/Graphics.hpp>
#include <thread>

class Test
{
private:
        sf::RenderWindow& m_window;

public:
        Test(sf::RenderWindow& window) :
                m_window(window)
        {
        }

        void draw()
        {
                m_window.clear(sf::Color(0, 0, 0, 128));

                sf::CircleShape c;
                c.setPosition(300, 200);
                c.setRadius(100);
                c.setFillColor(sf::Color::Red);

                m_window.draw(c);
                m_window.display();
                m_window.setActive(false);
        }
};

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "My window");

        Test TestThreading(window);

        window.setActive(false);

        std::thread t(&Test::draw, &TestThreading);
        t.join();

        std::cout << "One" << std::endl;
        window.close();
        std::cout << "Two" << std::endl;
}
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Zeeno

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Return code 234 on multithreading and Radeon
« Reply #3 on: November 13, 2013, 07:25:23 pm »
Quote
You might be able to over come the crash with a better scope handling and it's most likely an issue with OpenGL contexts and order of destruction, but I'm lacking the knowledge how SFML has implemented things.

Generally speaking: Don't use global variables and don't use manual memory management.
You should also avoid "using namespace", because while it makes things easier to type at first, it will make everything more complicated later on, when you're trying to figure out, from where which class/type originates from, plus you avoid name clashes.
code....

This code also return code 234 for me. As i wrote, I tried many ways of creating RenderWindow. It just prints "One" and "Two" and then (when automatically trying to destroy RenderWindow) crashes.
I am rewriting my Engine from SDL2 to SFML2 and everything works fine, just the quiting of applications always crashes. Normally it wouldn't be a big issue, application is quitting, but I am wondered why.

etixpp

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
    • FoxFire Development Website
    • Email
Re: Return code 234 on multithreading and Radeon
« Reply #4 on: November 13, 2013, 07:48:46 pm »
Quote
You might be able to over come the crash with a better scope handling and it's most likely an issue with OpenGL contexts and order of destruction, but I'm lacking the knowledge how SFML has implemented things.

Generally speaking: Don't use global variables and don't use manual memory management.
You should also avoid "using namespace", because while it makes things easier to type at first, it will make everything more complicated later on, when you're trying to figure out, from where which class/type originates from, plus you avoid name clashes.
code....

This code also return code 234 for me. As i wrote, I tried many ways of creating RenderWindow. It just prints "One" and "Two" and then (when automatically trying to destroy RenderWindow) crashes.
I am rewriting my Engine from SDL2 to SFML2 and everything works fine, just the quiting of applications always crashes. Normally it wouldn't be a big issue, application is quitting, but I am wondered why.

Do you quit with console or game window?

Zeeno

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Return code 234 on multithreading and Radeon
« Reply #5 on: November 13, 2013, 08:05:14 pm »
I just let the main function end. It's basically bunch of loops waiting for the right moment (one of the game objects call level->stop()) and then all loops end. Even the code posted here doesn't work properly.
Starting program using "$ ./program.run" and than printing return value "echo $?" gives me 234. I am developing using NetBeans, and after hitting "Play" button the result is same.
In this thread's code I don't have a chance to close window (it opens and close as main() ends) and I don't force program to quit. It just ends itself with 234 return code.

etixpp

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
    • FoxFire Development Website
    • Email
Re: Return code 234 on multithreading and Radeon
« Reply #6 on: November 13, 2013, 08:09:21 pm »
Use Debugger, on which part of the code it exactly quits?

Zeeno

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Return code 234 on multithreading and Radeon
« Reply #7 on: November 13, 2013, 08:15:04 pm »
After last command in main. I can get by stepping as far as 'return 0;', but then gdb(using through NetBeans) quit and shows nothing. When i tried to debug new/delete version, gdb quits at 'delete gw;' and shows nothing more. Tried valgrind and strace to see whether I can find anything interesting, but valgrind shows more than 50 000 errors and also output of strace is very long.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Return code 234 on multithreading and Radeon
« Reply #8 on: November 13, 2013, 08:36:57 pm »
My guess would be the graphics driver especially on Linux. Have you tried a different driver?

Maybe others should test the code as well to make sure it's really hardware/driver related. Your and my code run here on Windows 8.1 with my AMD card without problems, exit nicely with 0.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Zeeno

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Return code 234 on multithreading and Radeon
« Reply #9 on: November 13, 2013, 09:05:39 pm »
My guess would be the graphics driver especially on Linux. Have you tried a different driver?

Maybe others should test the code as well to make sure it's really hardware/driver related. Your and my code run here on Windows 8.1 with my AMD card without problems, exit nicely with 0.

Code does not work properly on glfxr drivers, but on open-source drivers it does end with 0 and print "Third". It would be nice to know why :)
I was worried that windows would pop message "Was this software running properly? - Yes - Reinstall" or something like that, every single time that program ends. Since it is only Linux-fglxr problem I guess that I can ignore this malfunction.
Thank you for all responses.