Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when creating ProgressBar #106

Closed
Kvaz1r opened this issue Aug 27, 2019 · 10 comments
Closed

Exception when creating ProgressBar #106

Kvaz1r opened this issue Aug 27, 2019 · 10 comments

Comments

@Kvaz1r
Copy link
Contributor

Kvaz1r commented Aug 27, 2019

MCVE(also can be reproduced in sample Many different widgets):

#include <TGUI/TGUI.hpp>
#include <iostream>

int main()
{
	sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
	tgui::Gui gui(window);
	try
	{
		auto progress = tgui::ProgressBar::create();
		gui.add(progress);
	}
	catch (std::exception& exc)
	{
		std::cout << exc.what() << '\n';
	}

	while (window.isOpen())
	{
		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();

			gui.handleEvent(event); // Pass the event to the widgets
		}

		window.clear();
		gui.draw(); // Draw all widgets
		window.display();
	}
}

Log:

Failed to add a new character to the font: the maximum texture size has been reached
vector too long

@texus
Copy link
Owner

texus commented Aug 27, 2019

I can't reproduce this. I tried it on both windows and linux but it just works without any error.
Creating a progress bar and adding it to the gui is also part of the tests that automatically run on windows and linux on each change, so it definitely shouldn't be failing. Maybe in cmake you could try checking the TGUI_BUILD_TESTS option, build TGUI again and run tests.exe (that is found somewhere in the build/tests folder) to see if it fails for you as well.

@Kvaz1r
Copy link
Contributor Author

Kvaz1r commented Aug 28, 2019

Not good, tests fail too, log:

An internal OpenGL call failed in Texture.cpp(98).
Expression:
glFlush()
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.

Failed to add a new character to the font: the maximum texture size has been reached

tests is a Catch v2.2.1 host application.
Run with -? for options

-------------------------------------------------------------------------------
[ProgressBar]
-------------------------------------------------------------------------------
T:\libraries\C++\TGUI-0.8\tests\Widgets\ProgressBar.cpp(28)
...............................................................................

T:\libraries\C++\TGUI-0.8\tests\Widgets\ProgressBar.cpp(28): FAILED:
due to unexpected exception with message:
  vector<T> too long

===============================================================================
test cases:   57 |   56 passed | 1 failed
assertions: 7128 | 7127 passed | 1 failed

P.S. I use VS2019 on Win10.

@texus
Copy link
Owner

texus commented Aug 28, 2019

Maybe this is a problem related to VS2019. I can't test that right now unfortunately (as I just started with completely reinstalling my PC today). It also looks like AppVeyor doesn't support VS2019 yet.

Did you build both SFML and TGUI yourself with the exact compiler that you are using?

@Kvaz1r
Copy link
Contributor Author

Kvaz1r commented Aug 28, 2019

Yes, I built both libraries with this same compiler. Maybe it's really a problem with VS2019, unfortunately I can't downgrade it.

@eXpl0it3r
Copy link

maximum texture size has been reached

This sounds more like a limitation of GPU as in, it only supports small-ish texture sizes. What's your GPU? What version of SFML are you on?

@texus what font does TGUI use? And is that an error from TGUI itself?

@texus
Copy link
Owner

texus commented Aug 28, 2019

TGUI uses DejaVuSans (stored as an unsigned char[] in the code which gets passed to sf::Font::loadFromMemory). It isn't a TGUI exception, I have never encountered it before.

@Kvaz1r
Copy link
Contributor Author

Kvaz1r commented Aug 28, 2019

This sounds more like a limitation of GPU as in, it only supports small-ish texture sizes. What's your GPU? What version of SFML are you on?

I don't think so because all other widgets created without problem.
GPU - Radeon RX Vega10. , SFML-2.5.1

I tried to debug the issue and found that for some reason when progress bar is set renderer variable
textSize get value 4294967295 and after for obvious reason it crashes in loadGlyph.

@texus
Copy link
Owner

texus commented Aug 28, 2019

The character size is always initialized in sf::Text, so either setCharacterSize was called with an invalid value or the entire tgui::Text object that contains the sf::Text object is already invalid. Neither seem very likely to me.

I just got a clean Windows 10 with VS2019 working and it doesn't crash for me. The tests all pass. I do get the OpenGL error in the tests, but this happens somewhere in Picture.cpp so it doesn't look related.

Double check to make sure that the SFML and TGUI libraries are compatible (the SFML libs used in your project must be the exact same ones as the ones that were found by cmake when building TGUI, you can't even mix release and debug files).

If you are certain that the libraries are compatible then maybe you could try debugging the code some more by e.g. printing the parameter in Text::setCharacterSize.

@Kvaz1r
Copy link
Contributor Author

Kvaz1r commented Aug 28, 2019

No, I am definitely sure it's not about library compatibilities. I investigated it a bit more and found that innerSize at this point has negative value, result of next expression become negative infinum what obvious can't give good result after casting.

So I just added checking:
if (getInnerSize().x > 0 && m_textBack.getSize().x > (getInnerSize().x * 0.85f))
and all tests passed.

@texus
Copy link
Owner

texus commented Aug 28, 2019

Thanks for debugging and finding the issue, I'll fix it tomorrow in a few minutes (together with the other widgets that have similar code). I don't think getInnerSize should ever be negative, so I'll just change the getInnerSize function itself, that should prevent similar issues in the future.

I was looking in that function earlier, trying to find some case where Text::findBestTextSize could possibly give a negative number, but I didn't realize there was another setCharacterSize call just a few lines below.

@texus texus closed this as completed in d511f3a Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants