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

Author Topic: RenderImage : unexpected segfault...  (Read 7459 times)

0 Members and 1 Guest are viewing this topic.

chocobn

  • Newbie
  • *
  • Posts: 39
    • View Profile
RenderImage : unexpected segfault...
« on: April 08, 2011, 01:24:50 am »
Hello! I get an error while using sf::RenderImage. Here is my minimal code :
Code: [Select]
std::cout<< "debutExport" <<std::endl;
m_app->canvasWindow->canvas->getFlattenedImage();
std::cout<< "finExport" <<std::endl;

Code: [Select]
sf::Image CE_Group::getFlattenedImage()
{
std::cout<< "start" <<std::endl;
sf::RenderImage RI;
RI.Create(800,600);
    RI.Clear(sf::Color(200,200,200));
RI.Display();
    sf::Image img = RI.GetImage();
std::cout<< "end" <<std::endl;
    return img;
}


I really don't understand because this what the programs displays :
Code: [Select]
debut export. total of frames:1000
debutExport
start
end
Segmentation fault

Does anyone have an idea about what i did wrong? The point is that the error is at the end of the method... I really don't understand why it occurs after the "return"...
Thanks in advance.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
RenderImage : unexpected segfault...
« Reply #1 on: April 08, 2011, 07:58:24 am »
You should rather use gdb and display the call stack. The crash probably happens during the destruction of the render image.
Laurent Gomila - SFML developer

chocobn

  • Newbie
  • *
  • Posts: 39
    • View Profile
RenderImage : unexpected segfault...
« Reply #2 on: April 08, 2011, 12:08:26 pm »
Gdb doesn't want to display the call stack ! I'm using the GDB geany plugin. It seems so strange to me to can't succeed to display a call stack in that case... :(

Indeed, it looks like it is during the destruction of the renderimage, because if I create it via a pointer (i don't know how this is really called), it works, but the renderimage is not destroyed!

Code: [Select]

sf::RenderImage* RI = new sf::RenderImage();

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
RenderImage : unexpected segfault...
« Reply #3 on: April 08, 2011, 12:11:38 pm »
You must use a debug version of SFML.
Laurent Gomila - SFML developer

chocobn

  • Newbie
  • *
  • Posts: 39
    • View Profile
RenderImage : unexpected segfault...
« Reply #4 on: April 08, 2011, 12:17:07 pm »
Sorry i'm such a newbie but i never did that kind of things! I'm using cmake. How could i change the libraries for the debug versions?

There are the concerned parts of my cmake file :

Code: [Select]

find_package(SFML REQUIRED COMPONENTS graphics window system)

target_link_libraries(Programme ${SFML_SYSTEM_LIBRARY} ${SFML_AUDIO_LIBRARY} ${SFML_GRAPHICS_LIBRARY} ${SFML_WINDOW_LIBRARY} ${GTKMM_LIBRARIES})


i tried
Code: [Select]
target_link_libraries(Programme ${SFML_SYSTEM_LIBRARY} ${SFML_AUDIO_LIBRARY} ${SFML_GRAPHICS_LIBRARY_DEBUG} ${SFML_WINDOW_LIBRARY} ${GTKMM_LIBRARIES})

but it doesn't works...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
RenderImage : unexpected segfault...
« Reply #5 on: April 08, 2011, 12:28:58 pm »
You must compile the debug SFML libraries (with CMAKE_BUILD_TYPE = Debug), and then in your project it's better to link to the debug version of all modules.
Laurent Gomila - SFML developer

chocobn

  • Newbie
  • *
  • Posts: 39
    • View Profile
RenderImage : unexpected segfault...
« Reply #6 on: April 08, 2011, 01:25:38 pm »
ok, I did that, but it doesn't change anything... I still have this segfault. In my mind, it is at the destruction of the renderImage... Something in the destructor of renderImage that bugs, maybe because of my code. But I might be wrong

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
RenderImage : unexpected segfault...
« Reply #7 on: April 08, 2011, 01:32:42 pm »
Quote
ok, I did that, but it doesn't change anything...

That should work.
What if you run gdb from the command line?
Laurent Gomila - SFML developer

chocobn

  • Newbie
  • *
  • Posts: 39
    • View Profile
RenderImage : unexpected segfault...
« Reply #8 on: April 08, 2011, 01:39:45 pm »
I will try, but it may take some time because i never did that and i have to learn how it works.
Is there a way to ensure that i am using the debug libraries?
I have compiled sfml in debug and changed my project's cmakelists.txt file to :

Code: [Select]
[...]
target_link_libraries(Programme ${SFML_SYSTEM_LIBRARY_DEBUG} ${SFML_AUDIO_LIBRARY_DEBUG} ${SFML_GRAPHICS_LIBRARY_DEBUG} ${SFML_WINDOW_LIBRARY_DEBUG} ${GTKMM_LIBRARIES})
[...]

chocobn

  • Newbie
  • *
  • Posts: 39
    • View Profile
RenderImage : unexpected segfault...
« Reply #9 on: April 08, 2011, 01:43:06 pm »
Actually, i succeed easily to use gdb... here is the backtrace, directly from the console :
Code: [Select]
(gdb) backtrace
#0  0x0166d675 in xcb_writev () from /usr/lib/libxcb.so.1
#1  0x01488dec in _XSend () from /usr/lib/libX11.so.6
#2  0x01488f90 in _XReply () from /usr/lib/libX11.so.6
#3  0x0147c867 in XSync () from /usr/lib/libX11.so.6
#4  0x013ac205 in ?? () from /usr/lib/fglrx/libGL.so.1
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

What does mean the last line? Is it the source of the problem?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
RenderImage : unexpected segfault...
« Reply #10 on: April 08, 2011, 01:48:13 pm »
Hmm... it's not really helpful (there's no function from SFML or your own code).

