Whenever I try to assign a variable to the value of any member variable of this struct from inside only this one function (this doesn’t happen for any others) I am given an std::bad_alloc exception. the struct and function are shown below (Note this is not the full struct)
struct mesh {
mesh() {
}
mesh(std::vector<triangle> &triangles) {
vertexList = triangles;
}
private:
public:
std::string Name{};
std::vector<triangle> vertexList{};
};
Note this is not the full function but the issue still occurs with only this.
mesh* world::addMesh(mesh *Mesh) {
std::string test = Mesh->Name;
return nullptr;
}
the mesh pointer that is being given to addMesh was just created before this by these lines of code. It was created globally the only time a member variable was modified before this was to set its name with Mesh->Name = "test";
.
mesh* Mesh = loadOBJ("path");
and is created by these lines:
mesh* triMesh = new mesh(tri);
return triMesh;
Also sometimes when creating Mesh with the above lines of code triMesh will just contain junk memory causing Mesh to also contain junk memory. By that I mean all member variables look uninitialized despite them having initializers this is seemingly random and after I restart the program a few times it stops happening for a little this makes me feel like I have undefined behavior somewhere. Despite this I have confirmed that the above issue still occurs when Mesh is valid via inspecting it with the debugger and creating it with mesh* Mesh = new mesh();
instead of the former.
Not sure if this is relevant but if I try to access any of the vectors of the struct from inside this function I am given the debug assertion for index out of bounds. I also have a 13900k CPU and only have had this issue recently the exact same code worked about a month ago.
To reiterate this issue only occurs in the addMesh function if I create a new identical function this issue does not happen at this point I am more curious as to why its happening.
When breaking on that line and looking at the values I can see that they are all valid. I can edit this post for more info if needed. I attempted a minimal reproducible example but couldn’t replicated the issue in a new project.
46784 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.