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

Author Topic: Application crashes  (Read 1897 times)

0 Members and 1 Guest are viewing this topic.

Cdore

  • Newbie
  • *
  • Posts: 1
    • View Profile
Application crashes
« on: November 13, 2013, 05:00:35 am »
Hi there. I'm using SFML to make a simple chat program. I built it and compiled it correctly, but when I ran the program exe, one with the server option and the other with the client option at the same time (basically two instances of the application running), they connect, but after it says this message on the console ("Enter exit to quit or message to send"), it has a stopped working crash. The debug error refers to:

Quote
(*_Pnext)->_Myproxy = 0;

Which lies in the xutility file at line 202.

The code the error pops up at when I was debugging it was:

Quote
packetSend << msgSend;

This is the full code for the program. The relevant breakpoint is in the DoStuff function.

Quote
#include <iostream>
#include <SFML/Network.hpp>

const unsigned short PORT = 5000;
sf::IpAddress IPADDRESS("127.0.0.1");
//const std::string IPADDRESS(a8);//change to suit your needs

std::string msgSend;

sf::TcpSocket socket;
sf::Mutex globalMutex;
bool quit = false;

void DoStuff(void)
{
   static std::string oldMsg;
   while(!quit)
   {
      sf::Packet packetSend;
      globalMutex.lock();
      packetSend << msgSend;
      globalMutex.unlock();
      
      socket.send(packetSend);
      
      std::string msg;
      sf::Packet packetReceive;
      
      socket.receive(packetReceive);      
      if(packetReceive >> msg)
      {
         if(oldMsg != msg)
            if(!msg.empty())
            {
               std::cout << msg << std::endl;
               oldMsg = msg;
            }
      }
   }
}
void Server(void)
{
   sf::TcpListener listener;
   listener.listen(PORT);
   listener.accept(socket);
   std::cout << "New client connected: " << socket.getRemoteAddress() << std::endl;
}
bool Client(void)
{
   if(socket.connect(IPADDRESS, PORT) == sf::Socket::Done)
   {
      std::cout << "Connected\n";
      return true;
   }
   return false;
}
void GetInput(void)
{
   std::string s;
   std::cout << "\nEnter exit to quit or message to send: ";
   std::cin >> s;
   if(s == "exit")
      quit = true;
   globalMutex.lock();
   msgSend = s;
   globalMutex.unlock();
}
int main(int argc, char* argv[])
{
   sf::Thread* thread = 0;
      
   char who;
    std::cout << "Do you want to be a server (s) or a client (c) ? ";
    std::cin  >> who;

    if(who == 's')
      Server();
   else
      Client();

   thread = new sf::Thread(&DoStuff);
   thread->launch();
      
   while(!quit)
   {
      GetInput();
   }
   if(thread)
   {
      thread->wait();
      delete thread;
   }
   return 0;
}

I appreciate the help.
« Last Edit: November 13, 2013, 05:02:06 am by Cdore »

 

anything