SFML community forums
Help => Graphics => Topic started by: td123 on June 18, 2011, 04:50:01 pm
-
I can't seem to figure out what should be a simple example.
I'm using sfml2.
Running the following code will return 1 in the bash prompt.
#include <SFML/Graphics.hpp>
class GameVars {
public:
GameVars() {
titleImage.LoadFromFile("title.png");
titleSprite.SetImage(titleImage);
titleSprite.SetPosition(0,0);
}
sf::Sprite titleSprite;
sf::Image titleImage;
};
int main() {
GameVars gamevars;
sf::RenderWindow window(sf::VideoMode(320, 200), "tppxx");
while(window.IsOpened()) {
// process events
sf::Event event;
while(window.PollEvent(event)) {
// close window
if(event.Type == sf::Event::Closed) {
// close the window
window.Close();
}
}
// clear screen
window.Clear();
window.Draw(gamevars.titleSprite);
// update window
window.Display();
}
return EXIT_SUCCESS;
}
it immediately returns 1, and running it through valgrind produces:
==10707== Conditional jump or move depends on uninitialised value(s)
==10707== at 0x4E543DE: sf::Renderer::SetShader(sf::Shader const*) (in /usr/lib/libsfml-graphics.so.2.0)
==10707== by 0x4E553EB: sf::RenderTarget::Draw(sf::Drawable const&) (in /usr/lib/libsfml-graphics.so.2.0)
==10707== by 0x401583: main (in /home/tom/The-Puzzle-Pits/tppxx/test)
==10707==
==10707== Conditional jump or move depends on uninitialised value(s)
==10707== at 0x4E54229: sf::Renderer::SetBlendMode(sf::Blend::Mode) (in /usr/lib/libsfml-graphics.so.2.0)
==10707== by 0x4E3BC82: sf::Drawable::Draw(sf::RenderTarget&, sf::Renderer&) const (in /usr/lib/libsfml-graphics.so.2.0)
==10707== by 0x4E553F9: sf::RenderTarget::Draw(sf::Drawable const&) (in /usr/lib/libsfml-graphics.so.2.0)
==10707== by 0x401583: main (in /home/tom/The-Puzzle-Pits/tppxx/test)
==10707==
==10707== Conditional jump or move depends on uninitialised value(s)
==10707== at 0x4E5432E: sf::Renderer::SetTexture(sf::Image const*) (in /usr/lib/libsfml-graphics.so.2.0)
==10707== by 0x4E58CB1: sf::Sprite::Render(sf::RenderTarget&, sf::Renderer&) const (in /usr/lib/libsfml-graphics.so.2.0)
==10707== by 0x4E553F9: sf::RenderTarget::Draw(sf::Drawable const&) (in /usr/lib/libsfml-graphics.so.2.0)
==10707== by 0x401583: main (in /home/tom/The-Puzzle-Pits/tppxx/test)
-
The Valgrind output is ok, don't worry about it.
The debugger output would be more helpful ;)
I'm using sfml2.
Which revision?
-
The Valgrind output is ok, don't worry about it.
The debugger output would be more helpful ;)
I'm using sfml2.
Which revision?
on archlinux, sfml 1.99.git20110616-1 which is just a snapshot taken on the date in the version
after putting a breakpoint on the draw function, I did the following:
I don't understand why titleSprite is an incomplete type.
print gamevars
$1 = {titleSprite = <incomplete type>, titleImage = {<sf::Resource<sf::Image>> = {myObservers = {_M_t = {
_M_impl = {<std::allocator<std::_Rb_tree_node<sf::ResourcePtr<sf::Image>*> >> = {<__gnu_cxx::new_allocator<std::_Rb_tree_node<sf::ResourcePtr<sf::Image>*> >> = {<No data fields>}, <No data fields>},
_M_key_compare = {<std::binary_function<sf::ResourcePtr<sf::Image>*, sf::ResourcePtr<sf::Image>*, bool>> = {<No data fields>}, <No data fields>}, _M_header = {_M_color = std::_S_red,
_M_parent = 0xc70270, _M_left = 0xc70270, _M_right = 0xc70270}, _M_node_count = 1}}}, myMutex = {<sf::NonCopyable> = {<No data fields>},
myMutexImpl = 0x604110}}, <sf::GlResource> = {<No data fields>}, myWidth = 320, myHeight = 200, myTextureWidth = 320, myTextureHeight = 200, myTexture = 1, myIsSmooth = false,
myPixels = {<std::_Vector_base<unsigned char, std::allocator<unsigned char> >> = {
_M_impl = {<std::allocator<unsigned char>> = {<__gnu_cxx::new_allocator<unsigned char>> = {<No data fields>}, <No data fields>}, _M_start = 0x7ffff7f76010 "", _M_finish = 0x7ffff7fb4810 "",
_M_end_of_storage = 0x7ffff7fb4810 ""}}, <No data fields>}, myTextureUpdated = false, myArrayUpdated = true, myPixelsFlipped = false}}
-
Just to state this if it wasn't clear, the image was never drawn to the screen.
-
But where does the application stop?