Wrong display of background texture

Started by china92, 31 May 2013, 18:15:33


I don't know if it is an bug in tgui/sfml, or I wrote something in a wrong way, but I have a problem.

Right now I'm trying to make my own tgui::ChildWindow with turrets (TurretWindow). I already made my own tgui::Panel (InformationPanel), which displays Informations (and 'latches' it).

Informations contains pointer to a texture, and list of strings, InformationPanel puts string into labels and copy the texture from Informations. Texture in InformationPanel is displayed by using setBackgtoundTexture on tgui::Panel named 'image'.

Right now I added some turrets into a TurretWindow, but only the last InformationPanel displays texture correctly and I don't know why...

I'm attaching code, and asking for help.


It took me some time, but I think I have found the issue.

Your TurretWindow has a member turretPanels, which is a vector of InformationPanel. This InformationPanel contains an sf::Texture object. Sprites keep a pointer to the texture, so the location of the InformationPanel may not be moved. However, because you are using a vector, reallocation can take place when adding a new object. Your InformationPanel was moved and so was your texture, but the sprites kept the pointer to the old location.
There are different ways to fix this, but I think the easiest way would be to use a list of it instead of a vector. This does mean that you have to work with iterators instead of using the [] operator, so some code might need to change.

Its not related to this issue, but you should make two small changes to your code.
- In your addTurret function you pass **this as parent when creating InformationPanel. It should be *turretGrid as it is supposed to be part of the grid and not part of the child window.
- When you include a header, you should use '/' instead of '\'. That way I can at least compile your code without changes :).


Yes, the problem was in this reallocation. I was trying to figure it out by myself but I gave up, I would never thought about it for my own, so thank you so much for your help, I do really appreciate it! :D

And of course you are right about those two last advices, thanks for them as well. :)

My tower defense is almost ready for playing, so I'll show you what I'm doing soon.


Quote from: china92 on 01 June 2013, 10:58:48
My tower defense is almost ready for playing, so I'll show you what I'm doing soon.
If you want to see the effect of my work: https://en.sfml-dev.org/forums/index.php?topic=11783.msg81779#msg81779 ;)