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

Author Topic: SFML 1.3 and OS X  (Read 48268 times)

0 Members and 1 Guest are viewing this topic.

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
SFML 1.3 and OS X
« Reply #90 on: December 18, 2008, 04:13:53 pm »
I gave the French version to Laurent one week ago, I don't know if he translated it, and I don't know whether he will allow you to see it before the 1.4 release :D .
Want to play movies in your SFML application? Check out sfeMovie!

coral

  • Newbie
  • *
  • Posts: 37
    • View Profile
SFML 1.3 and OS X
« Reply #91 on: December 26, 2008, 07:08:44 pm »
Hey!

A freind of me is trying out some of the networking functions of SFML, this example works perfectly on his Windows computers and he thought i might give it a go and compile it:

Code: [Select]

#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;
}


It compiles in OSX, but at runtime i get this:

Code: [Select]

...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)


As said, this does not occur on his Windows machine. Is this code related or SFML related to the Mac?

I am compiling with the lastest version from the SVN.

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
SFML 1.3 and OS X
« Reply #92 on: December 27, 2008, 08:56:55 pm »
When using telnet localhost 4567 after launching your application, I get this :

Quote
   DEBUG: Entering thread: "handleConn()".
Listening to port 4567. Waiting for TCP connections...
...waiting!
...waiting!
Client connected ! (127.0.0.1)
Unable to connect to client! (127.0.0.1)
...waiting!
Client connected ! (127.0.0.1)
Unable to connect to client! (127.0.0.1)
...waiting!
[repeated about one hundred times]
Client connected ! (255.255.255.255)
...waiting!
[last two lines repeated infinitely]


Try to keep only the network feature in order to know if the issue comes from my port.
Want to play movies in your SFML application? Check out sfeMovie!

lzr

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • http://lzr.cc
SFML 1.3 and OS X
« Reply #93 on: December 28, 2008, 02:10:04 am »
I wanted to try out the SVN, but I had some trouble getting the library to compile. All the packages were fine except for sfml-audio and sfml-graphics.

Here are the errors I get for sfml-audio:
Code: [Select]

/sfml/build/xcode/../../src/SFML/Audio/AudioDevice.cpp:159: error: invalid conversion from 'const char*' to 'ALubyte*'
/sfml/build/xcode/../../src/SFML/Audio/AudioDevice.cpp:159: error:   initializing argument 1 of 'ALenum alGetEnumValue(ALubyte*)'
/sfml/build/xcode/../../src/SFML/Audio/AudioDevice.cpp:160: error: invalid conversion from 'const char*' to 'ALubyte*'
/sfml/build/xcode/../../src/SFML/Audio/AudioDevice.cpp:160: error:   initializing argument 1 of 'ALenum alGetEnumValue(ALubyte*)'
/sfml/build/xcode/../../src/SFML/Audio/AudioDevice.cpp:161: error: invalid conversion from 'const char*' to 'ALubyte*'
/sfml/build/xcode/../../src/SFML/Audio/AudioDevice.cpp:161: error:   initializing argument 1 of 'ALenum alGetEnumValue(ALubyte*)'
/sfml/build/xcode/../../src/SFML/Audio/AudioDevice.cpp:162: error: invalid conversion from 'const char*' to 'ALubyte*'
/sfml/build/xcode/../../src/SFML/Audio/AudioDevice.cpp:162: error:   initializing argument 1 of 'ALenum alGetEnumValue(ALubyte*)'


And here are the sfml-graphics errors:
Code: [Select]

