[Possible Bug] Canvas not displaying
« on: 30 October 2018, 17:55:47 »
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
Code: [Select]
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.
Code: [Select]
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

  • *****
  • 1276
    • View Profile
    • Texus's Blog
Re: [Possible Bug] Canvas not displaying
« Reply #1 on: 30 October 2018, 19:09:17 »
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?
// 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:
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.

Re: [Possible Bug] Canvas not displaying
« Reply #2 on: 30 October 2018, 22:00:56 »
SFML was out of date, that looks like it fixed it.

Thanks!