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

Author Topic: Font .loadFromFile throwing a access violation. [SOLVED]  (Read 25015 times)

0 Members and 1 Guest are viewing this topic.

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Font .loadFromFile throwing a access violation.
« Reply #15 on: November 19, 2012, 09:07:31 pm »

Have you tried a different position?

CurserPosText.setPosition(236,240);

Just did. I also have it printing X/Y cords just fine in the console window so I know that the string is not empty. Its how I found out to try to put it at 236/240  ;D

Still no text tho.

Not sure if this is a hint but I've discovered that changing my:
sf::Text CurserPosText;

From private to global causes sfml graphics to throw a:
Quote
Unhandled exception at 0x57049035 (sfml-graphics-d-2.dll) in Genesis.exe: 0xC0000005: Access violation writing location 0x00000000.

at:
CurserPosText.setString(MousePos);

Hmm

Found out even more. It will throw the exception if I ever move it from its location to any other location in the header file.
private:
        bool Enabled;
        sf::Text CurserPosText; //If this is moved we will get a exception the first time its called.
        sf::Font DevHudFont;
        sf::String MousePos;
        sf::Vector2i mouse_pos;

        void setVars(EngineWindow&);
 

Maybe its because its used in the constructor?

Apparently moving the "Enabled" bool variable fixed this issue. o.O ...* extremely confused* Still no text.
« Last Edit: November 19, 2012, 09:48:37 pm by Flash619 »

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Font .loadFromFile throwing a access violation.
« Reply #16 on: November 19, 2012, 11:04:31 pm »
So still no text after a few hours of playing around with it........ -_-

I'm trying to convert the text back to a string with:

        mouse_pos = sf::Mouse::getPosition(glWindow);
                MousePosSS << "Mouse Pos: " << "X: " << mouse_pos.x << " Y: " << mouse_pos.y;
                MousePosS = MousePosSS.str();
                consoleLog.info(MousePosS);
                CurserPosText.setString(MousePosSS.str());
                sf::String myTest = CurserPosText.getString();
                std::string myString = myTest.toAnsiString();
                consoleLog.info(myString);
 

To see whats in it, to see if that's why it won't show up. Unfortunately this is making my program throw constant breaks for some reason. Any ideas? I really could use a break right about now, because I'm completely out of ideas.

So there I was one day, just clicking around in the debug window pretending to know what I'm doing, and I ran across this....

Quote
-      m_font   0xcccccccc {m_library=??? m_face=??? m_streamRec=??? ...}   const sf::Font *

Looks like the problem is the font yet.

I included a snippit of the error.


Tried to test some stuff......

Get this error:
Quote
Run-Time Check Failure #2 - Stack around the variable 'MyFont' was corrupted.

Came from:
DevHud::DevHud()
{
        DevHudEnabled = false;
        sf::Font MyFont;
        if(!MyFont.loadFromFile("arial.ttf"))
        {

        }
        CurserPosText.setFont(MyFont);
        //Setting up defaults for font/text elements.
        //fontUtils.SetupText(fontUtils.DevHud,DevHudFont,CurserPosText);
        CurserPosText.setPosition(236,240);
        CurserPosText.setCharacterSize(40);
}
 

o.O; Would seem my font became instantly corrupt.....

EDIT

Yep its official the problem is that the font is pointing to blank memory adresses, and as a result, the sf::text is getting currupt font data.  ::) Still have no idea what to do about it. But now I know the root of the issue.

In short the error "I believe" is this:

It creates the Font object -> Loads the font in successfully -> ???Looses its Font info??? ->Tries to set a font to a invalid memory location *bam exception* or it is somehow successful and -> loads in the corrupt font data anyways -> Doesn't display anything because it was given bad memory locations when it tried to load the font and it is now corrupt.

Hope that makes some sense. I'm working on poking it with a stick right now.

Well after poking it with a stick several times. I have found something.

If I call:
fontUtils.SetupText(fontUtils.DevHud,DevHudFont,CurserPosText);
 

It can load its font just fine, it keeps its memory addresses, everything works well. However, the moment I tell a text object that its font is "DevHudFont" the fonts memory addresses show up as a bunch of "0"s in the debug window, and the text as a result gets corrupt font data.

Any ideas on why setting the font would make the font go batty? XD

[attachment deleted by admin]
« Last Edit: November 19, 2012, 11:49:04 pm by Flash619 »

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Font .loadFromFile throwing a access violation.
« Reply #17 on: November 20, 2012, 12:52:35 am »
Ok So I found that it ONLY goes corrupt when its in the other class.

I just put the following into my main loop:

                sf::Vector2i mouse_pos;
        mouse_pos = sf::Mouse::getPosition(glWindow);
                std::stringstream MousePosSS;
                MousePosSS << "Mouse Pos: " << "X: " << mouse_pos.x << " Y: " << mouse_pos.y;
                std::string MousePosS;
                MousePosS = MousePosSS.str();
                ConsoleLog.info(MousePosS);
                sf::Text CurserPosText;
                sf::Font CurserPosFont;
                if(!CurserPosFont.loadFromFile("arial.ttf"))
                {

                }
                CurserPosText.setFont(CurserPosFont);
                CurserPosText.setString(MousePosSS.str());
                MousePosSS.str("");
                glWindow.draw(CurserPosText);
                glWindow.display();
 

