Read access violation when Loading a form file.

Started by Dani305, 05 May 2023, 22:01:52


Okay, so I've been trying to find a solution around this error all day with no Luck. So, I'm working on a project that has a login screen that is loaded from a Form file but when I do login and the program tries to load another Form file the program crashes and opens the xtree file with the error "Unhandled exception thrown: read access violation." and "**_Scary** was 0xEA8.".The thing is that everything worked fine yesterday and I commited my work to my repo and some of my teammates ran the code and it worked fine....

Note: I tried everything on the forum and search online with no luck.


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

#pragma once

#define STUDENT_FORM_PATH "resources/StudenetForm.txt"
#define INSTRUCTOR_FORM_PATH "resources/InstructorFrm.txt"
#define LOGIN_FORM_PATH "resources/LoginScrnForm.txt"

class FormManger


tgui::String Student = STUDENT_FORM_PATH;

tgui::String Login = LOGIN_FORM_PATH;

tgui::String Instructor = INSTRUCTOR_FORM_PATH;


void Setscreen(sf::RenderWindow& win, tgui::GuiSFML& gui, tgui::String User, tgui::String Usertype);


#include "FormManger.h"

void FormManger::Setscreen(sf::RenderWindow &win,tgui::GuiSFML &gui ,tgui::String User, tgui::String Usertype)
try {
if (Usertype == "IN")
std::cout << "\nLogged in as Instructor\n";

else if(Usertype == "ST")

std::cout << "\nLogged in as Student\n";
gui.loadWidgetsFromFile(Form.Student, true);
catch(const tgui::Exception &e)
std::cout << "Error occoured: " << e.what() << std::endl;


Thanks in advance for the help.


0xEA8 is a rather low number. A read violation that close to 0x0 usually means that a function is being called on a nullptr object.

In e.g. your 'gui.get<tgui::Button>("USR_Button")->setText(User);' line, are you certain that "USR_Button" exists and is a Button type? Otherwise 'gui.get<tgui::Button>("USR_Button")' would be a nullptr.

If you run the code with a debugger it should tell you exactly where it crashes. If the location isn't in your own code, you should be able to show a call stack that will tell you exactly where it happened.


Quote from: texus on 05 May 2023, 22:15:43In e.g. your 'gui.get<tgui::Button>("USR_Button")->setText(User);' line, are you certain that "USR_Button" exists and is a Button type? Otherwise 'gui.get<tgui::Button>("USR_Button")' would be a nullptr.

I Tried to comment this line and rerun the code, but still the problem still persists. Another thing that happened is that the problem was with the Instructor form file with the student one working completely fine until it randomly decided to not work and throw the same error at me.