Ok, let's try something else. Could you show me a complete and minimal code thatreproduces your problem? I insist on complete and minimal ;)
Laurent Gomila - SFML developer

chocobn

  • Newbie
  • *
  • Posts: 39
    • View Profile
RenderImage : unexpected segfault...
« Reply #11 on: April 08, 2011, 02:01:32 pm »
hoping it is as minimal as expected! (at least it's complete I think ;) )

thank you very much for your help!

main.cpp
Code: [Select]

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <iostream>
sf::Image getFlatennedImage()
{
std::cout<< "debutFonction" <<std::endl;
sf::RenderImage RI;
RI.Create(800,600);
RI.SetActive();
    RI.Clear();
RI.Display();
std::cout<< "finFonction" <<std::endl;
return RI.GetImage();
}


int main()
{
    // Create the main window
    sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window");

    // Start main loop
    bool Running = true;
    while (Running)
    {
std::cout<< "avant appel" <<std::endl;
        getFlatennedImage();
std::cout<< "apres appel" <<std::endl;
        App.Display();
    }

    return EXIT_SUCCESS;
}


cmakelists.txt (not really needed, but may be helpful)
Code: [Select]
# explications qt = http://www.marcossantamaria.com/tutorialdata.php?id=3
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_FLAGS "-Wall -W -ansi -pedantic -g")

set(CMAKE_BUILD_TYPE CMAKE_CXX_FLAGS_DEBUG)

#Déclaration du projet
project(Programme)


find_package(SFML REQUIRED COMPONENTS graphics window system)


#Déclaration de l'exécutable
add_executable(
Programme
main.cpp
)


target_link_libraries(Programme ${SFML_SYSTEM_LIBRARY_DEBUG} ${SFML_AUDIO_LIBRARY_DEBUG} ${SFML_GRAPHICS_LIBRARY_DEBUG} ${SFML_WINDOW_LIBRARY_DEBUG})

INSTALL_TARGETS( /bin Programme)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
RenderImage : unexpected segfault...
« Reply #12 on: April 08, 2011, 02:04:42 pm »
Try to add an event loop that process event from the window (it doesn't have to do something useful, just call GetEvent).

And is the first call crashing? Or is it happening after a certain amount of calls?
Laurent Gomila - SFML developer

chocobn

  • Newbie
  • *
  • Posts: 39
    • View Profile
RenderImage : unexpected segfault...
« Reply #13 on: April 08, 2011, 02:11:10 pm »
it does exactly that
Code: [Select]

$ ./Programme
avant appel
debutFonction
finFonction
Segmentation fault


even with adding:
Code: [Select]
sf::Event Event;
while (App.GetEvent(Event))
{
// Process event
}


into the loop

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
RenderImage : unexpected segfault...
« Reply #14 on: April 08, 2011, 02:57:38 pm »
Which revision of SFML 2 are you using?

Does the "shader" example work?
Laurent Gomila - SFML developer