ld: table of contents for archive: /Users/leeranraphaely/sfml/build/xcode/../../extlibs/libs-xcode/libfreetype.a is out of date; rerun ranlib(1) (can't load from it)
/usr/bin/libtool: internal link edit command failed


I'm using a PowerPC G5 mac with OS X version 10.4.11 and Xcode version 2.2, if that helps.

zhinchliffe

  • Newbie
  • *
  • Posts: 18
    • View Profile
SFML 1.3 and OS X
« Reply #94 on: December 28, 2008, 02:39:36 am »
Help! Can anyone please give me a straightforward way to get the current SVN version of SFML working in Xcode? I'm really, really confused. Much thanks in advance.

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
SFML 1.3 and OS X
« Reply #95 on: December 28, 2008, 03:00:26 pm »
Quote from: "lzr"
I wanted to try out the SVN, but I had some trouble getting the library to compile. All the packages were fine except for sfml-audio and sfml-graphics.

Here are the errors I get for sfml-audio:
[...]

Looks odd... did you compile the OpenAL framework yourself ? (make sure you're using the one from your system or from the 10.4 SDK)
Check there is no OpenAL framework in /Library/Frameworks (which would be one you built), and have a look at the al.h file in the OpenAL framework and check you have these two lines :
Code: [Select]
#define AL_VERSION_1_0
#define AL_VERSION_1_1

Because I'm wondering whether you'd be using OpenAL 1.0... (SFML demands OpenAL 1.1)

Quote from: "lzr"
And here are the sfml-graphics errors:
[...]

I'm using a PowerPC G5 mac with OS X version 10.4.11 and Xcode version 2.2, if that helps.

I dunno if this could change anything, but the Xcode project is supposed to be used with Xcode 2.4 and later. Try to update.
If this does not work, try what's advised by Xcode : launch Terminal.app (from the Utilities folder) and type this :

Code: [Select]
cd path/to/your/sfml/directory
ranlib extlibs/libs-xcode/libfreetype.a
ranlib extlibs/libs-xcode/libsndfile.a
Want to play movies in your SFML application? Check out sfeMovie!

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
SFML 1.3 and OS X
« Reply #96 on: December 28, 2008, 03:07:33 pm »
Quote from: "zhinchliffe"
Help! Can anyone please give me a straightforward way to get the current SVN version of SFML working in Xcode? I'm really, really confused. Much thanks in advance.

The easiest way for now is...

Download the files from the SVN repository.
Open the project sfml/build/xcode/SFML.xcodeproj with Xcode 2.4 (or any other newer version).
Click the build button in the toolbar.
Copy all the framework from sfml/libs/xcode to /Library/Frameworks (if building worked well).


That is not a comprehensive solution, but the best if you wish to use SFML right now for your personal use.

Otherwise you can wait for the 1.4 release (that should come in the next few days if I'm not mistaken).
Want to play movies in your SFML application? Check out sfeMovie!

zhinchliffe

  • Newbie
  • *
  • Posts: 18
    • View Profile
SFML 1.3 and OS X
« Reply #97 on: December 28, 2008, 08:59:12 pm »
Thanks, Ceylo, that worked great!

lzr

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • http://lzr.cc
SFML 1.3 and OS X
« Reply #98 on: December 30, 2008, 08:31:37 am »
Thanks Ceylo, I finally got it to work. After updating Xcode, I moved the OpenAL framework that was in /Library/Frameworks to a temp folder and SFML compiled. Do I need that OpenAL framework, or can I get rid of it? I'm not that familiar with Mac development.

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
SFML 1.3 and OS X
« Reply #99 on: December 30, 2008, 03:27:32 pm »
Mac OS X 10.4 and newer versions already provide OpenAL, so you don't need your personal framework.
Want to play movies in your SFML application? Check out sfeMovie!

zhinchliffe

  • Newbie
  • *
  • Posts: 18
    • View Profile
SFML 1.3 and OS X
« Reply #100 on: January 02, 2009, 10:33:22 pm »
hey, Ceylo, how do I compile the static libraries on OS X? when I build that Xcode project, all I get is the dynamic libraries. is there something extra i have to do?

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
SFML 1.3 and OS X
« Reply #101 on: January 02, 2009, 11:11:55 pm »
I did not provide any way to build a static version of the libraries.

First because you would have to add all the missing libraries yourself (Cocoa, OpenGL, OpenAL, libsndfile, libfreetype). This is because Apple only provides dynamic libraries (unlike Microsoft), and static libraries cannot link against those (whereas they can contain other static libraries). On the other side, this also means that with the dynamic version, you don't need to worry about any depedency, which makes the things quite simpler.

Second because you can put the SFML frameworks in the application bundle if your purpose is to redistribute your product.


If you really wish to use static libraries, I suppose this would be because of a VERY specific issue and therefore I consider you'd know well Mac OS X development, and you could and would have to build them yourself.
Want to play movies in your SFML application? Check out sfeMovie!

zhinchliffe

  • Newbie
  • *
  • Posts: 18
    • View Profile
SFML 1.3 and OS X
« Reply #102 on: January 03, 2009, 12:17:18 am »
Well, I am having a bugger of a problem, so could you check this topic out?

lzr

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • http://lzr.cc
SFML 1.3 and OS X
« Reply #103 on: January 07, 2009, 08:54:52 am »
Is there any way to decrease the file size? 15.3 MB seems a little large...

EDIT:

Also, is it possible to compile as a universal binary on a PowerPC mac? I tried adding in intel to the frameworks both on the SFML compile and my program compile. The SFML compiled fine but compiling the template with PowerPC and Intel enabled gives me a long and cryptic linking error.

Also, Thanks a lot for the port and the tutorial, which was very helpful and easy to follow.

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
SFML 1.3 and OS X
« Reply #104 on: January 07, 2009, 04:36:56 pm »
Uh.. where have you found a 15.3 MB file ?
Want to play movies in your SFML application? Check out sfeMovie!