0
Debug assertion failed
Why vs cpp throws a run-time error where it says Expression: vector subscript out of range
5 Respostas
+ 5
Don't make duplicates!
https://www.sololearn.com/Discuss/1588225/runtime-error
+ 2
Ilias, I find this a bit strange.
You post a line of code here that suggests a specific kind of answer. And only AFTER you hear a possible reason, you show your actual code that could mean anything.
Then now I hear you even have posted the same question before.
Before you post a question here, you should honestly try to find the mistake yourself. If that doesn't succeed, you should think well about what you're even asking, and write it in a way that people can understand. And do that ONCE, not several times.
+ 1
Sounds like you shot over the limit.
Like your vector has 3 elements (0, 1, 2) and you tried to access a fourth element (v[3].)
0
void GLSLProgram::compileShader(const std::string& filePath, GLuint& id)
{
std::ifstream fileptr(filePath);
if (fileptr.fail()) {
// Not sold on this
perror(filePath.c_str());
fatalError("Failed to Open " + filePath);
}
std::string fileContents = "";
std::string line;
while (std::getline(fileptr, line))
{
fileContents += line + "\n";
}
fileptr.close();
// This is weird
const GLchar * contentsPtr = fileContents.c_str();
glShaderSource(id, 1, &contentsPtr, 0);
glCompileShader(id);
GLint success = 0;
glGetShaderiv(id, GL_COMPILE_STATUS, &success);
if (success == GL_FALSE) {
GLint maxLength = 0;
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &maxLength);
std::vector<GLchar> errorLog(maxLength);
glGetShaderInfoLog(id, maxLength, &maxLength, &errorLog[0]);
glDeleteShader(id);
std::printf("%s\n", &(errorLog[0]));
fatalError("Shader " + filePath + " failed to Compile");
}
0
That is how I use vector.