Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Assertion failed after trying to draw text to a window  (Read 3324 times)

0 Members and 1 Guest are viewing this topic.

NipIsTrue

  • Newbie
  • *
  • Posts: 15
    • View Profile
Assertion failed after trying to draw text to a window
« on: September 18, 2019, 10:46:59 pm »
So I am trying to draw some simple text to a window, and when debugged, I get an assertion error that looks like this:
Debug Assertion Failed!

Program: C:\WINDOWS\SYSTEM32\MSVCP120D.dll
File: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xtree
Line: 327

Expression: map/set iterators incompatible

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

after
window.draw(text);

Here is the code that causes the assertion:

void Editor::render(sf::RenderWindow& window) {
        sf::RectangleShape shape(sf::Vector2f(500, 500));
        shape.setPosition(50, 50);
        shape.setFillColor(sf::Color(30, 30, 30));
        window.draw(shape);

        sf::Text text;
        text.setFont(font);
        text.setString("Test");
        text.setFillColor(sf::Color::White);
        text.setPosition(100, 100);
        window.draw(text);
}
 

font is a member of the Editor class, and loadFromFile() is called in the constructor, and appears to work fine.

When built and ran in release mode, I get an access violation exception, if that means anything.
« Last Edit: September 27, 2019, 01:38:29 pm by NipIsTrue »

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Assertion failed after trying to draw text to a window
« Reply #1 on: September 30, 2019, 03:48:48 am »
There is nothing wrong in the code you showed here.
What is this file "xtree"? And are you using some std::map?
Visit my game site (and hopefully help funding it? )
Website | IndieDB

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Assertion failed after trying to draw text to a window
« Reply #2 on: September 30, 2019, 09:19:39 am »
Showing the call stack at time of assert failure would probably help here.

It's interesting that you're creating and destroying an sf::Text on every render. Wouldn't it be more efficient to store that and re-use it?
It's possible that the font creates a texture for the character size requested by a text on demand so it may also destroy this if there is no text using it but I don't know or think that's right. However, if it does, this texture is created and destroyed every time. Again, I don't think that actually happens but don't know enough about how font stays efficient to be certain either way.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

NipIsTrue

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Assertion failed after trying to draw text to a window
« Reply #3 on: September 30, 2019, 01:24:54 pm »
I did not manually include xtree, so my best guess is that sfml is including it somewhere? I am not using any std::maps so I also presume sfml is using it somewhere? Here is the call stack:
    sfml-graphics-d-2.dll!00007ff865d312ad()   Unknown
    sfml-graphics-d-2.dll!00007ff865d36f3f()   Unknown
    sfml-graphics-d-2.dll!00007ff865d2c74a()   Unknown
    sfml-graphics-d-2.dll!00007ff865d1bf48()   Unknown
    sfml-graphics-d-2.dll!00007ff865da539d()   Unknown
    sfml-graphics-d-2.dll!00007ff865da51f5()   Unknown
    sfml-graphics-d-2.dll!00007ff865d6bd49()   Unknown
As for recreating the text object every frame, this is my first time attempting to draw text, so thanks for the tip. I'll try storing the text object as a member of the class.

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Assertion failed after trying to draw text to a window
« Reply #4 on: September 30, 2019, 01:42:30 pm »
it seems you have some kind of messed dll's. did you try a simple minimal code to load and display text? does it gives you the same problem?
Visit my game site (and hopefully help funding it? )
Website | IndieDB

NipIsTrue

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Assertion failed after trying to draw text to a window
« Reply #5 on: October 01, 2019, 02:06:01 am »
Yes, I tried and was unable to re-create the problem. I was able to successfully render the text. However, I have no idea what could be wrong with my dlls. I used the same settings for both projects.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: Assertion failed after trying to draw text to a window
« Reply #6 on: October 02, 2019, 11:43:31 pm »
   sfml-graphics-d-2.dll!00007ff865d312ad()   Unknown
    sfml-graphics-d-2.dll!00007ff865d36f3f()   Unknown
    sfml-graphics-d-2.dll!00007ff865d2c74a()   Unknown
    sfml-graphics-d-2.dll!00007ff865d1bf48()   Unknown
    sfml-graphics-d-2.dll!00007ff865da539d()   Unknown
    sfml-graphics-d-2.dll!00007ff865da51f5()   Unknown
    sfml-graphics-d-2.dll!00007ff865d6bd49()   Unknown
Using the debug libraries this should show a proper call-stack.
Are you somehow running without debug symbols?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

NipIsTrue

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Assertion failed after trying to draw text to a window
« Reply #7 on: October 04, 2019, 01:31:20 am »
I don't think so? If you are asking about linking the right libraries I am sure I am doing that right. How can I check about the symbols though?

NipIsTrue

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Assertion failed after trying to draw text to a window
« Reply #8 on: October 04, 2019, 01:38:14 am »
Also forgot to add:
When I made the text object a member of the Editor class, and called
text.setFont(font);
text.setString("Test");
text.setFillColor(sf::Color::White);
text.setPosition(100, 100);
 
once in the constructor, then called
window.draw(text);
in Editor::render() then I get this:
Debug Error!

R6025
- pure virtual function call


(Press Retry to debug the application)

Once again it is happening after window.draw(text) is called

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Assertion failed after trying to draw text to a window
« Reply #9 on: October 05, 2019, 12:27:10 pm »
You should then press Retry to run the debugger and find out which pure virtual function is called.

But generally I can agree with previous answers, it looks like you are linking (or loading, in case of DLLs) incompatible binaries. Has SFML been compiled for the same compiler version, with exact same settings as your own project (debug/release, static/dynamic standard library, identical compiler flags, etc)? If you didn't compile SFML yourself, that might be worth a try.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

NipIsTrue

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Assertion failed after trying to draw text to a window
« Reply #10 on: October 05, 2019, 05:04:54 pm »
When I clicked retry, it triggered a breakpoint that I did not place after
window.draw(shape)
and when I continued it just exited with no message. I have no idea how to interpret that. However, after messing with breakpoints, the message shows up after
window.draw(text)
and the program it originated from was my executable, not any of the sfml or c++ runtime dlls. I'm also not quite sure how to interpret this. As for compiling sfml, I can give that a try, I was using precompiled binaries.