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

Author Topic: MAC - EXC_BAD_ACCESS signal in sf::RenderTarget::Clear  (Read 6411 times)

0 Members and 1 Guest are viewing this topic.

didito

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • http://didito.gpigs.com
MAC - EXC_BAD_ACCESS signal in sf::RenderTarget::Clear
« on: August 14, 2009, 09:21:17 pm »
hello,

i would like to use SFML in a project on my mac, because i liked the provided functionality and the clean C++ style.
i downloaded the full SDK v.15 but i can't get my simple example working (based on the c++ tool / cmdline SFML xcode template).

my system:
mac book pro, macosx v10.5.8
architecture: intel
gfx: nvidia 8600m gt
IDE: xcode 3.0

here is the code of my simple example:
Code: [Select]

#include <cstdio>
#include <string>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics.hpp>
//#include <SFML/System.hpp>
#include "config_sensorvis.hpp"


int main()
{
    //allocate resources
    std::string fontFilename("arial.ttf");
    sf::Font font;
    if (!font.LoadFromFile(fontFilename, 50))
    {
        printf("[ERROR] could NOT load font %s\n", fontFilename.c_str());
        //return EXIT_FAILURE;
    }
    else
    {
        font = sf::Font::GetDefaultFont();
    }

   
    //setup
    sf::WindowSettings settings;
    settings.DepthBits         = 24;
    settings.StencilBits       = 8;
    settings.AntialiasingLevel = 0;

    sf::RenderWindow app(sf::VideoMode(640, 480, 32), APP_TITLE /*, sf::Style::Close, settings*/);
   
    //app.UseVerticalSync(false);
    //app.SetFramerateLimit(60); // Limit to 60 frames per second
    //app.SetFramerateLimit(0);  // No limit
   
    app.PreserveOpenGLStates(true);

    app.SetPosition(0, 0);

    /*sf::View view;
    app.SetView(view);*/
   
    //timer
    sf::Clock clock;
   
    sf::Event event;

    const sf::Input& input = app.GetInput();

    //main loop
    while (app.IsOpened())
    {
        //timing update - get elapsed time since last loop
        float dt = clock.GetElapsedTime();
        clock.Reset();
        float framerate = 1.f / clock.GetElapsedTime();

        unsigned int mouseX = input.GetMouseX();
        unsigned int mouseY = input.GetMouseY();


        while (app.GetEvent(event))
        {
            //process all events from message queue ...

            if (event.Type == sf::Event::Closed)
            {
                app.Close();
            }
            else
            if (event.Type == sf::Event::KeyPressed)
            {
                if (event.Key.Code == sf::Key::Escape)
                {
                    app.Close();
                }
                else
                if (event.Key.Code == sf::Key::F1)
                {
                    sf::Image screen = app.Capture();
                    screen.SaveToFile("screenshot.jpg");
                }
            }
            else
            if (event.Type == sf::Event::Resized)
            {
               // glViewport(0, 0, event.Size.Width, event.Size.Height);
            }
            else
            {
                printf("[WARNING] uncatched event\n");
            }
        }


        //render
        app.SetActive();
        app.Clear(sf::Color(255, 0, 0));
               
        glClearColor(0.f, 0.f, 0.f, 0.f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        glTranslatef(0.f, 0.f, -200.f);
        glColor3f(255.f, 0.f, 0.f);
        glBegin(GL_QUADS);

            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f(-50.f,  50.f, -50.f);
            glVertex3f( 50.f,  50.f, -50.f);
            glVertex3f( 50.f, -50.f, -50.f);

            glVertex3f(-50.f, -50.f, 50.f);
            glVertex3f(-50.f,  50.f, 50.f);
            glVertex3f( 50.f,  50.f, 50.f);
            glVertex3f( 50.f, -50.f, 50.f);

            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f(-50.f,  50.f, -50.f);
            glVertex3f(-50.f,  50.f,  50.f);
            glVertex3f(-50.f, -50.f,  50.f);

            glVertex3f(50.f, -50.f, -50.f);
            glVertex3f(50.f,  50.f, -50.f);
            glVertex3f(50.f,  50.f,  50.f);
            glVertex3f(50.f, -50.f,  50.f);

            glVertex3f(-50.f, -50.f,  50.f);
            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f( 50.f, -50.f, -50.f);
            glVertex3f( 50.f, -50.f,  50.f);

            glVertex3f(-50.f, 50.f,  50.f);
            glVertex3f(-50.f, 50.f, -50.f);
            glVertex3f( 50.f, 50.f, -50.f);
            glVertex3f( 50.f, 50.f,  50.f);

        glEnd();


        //render hud
        sf::String fps;
        fps.SetText("fps: ");
        fps.SetFont(font);
        fps.SetSize(50);

        fps.SetColor(sf::Color(128, 128, 0));
        //fps.SetRotation(90.f);
        //fps.SetScale(2.f, 2.f);
        fps.Move(100.f, 200.f);

        app.Draw(fps);

        app.Display();
    }
   
    app.Close();


    return EXIT_SUCCESS;
}




i launch the example and after a short while gdb receives a EXC_BAD_ACCESS signal from "sf::RenderTarget::Clear" and then i only see assembler code (why? i don't strip the symbols as far as i can see and the source comes with the full SDK) in the debugger. so i don't know what is wrong with it. when i comment the SetActive() Clear() or Draw(text) functions of the RenderWindow object it works, but of course i don't see anything then ... maybe there is a problem with the window settings (resolution, depth, ...)? does anybody have any idea?

thanks in advance,
didi

didito

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • http://didito.gpigs.com
MAC - EXC_BAD_ACCESS signal in sf::RenderTarget::Clear
« Reply #1 on: August 15, 2009, 07:31:26 pm »
btw, the debugger (which is automatically triggered by the crash) says:

Quote

[Session started at 2009-08-15 14:01:28 +0200.]
Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-768) (Tue Oct  2 04:07:49 UTC 2007)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".warning: Unable to read symbols for "@executable_path/../Frameworks/SFML.framework/Versions/A/SFML" (file not found).
warning: Unable to read symbols for "@executable_path/../Frameworks/sfml-system.framework/Versions/A/sfml-system" (file not found).
warning: Unable to read symbols for "@executable_path/../Frameworks/sfml-graphics.framework/Versions/A/sfml-graphics" (file not found).
warning: Unable to read symbols for "@executable_path/../Frameworks/sfml-window.framework/Versions/A/sfml-window" (file not found).
Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/didito/MyTestApp', process 704.
warning: Could not find object file "/Users/lucas/release-sfml-1.5/SFML-1.5-sdk-macosx/build/xcode/build/SFML.build/Release/sfml-graphics.build/Objects-normal/i386/Color.o" - no debug information available for "/Users/lucas/release-sfml-1.5/SFML-1.5-sdk-macosx/build/xcode/../../src/SFML/Graphics/Color.cpp".

... and a lot of the same warnings ...



maybe this gives someone a clue...

didito

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • http://didito.gpigs.com
MAC - EXC_BAD_ACCESS signal in sf::RenderTarget::Clear
« Reply #2 on: August 15, 2009, 08:22:52 pm »
ok, now i built my project with codeblocks and it works so far(no crashes, no spindump). if anyone is interested in the project file/setup, i can help and post it.
the problem with the missing debug information still exists when i launch it via gdb which would help with debugging. but at least it is not a show stopper.
i wonder what causes the problem with xcode? maybe some wrong setting with the SFML template?

---

anyway, now i have another problem. i cannot load any font. i tried different ttf fonts (i think from windows systems) which work perfectly for example in Ogre3D on mac, windows and linux. but not with this SFML based application. i always get a message like this:
Failed to load font "/mypath.../bin/data/font/arial.ttf" (cannot render this glyph format)
is there anything odd going on with the freetype version? and the default font does not seem to exist or work. how can i check that? where do i get compatible fonts that work with SFML on mac?

with one font i even got a crash, here is the gdb output:
Quote

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x1bffffff
0x00248f5c in FT_Done_Glyph ()
(gdb) backtrace
#0  0x00248f5c in FT_Done_Glyph ()
#1  0x001d19c0 in sf::priv::FontLoader::CreateBitmapFont ()
#2  0x001d2d18 in sf::priv::FontLoader::LoadFontFromFile ()
#3  0x001d0af9 in sf::Font::LoadFromFile ()

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
MAC - EXC_BAD_ACCESS signal in sf::RenderTarget::Clear
« Reply #3 on: August 16, 2009, 03:09:35 pm »
You should try to compile the frameworks from the latest sources in the Subversion repository. There has been one important fix (and your error saying "cannot render this glyph format" makes me think of it).
Want to play movies in your SFML application? Check out sfeMovie!

didito

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • http://didito.gpigs.com
MAC - EXC_BAD_ACCESS signal in sf::RenderTarget::Clear
« Reply #4 on: August 17, 2009, 06:19:24 pm »
i guess you mean NOT the v2.0 branch, but v1.5 or v1.6 - or what is it called - revision 1204?

i did update my working copy and this time i accomplished to compile the framework with xcode. there were some errors with the OpenAL framework (the compiler refused to find it despite adding the custom, the original apple and setting the frameworks searchpath) so i did not build SFML-audio yet.
i also had to remove the GCC 4.2 dependency since i don't have it and i don't know where to get it ... i hope it does not matter.

then i had some problems with dyld not finding the frameworks or if it found them then there was an error in stat(). finally i managed to do it by putting the frameworks into @executeablepath/../Frameworks and now it works.

the font problem is gone as well. thanks for your help! maybe you can ellaborate on what caused the error?!?
and any info on what is the difference between v1.5 (released) and the current version in the repository?

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
MAC - EXC_BAD_ACCESS signal in sf::RenderTarget::Clear
« Reply #5 on: August 18, 2009, 12:22:22 am »
Quote from: "didito"
i guess you mean NOT the v2.0 branch, but v1.5 or v1.6 - or what is it called - revision 1204?

Yep I meant the trunk (which represents SFML 1.6).

Quote from: "didito"
i did update my working copy and this time i accomplished to compile the framework with xcode. there were some errors with the OpenAL framework (the compiler refused to find it despite adding the custom, the original apple and setting the frameworks searchpath) so i did not build SFML-audio yet.

Your issue with the OpenAL framework is.. weird, because it's included in the trunk, and everything should have been set up correctly to let Xcode find the framework. I'll have a look at it.

Quote from: "didito"
i also had to remove the GCC 4.2 dependency since i don't have it and i don't know where to get it ... i hope it does not matter.

About GCC 4.2... this is weird too. Xcode is supposed to use the default system compiler. I'll have a look at it too.

Quote from: "didito"
then i had some problems with dyld not finding the frameworks or if it found them then there was an error in stat(). finally i managed to do it by putting the frameworks into @executeablepath/../Frameworks and now it works.

The warnings about the frameworks not being present at @executable_path/../Frameworks is normal, but I don't understand what you "stat()" error is.

Quote from: "didito"
the font problem is gone as well. thanks for your help! maybe you can ellaborate on what caused the error?!?
and any info on what is the difference between v1.5 (released) and the current version in the repository?

With SFML 1.5, there is no OpenGL context activated until you make a window, but fonts need this context. Thus loading a font before making a window caused troubles.
Want to play movies in your SFML application? Check out sfeMovie!

didito

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • http://didito.gpigs.com
MAC - EXC_BAD_ACCESS signal in sf::RenderTarget::Clear
« Reply #6 on: October 12, 2009, 01:46:54 am »
i managed to build and use everything (still except the audio part) a while ago after updating my working copy (as suggested). i did not figure out my issue with OpenAL but since i do not use it yet i've had no time or motivation to investigate further on that topic.

i do not know what the dyld and stat() error was, but it went away after
i switched to CodeBlocks. the strange thing is i can compile but i can't launch any application built with SFML on xcode. maybe i have some wrong settings - i am not a xcode professional.

disabling the gcc 4.2 requirement was no biggie and it seems to work with v4.01. i've read that the new xcode that comes with the iphone SDK has gcc 4.2. i guess i will update to the newer GCC at some point. i hope with snow leopard, an updated xcode and hopefully a newer GCC (>4.2).

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
MAC - EXC_BAD_ACCESS signal in sf::RenderTarget::Clear
« Reply #7 on: October 12, 2009, 06:16:22 pm »
Quote from: "didito"
the strange thing is i can compile but i can't launch any application built with SFML on xcode. maybe i have some wrong settings - i am not a xcode professional.

Is it the same issue than here ?

Quote from: "didito"
i hope with snow leopard, an updated xcode and hopefully a newer GCC (>4.2).

Well for now Xcode 3.2 provides GCC 4.2.1. Let's see what's up :) .
Want to play movies in your SFML application? Check out sfeMovie!