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

Author Topic: Problem with crashing a application but application works (strange)  (Read 2335 times)

0 Members and 1 Guest are viewing this topic.

domin568

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Hello I have such strange problem , I made application with network connection, by  TCP sockets, I created another thread to networking. When I begin 2 applications (server,client), in Task Manager I can see  "Application don't responding", but through windows aero I can see my crashed applications, and client and server works ! I press W and my shape move up, and even this is sending to opposite application and there I can see that shape was moved on another application. This is strange problem :/ Sorry for my English. Code (some names is from Polish language because it's better for me in recognise a application and I think this is not problem for you because names are not very important)
Server :
#include "stdafx.h"
#include <SFML/Graphics.hpp>
#include <iostream>
#include <SFML/Network.hpp>
#include "Klocek.h"
sf::Packet pakiet_wyslany;
sf::Packet pakiet_odebrany;

        sf::Vector2f start_position_odebrane ;
        sf::Vector2f klocek_size_odebrane ;
        sf::Color kolor_klocka_odebrane ;
        float thickness_klocek_odebrane  ;
        sf::Color kolor_thickness_odebrane ;

        sf::Vector2f pozycja_klocka_net;
        sf::TcpSocket socket ;
using namespace std;
void poruszajKlockiem (sf::Keyboard::Key klawisz [],klocek & klocek)
{
        if (sf::Keyboard::isKeyPressed (klawisz[0])== true )
        {
        klocek.setPosition (sf::Vector2f (klocek.getPosition().x , klocek.getPosition().y -4) ) ;
        }

        if (sf::Keyboard::isKeyPressed (klawisz[1])== true )
        {
        klocek.setPosition (sf::Vector2f (klocek.getPosition().x , klocek.getPosition().y +4) ) ;
        }

        if (sf::Keyboard::isKeyPressed (klawisz[2])== true )
        {
        klocek.setPosition (sf::Vector2f (klocek.getPosition().x -4 , klocek.getPosition().y ) ) ;
        }

        if (sf::Keyboard::isKeyPressed (klawisz[3])== true )
        {
        klocek.setPosition (sf::Vector2f (klocek.getPosition().x +4 , klocek.getPosition().y ) ) ;
        }
}
void komunikacja_sieciowa (klocek & klocek)
{
        while (true)
        {
                pakiet_wyslany.clear () ;
                pakiet_odebrany.clear () ;

                pakiet_wyslany << klocek.getPosition().x << klocek.getPosition().y ;
                if (socket.send (pakiet_wyslany) != sf::Socket::Done )
                {
                        cout << "Nie udalo sie wyslac " << endl ;
                }
                if (socket.receive (pakiet_odebrany) == sf::Socket::Done )
                {
                        pakiet_odebrany >> pozycja_klocka_net.x >> pozycja_klocka_net.y ;
                }
        }

       
}
void aktualizuj_pozycje_kloceknet (klocek & klocek_net)
{
        klocek_net.setPosition (pozycja_klocka_net);
}

int main(int argc, char* argv[])
{
        cout << "SERVER" << endl ;
        sf::TcpListener listener;
        listener.listen (5000);

        sf::RenderWindow okno(sf::VideoMode (800,600,32),"Klocki");
        okno.setFramerateLimit (60);
        sf::Vector2f start_position (300,300);
        sf::Vector2f klocek_size (50,50);
        sf::Color kolor_klocka (255,0,0);
        float thickness_klocek = 10 ;
        sf::Color kolor_thickness (0,255,255);

        pakiet_wyslany << start_position.x << start_position.y << klocek_size.x << klocek_size.y << kolor_klocka.r << kolor_klocka.g << kolor_klocka.b
        << thickness_klocek << kolor_thickness.r << kolor_thickness.g << kolor_thickness.b ;
       
        if (listener.accept (socket)==true)
        {
                cout << "Polaczono" << endl ;
        }
        if ( socket.send (pakiet_wyslany) != sf::Socket::Done )
        {
                cout  << "Unable to send data " << endl ;
        }
        if (socket.receive(pakiet_odebrany) == sf::Socket::Done )
        {
        pakiet_odebrany >> start_position_odebrane.x >> start_position_odebrane.y >> klocek_size_odebrane.x >> klocek_size_odebrane.y >> kolor_klocka_odebrane.r >> kolor_klocka_odebrane.g >> kolor_klocka_odebrane.b
        >> thickness_klocek_odebrane >> kolor_thickness_odebrane.r >> kolor_thickness_odebrane.g >> kolor_thickness_odebrane.b ;
        }

       
        klocek klocek_net (start_position_odebrane,klocek_size_odebrane.x,klocek_size_odebrane.y,kolor_klocka_odebrane,thickness_klocek_odebrane,kolor_thickness_odebrane );
        klocek klocek (start_position,klocek_size.x,klocek_size.y,kolor_klocka,thickness_klocek,kolor_thickness);
       
       
        sf::Thread watek_net (&komunikacja_sieciowa,klocek) ;
    watek_net.launch ();
       

        sf::Keyboard::Key klawisze [] = {sf::Keyboard::W,sf::Keyboard::S,sf::Keyboard::A,sf::Keyboard::D};

        while (okno.isOpen ())
        {
        aktualizuj_pozycje_kloceknet (klocek_net);
        poruszajKlockiem (klawisze,klocek);
        okno.display();
        okno.clear();
        klocek_net.drawKlocek(okno);
    klocek.drawKlocek(okno);
        }
        return 0;
}
 
client
#include "stdafx.h"
#include <SFML/Graphics.hpp>
#include <iostream>
#include <SFML/Network.hpp>
#include "Klocek.h"
sf::Packet pakiet_wyslany;
sf::Packet pakiet_odebrany;

        sf::Vector2f start_position_odebrane ;
        sf::Vector2f klocek_size_odebrane ;
        sf::Color kolor_klocka_odebrane ;
        float thickness_klocek_odebrane  ;
        sf::Color kolor_thickness_odebrane ;

        sf::Vector2f pozycja_klocka_net;
        sf::TcpSocket socket ;

using namespace std;
void poruszajKlockiem (sf::Keyboard::Key klawisz [],klocek & klocek)
{
        if (sf::Keyboard::isKeyPressed (klawisz[0])== true )
        {
        klocek.setPosition (sf::Vector2f (klocek.getPosition().x , klocek.getPosition().y -4) ) ;
        }

        if (sf::Keyboard::isKeyPressed (klawisz[1])== true )
        {
        klocek.setPosition (sf::Vector2f (klocek.getPosition().x , klocek.getPosition().y +4) ) ;
        }

        if (sf::Keyboard::isKeyPressed (klawisz[2])== true )
        {
        klocek.setPosition (sf::Vector2f (klocek.getPosition().x -4 , klocek.getPosition().y ) ) ;
        }

        if (sf::Keyboard::isKeyPressed (klawisz[3])== true )
        {
        klocek.setPosition (sf::Vector2f (klocek.getPosition().x +4 , klocek.getPosition().y ) ) ;
        }
}
void komunikacja_sieciowa (klocek & klocek)
{
       

        while (true)
        {
                pakiet_wyslany.clear () ;
                pakiet_odebrany.clear () ;

                pakiet_wyslany << klocek.getPosition().x << klocek.getPosition().y ;
                if (socket.send (pakiet_wyslany) != sf::Socket::Done )
                {
                        cout << "Nie udalo sie wyslac " << endl ;
                }
                if (socket.receive (pakiet_odebrany) == sf::Socket::Done )
                {
                        pakiet_odebrany >> pozycja_klocka_net.x >> pozycja_klocka_net.y ;
                }
        }

       

   
}
void aktualizuj_pozycje_kloceknet (klocek & klocek_net)
{
        klocek_net.setPosition (pozycja_klocka_net);
}

int main(int argc, char* argv[])
{
        sf::Vector2f start_position (300,300);
        sf::Vector2f klocek_size (50,50);
        sf::Color kolor_klocka (255,0,0);
        float thickness_klocek = 10 ;
        sf::Color kolor_thickness (0,0,255);

        if (socket.connect ("127.0.1",5000)==sf::Socket::Done)
        {
                cout << "Polaczono " << endl ;
        }
       

        if (socket.receive(pakiet_odebrany) == sf::Socket::Done )
        {
        pakiet_odebrany >> start_position_odebrane.x >> start_position_odebrane.y >> klocek_size_odebrane.x >> klocek_size_odebrane.y >> kolor_klocka_odebrane.r >> kolor_klocka_odebrane.g >> kolor_klocka_odebrane.b
        >> thickness_klocek_odebrane >> kolor_thickness_odebrane.r >> kolor_thickness_odebrane.g >> kolor_thickness_odebrane.b ;
       
        }
       
        klocek klocek_net (start_position_odebrane,klocek_size_odebrane.x,klocek_size_odebrane.y,kolor_klocka_odebrane,thickness_klocek_odebrane,kolor_thickness_odebrane );
        pakiet_wyslany << start_position.x << start_position.y << klocek_size.x << klocek_size.y << kolor_klocka.r << kolor_klocka.g << kolor_klocka.b
        << thickness_klocek << kolor_thickness.r << kolor_thickness.g << kolor_thickness.b ;
        if ( socket.send (pakiet_wyslany) != sf::Socket::Done )
        {
                cout  << "Unable to send data " << endl ;
        }

       
        klocek klocek (start_position,klocek_size.x,klocek_size.y,kolor_klocka,thickness_klocek,kolor_thickness);
        sf::Thread watek_net (&komunikacja_sieciowa,klocek) ;
    watek_net.launch ();
        sf::RenderWindow okno(sf::VideoMode (800,600,32),"Zderzejace sie klocki");
        okno.setFramerateLimit (60);
        sf::Keyboard::Key klawisze [] = {sf::Keyboard::W,sf::Keyboard::S,sf::Keyboard::A,sf::Keyboard::D};

        while (okno.isOpen ())
        {
        aktualizuj_pozycje_kloceknet (klocek_net);
        poruszajKlockiem (klawisze,klocek);
        okno.display();
        okno.clear();
        klocek_net.drawKlocek(okno);
    klocek.drawKlocek(okno);
        }
        return 0;
}
 

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Problem with crashing a application but application works (strange)
« Reply #1 on: November 11, 2013, 01:17:22 am »
It looks like you just aren't handling the events in your RenderWindows. Even if you don't actually doing anything with the events, polling events should get rid of the "Application is not responding" messages.
DSFML - SFML for the D Programming Language.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11029
    • View Profile
    • development blog
    • Email
Re: Problem with crashing a application but application works (strange)
« Reply #2 on: November 11, 2013, 09:21:14 am »
As Jebbs pointed out, if you're not polling the event queue Windows will think your application doesn't do anything, thus showing "Application not responding" even though it's running fine.

And as another side note, I highly recommend to use English for all of your code, not only will it match all the libraries name language (English.English instead of <your language>.English), but it will also make it much more easier to let anyone take a look at your code and directly understand it. It's not a must, it's just a suggestion. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

domin568

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Problem with crashing a application but application works (strange)
« Reply #3 on: November 11, 2013, 06:45:11 pm »
Thanks Jebbs , now my application works :), really stupid error. I will write my next codes in English