1
General discussions / SFML 2 for OS X comes true!
« on: October 18, 2011, 11:14:27 pm »
That seemed to work better! Stupid GUI indeed.
Thanks for the help!
Thanks for the help!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Command /Developer/usr/bin/clang++ failed with exit code 1
ld: library not found for -lsfml-system-d
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
const bool DEBUG = true;
const unsigned int PORTTCP = 4567;
const unsigned int PORTUDP = 4568;
struct Client
{
sf::SocketTCP socket;
sf::IPAddress address;
};
bool running = true;
string errMess;
sf::Mutex globalMutex;
vector<Client> connClients;
vector<sf::SocketTCP> connSendClients;
void handleConn(void *UserData)
{
if(DEBUG)
{
globalMutex.Lock();
cout << "\tDEBUG: Entering thread: \"handleConn()\"." << endl;
globalMutex.Unlock();
}
sf::SocketTCP listener;
if(!listener.Listen(PORTTCP))
{
running = false;
errMess = "Failed listening to port!";
return;
}
cout << "Listening to port " << PORTTCP << ". Waiting for TCP connections..." << endl;
sf::SelectorTCP selector;
selector.Add(listener);
while(running)
{
unsigned int NbSockets = selector.Wait(5.f);
for(unsigned int i = 0; i < NbSockets; i++)
{
sf::SocketTCP socket = selector.GetSocketReady(i);
//New connection.
if(socket == listener)
{
sf::IPAddress address;
sf::SocketTCP client;
listener.Accept(client, &address);
globalMutex.Lock();
cout << "Client connected ! (" << address << ")" << endl;
globalMutex.Unlock();
selector.Add(client);
Client tmpClient;
tmpClient.socket = client;
tmpClient.address = address;
connClients.push_back(tmpClient);
sf::SocketTCP tmpSocket;
if(!tmpSocket.Connect(PORTTCP, address))
{
globalMutex.Lock();
cout << "Unable to connect to client! (" << connClients[i].address.ToString() << ")" << endl;
globalMutex.Unlock();
}
connSendClients.push_back(tmpSocket);
}
else
{
sf::Packet packet;
if(socket.Receive(packet) == sf::Socket::Done)
{
sf::Int8 isMess;
string clientName;
string mess;
packet >> isMess >> clientName >> mess;
if(isMess == 0)
{
if(mess == "quit")
{
sf::IPAddress droppedIP;
int q;
for(unsigned int i = 0; i < connClients.size(); i++)
{
if(socket == connClients[i].socket)
{
droppedIP = connClients[i].address;
q = i;
}
}
globalMutex.Lock();
cout << "Client dropped! (" << droppedIP.ToString() << ")" << endl;
globalMutex.Unlock();
selector.Remove(socket);
globalMutex.Lock();
connClients.erase(connClients.begin()+q);
globalMutex.Unlock();
}
}
if(isMess == 1)
{
if(DEBUG)
{
globalMutex.Lock();
cout << "Message recieved!" << endl;
globalMutex.Unlock();
}
globalMutex.Lock();
cout << clientName << ": " << mess << endl;
globalMutex.Unlock();
if(DEBUG)
{
globalMutex.Lock();
cout << "\tDEBUG: connSendClients.size(): " << connSendClients.size() << endl;
globalMutex.Unlock();
}
for(unsigned int i = 0; i < connSendClients.size(); i++)
{
if(connSendClients[i].Send(packet) != sf::Socket::Done)
{
globalMutex.Lock();
cout << "Unable to send packet to client! (" << connClients[i].address.ToString() << ")" << endl;
globalMutex.Unlock();
}
}
}
}
}
}
globalMutex.Lock();
cout << "...waiting!" << endl;
globalMutex.Unlock();
}
for(unsigned int i = 0; i < connSendClients.size(); i++)
{
connSendClients[i].Close();
}
}
int main()
{
sf::RenderWindow app(sf::VideoMode(800, 600, 32), "Julles chatt server.");
sf::Thread connThread(&handleConn);
connThread.Launch();
while(app.IsOpened())
{
sf::Event Event;
while (app.GetEvent(Event))
{
// Close window : exit
if(Event.Type == sf::Event::Closed)
app.Close();
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
app.Close();
}
app.Display();
}
running = false;
connThread.Wait();
return 0;
}
...waiting!
Client connected ! (83.227.232.222)
...waiting!
SFML2(1725,0xb0147000) malloc: *** error for object 0xa02056d8: Non-aligned pointer being freed
*** set a breakpoint in malloc_error_break to debug
SFML2(1725,0xb0147000) malloc: *** error for object 0xa02056d8: Non-aligned pointer being freed
*** set a breakpoint in malloc_error_break to debug
Message recieved!
blabla: tjo din keffade grek
DEBUG: connSendClients.size(): 1
Unable to send packet to client! (83.227.232.222)
...waiting!
SFML2(1725,0xb0147000) malloc: *** error for object 0xa02056d8: Non-aligned pointer being freed
*** set a breakpoint in malloc_error_break to debug
SFML2(1725,0xb0147000) malloc: *** error for object 0xa02056d8: Non-aligned pointer being freed
*** set a breakpoint in malloc_error_break to debug
Message recieved!
blabla: jkhdfjkdh
DEBUG: connSendClients.size(): 1
Unable to send packet to client! (83.227.232.222)
...waiting!
Program received signal: “SIGPIPE”.
Xcode: Introspection dylib not loaded because thread 3 has function: malloc_printf on stack
(gdb)
void sf::RenderWindow::PreserveOpenGLStates ( bool Preserve )
Tell SFML to preserve external OpenGL states, at the expense of more CPU charge.
Use this function if you don't want SFML to mess up your own OpenGL states (if any). Don't enable state preservation if not needed, as it will allow SFML to do internal optimizations and improve performances. This parameter is false by default