And it works perfectly.

Any ideas why that in a object of a class in a loop would fail? o.O

Basically this code his how it fails right now... *Is pseudo code may have miss types"

.h

class MyMainClass{
         void MyMainFunction(sf::RenderWindow&);
};
class DevHud{
         void PrintStuff(sf::RenderWindow&);
};
 

.cpp
void MyMainClass::MyMainFunction(sf::RenderWindow& renderWindow){
        DevHud devHud;
        while(true)
        {
                devHud.PrintStuff(renderWindow);
                //Plus some code here to detect exit and what not.
         }
}
void DevHud::PrintStuff(sf::RenderWindow& renderWindow){
                sf::Vector2i mouse_pos;
                mouse_pos = sf::Mouse::getPosition(renderWindow);
                std::stringstream MousePosSS;
                MousePosSS << "Mouse Pos: " << "X: " << mouse_pos.x << " Y: " << mouse_pos.y;
                std::string MousePosS;
                MousePosS = MousePosSS.str();
                consoleLog.info(MousePosS);
                sf::Text CurserPosText;
                sf::Font CurserPosFont;
                if(!CurserPosFont.loadFromFile("visitor2.ttf"))
                {

                }
                CurserPosText.setFont(CurserPosFont);
                CurserPosText.setString(MousePosSS.str());
                MousePosSS.str("");
                renderWindow.draw(CurserPosText);
                /*And yes, I know this is inefficient but its the quickest simplist example I could come up with. I also have not tested this exact code but basically replicated it in my main class. Its just an example of whats going on and whats causing the error. */
}
 

Thats pretty much all that's happening. Just two classes talking to each other and that's all the error I'm getting. Contently the error is:

Quote
Run-Time Check Failure #2 - Stack around the variable 'CurserPosText' was corrupted.

So let me know if I'm doing something that you shouldn't. Or if you know what the error is, ...or if you have any idea at all because I have none.
« Last Edit: November 20, 2012, 02:32:53 am by Flash619 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Font .loadFromFile throwing a access violation.
« Reply #18 on: November 20, 2012, 08:01:12 am »
I just want to check something, what's your OS, compiler and version of SFML? Are you sure that you don't mix debug and release?
Laurent Gomila - SFML developer

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Font .loadFromFile throwing a access violation.
« Reply #19 on: November 20, 2012, 04:43:06 pm »
I just want to check something, what's your OS, compiler and version of SFML? Are you sure that you don't mix debug and release?

Windows 8 Pro 64 bit

Compiler Version? ....I'll just list some Visual Studio properties since I cant find one thats called that:

Platform Toolset: Visual Studio 2012 (v110)

Aditional dependencies: "Debug Mode"
sfml-graphics-d.lib
sfml-audio-d.lib
sfml-window-d.lib
sfml-main-d.lib
sfml-network-d.lib
sfml-system-d.lib

Aditional dependencies: "Release Mode"
sfml-graphics.lib
sfml-audio.lib
sfml-window.lib
sfml-main.lib
sfml-network.lib
sfml-system.lib


As for the SFML version, its 2.0 I don't know the exact version number.

But that's all of the info you asked for "I hope" If you need any more information please, do ask. :) I'm happy to help you help me in any way I can.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Font .loadFromFile throwing a access violation.
« Reply #20 on: November 20, 2012, 05:05:49 pm »
Did you recompile SFML?
Laurent Gomila - SFML developer

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Font .loadFromFile throwing a access violation.
« Reply #21 on: November 20, 2012, 05:12:22 pm »
Did you recompile SFML?

I think I did... It's been a while. I remember it took a bit to get CMake to work. ^^;; But Yes, I'm fairly sure the lib's I'm using I compiled. Would you like me to re compile?  ???

If your answer is yes. I just re downloaded and re tried cmake to get this error:
Quote
CMake Error: The source directory "C:/Users/Travis/Desktop/SFML-2.0-rc" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

-_- Me and CMake never ever get along it seems.
« Last Edit: November 20, 2012, 05:16:51 pm by Flash619 »

cf

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Font .loadFromFile throwing a access violation.
« Reply #22 on: November 20, 2012, 05:21:10 pm »
Quote
CMake Error: The source directory "C:/Users/Travis/Desktop/SFML-2.0-rc" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

-_- Me and CMake never ever get along it seems.
I don't belive any of the other downloads contains the CMake-files, so you should try the newest snapshot.

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Font .loadFromFile throwing a access violation.
« Reply #23 on: November 20, 2012, 05:28:07 pm »
I don't belive any of the other downloads contains the CMake-files, so you should try the newest snapshot.

Yea I downloaded the wrong file. XD Hence the big "whoops" XD haha

I have AMAZING NEWS!!! The rebuild works flawlessly! I had a bad build. XD I wonder what other errors I had due to that.... >.>' Time to go play with stuff thats working. ^_^

Laurent, Thanks a TON. I would have never expected it to be the build itself.  ;D

Thank you everyone who helped! Without you, I would still be thinking it was my loop. XD