Okay, thank you, texus!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts MenuQuote from: cg923 on 09 April 2024, 19:31:13doesn't your original problem disappearActually, it doesn't. If get() throws the exception that isn't caught, the program will terminate and in the terminal I will be able to see what happened (what was the reason to terminate) whereas a nullptr dereference will cause a segfault without any explanation.
Quote from: texus on 09 April 2024, 19:25:22make the first parameter a templateOh, that's even better. Thank you for your advice!
template <class WidgetType>
typename WidgetType::Ptr get(tgui::Gui &gui,const String& widgetName) const
{
auto ptr=gui.get<WidgetType>(widgetName);
if(ptr==nullptr) throw std::runtime_error("reason+widgetName");
return ptr;
}
+ the same function which is overloaded for tgui::Container* instead of tgui::Gui.
Quote from: cg923 on 08 April 2024, 18:50:18For example, I might want to add a widget if get() returns nullptr, or something like that.I can also do this in case of an exception being thrown, can't I? Anyway we have already discussed that using exceptions might break backwards compatibility, so the only thing I would be glad to see is some information in the terminal.
Quote from: cg923 on 08 April 2024, 18:50:18might be annoyingI admit that it might be, but isn't it annoying to spend time using a debugger only to figure out that there was a mistake in the naming? As Texus has suggested, we can use a global flag to disable these messages (or we may not print them in the release version of the library, but do it in the debug one).
gui.add(picture, "picture");
//...
func(gui.get<...>("picturW")); //(1)
//////////
func(Picture::Ptr pic):
pic->getRenderer()->setTexture(texture); //(2) We will get a segmentation fault only there!
//And in my case I truly believed that the problem was with the setTexture() function
Quote from: texus on 06 April 2024, 22:18:37That assertion means you are trying to create the Texture before the Gui has been constructed.oh, yes, I haven't updated the page and haven't noticed your reply, but why do I need some backend to create a texture?
texture.loadFromPixelData(smg.getSize(), smg.getPixelsPtr());
//smg - sf::Image;
//texture - tgui::Texture;
I definitely know that sf::Image is loaded correctly and is not empty.tgui::Backend::createTexture() (Unknown:0)
tgui::Texture::loadFromPixelData(tgui::Vector2<unsigned int>, unsigned char const*, tgui::Rect<unsigned int> const&, tgui::Rect<unsigned int> const&, bool) (Unknown:0)
Backend::GetTextureFromClipboard() (Backend.hpp:37)
main() (test.cpp:41)
UPD: I've rebuilt tgui with debug flag and I have the following message from tgui::getBackend():TGUI assertion: getBackend() was called while there is no backend
test: /.../LIBS/TGUI-1.2.0/src/Backend/Window/Backend.cpp:77: std::shared_ptr<tgui::Backend> tgui::getBackend(): Assertion `globalBackend != nullptr' failed.//Briefly
BalanceRatio()
{
SpindleControl2->setValue(BalancedValue);
} SpindleControl1->onValueChange([](){
//Some code here
SpindleControl1->setFocused(0);
});
SpindleControl1->onUnfocus(BalanceRatio);
And it worked pretty nice until I noticed that if I press the arrow continuously, onUnfocus will be never called.
.
tgui::Font font;
font.getBackendFont()->loadFromFile("font.ttf");
but this leads to a segmentation fault. Are there any ways to do what I intend to do?
Quote from: texus on 25 March 2024, 18:24:54all TGUI widgets need to be destroyed before the Gui object is destroyed.Oh, that's it. I swapped two lines in the code (see below) and it settled the matter, thank you!
//How it was:
Scene scene;
tgui::Gui gui;
//How it is now:
tgui::Gui gui;
Scene scene;
class Scene
{
public:
std::list<tgui::Group::Ptr> groups;
private:
using iterator = std::list<tgui::Group::Ptr>::iterator;
iterator current_group;
void change_scene(iterator &from, iterator &to);
};
scene.groups.emplace_back(tgui::Group::create());
//Some widgets initialization and adding them to the group
gui.add(scene.groups.begin());
It works pretty nice until I close the program (and ~Scene() is called) and get Seg fault message. I've attached the picture from the debugger.
bool linked = 1;
tgui::Texture link_t[2];
for (short i = 0; i < 2; ++i)
link_t[i].load("lu.png", {unsigned(50 * i), 0, 50, 50});
auto link_b = gui.get<tgui::Button>("link_b");
auto lb_func = [&link_b, &linked, &link_t]()
{
linked = !linked;
link_b->getRenderer()->setTexture(link_t[linked]);
};
gui.get<tgui::Button>("link_b")->onClick(lb_func);
It's expected the texture to be changed every time I click the button, but actually it changes only once. bool linked = 1;
tgui::Texture linked_t, unlinked_t;
linked_t.load("linked.png");
unlinked_t.load("unlinked.png");
auto link_b = gui.get<tgui::Button>("link_b");
if (linked)
link_b->getRenderer()->setTexture(linked_t);
else
link_b->getRenderer()->setTexture(unlinked_t);
auto lb_func = [&link_b, &linked, &linked_t, &unlinked_t]()
{
linked = !linked;
if (linked)
link_b->getRenderer()->setTexture(linked_t);
else
link_b->getRenderer()->setTexture(unlinked_t);
};
gui.get<tgui::Button>("link_b")->onClick(lb_func);And it works pretty good! I think the problem that my first piece of code uses the textures with the same ID. Perhaps, that's the reason why setTexture() doesn't change the texture.
spin_control->hideWithEffect(...) none of the effects affects widget somehow.spin_control->getRenderer()->setOpacity(0) nothing happens again. spin_control->getSpinButtonRenderer()->setOpacity(0.5);
spin_control->getSpinTextRenderer()->setOpacity(0.5);it actually works.