[Possible Bug] Canvas not displaying

Started by methinks82, 30 October 2018, 17:55:47

methinks82

When creating a canvas widget, if setSize is called after the canvas is added to it's parent the canvas will not display.

This version works

tgui::Canvas::Ptr canvas = tgui::Canvas::create();
canvas->setPosition(50,50);
canvas->setSize(100,100);
gui.add(canvas);
canvas->clear("100,100,100");
canvas->display();


When we switch the order of canvas->setSize and gui.add, the canvas no longer displays.

tgui::Canvas::Ptr canvas = tgui::Canvas::create();
canvas->setPosition(50,50);
gui.add(canvas);                   // moved before setSize
canvas->setSize(100,100);
canvas->clear("100,100,100");
canvas->display();


It doesn't matter if the parent is gui or another widget (such as panel)
I haven't observed this behavior with any other widgets.

TGUI 0.8.1
Visual C++ 2017 15.8.8

texus

I can't reproduce this here, so it might be related to your graphics driver. Which SFML version are you using? Make sure try the latest SFML version (2.5.1) as the render texture code has had several changes in the last few versions.

To rule out the possibility that this is a bug in TGUI, what happens if you use the following code?
Code (cpp) Select
// Create the RenderTexture and Sprite which the Canvas created for you
sf::RenderTexture rt;
sf::Sprite sprite;

// This code is executed only if gui.add is placed before setSize
rt.create(800, 600);
sprite.setTexture(rt.getTexture(), true);
rt.clear();
rt.display();

// This code is executed when calling setSize
rt.create(100, 100);
sprite.setTexture(rt.getTexture(), true);
rt.clear();
rt.display();

// This was your clear and display call
rt.clear({100,100,100});
rt.display();


You will also need to put the following in your draw loop for it to show up in the top left corner:
Code (cpp) Select
window.draw(sprite);

If it doesn't show and removing the first part where rt.create is called does work, then it is clearly an error in SFML or your graphics driver. If the code does work however, then it may still be an issue in TGUI and then I'll try to investigate further.

methinks82

SFML was out of date, that looks like it fixed it.

Thanks!