I need your help once more.
i tried to collect the data of all textures first before i give it to the shader.
Here is my latest commit: collect all texture data and give it to the shader later, (e5490b94) · Commits · C-Fu / OpenGL · GitLab
If there is no texture (so the catch block is executed) it works fine. But if there is a texture, it crashes. Anyone who sees the problem?? the old version where i gave the data to the shader once in the try and once in the catch block it worked.
I don’t see the different that causes the crash
==EDIT==
i figured out that this works:
try
{
if (it->texture == "")
throw std::invalid_argument("no texture name");
std::string tempPath = path;
while (tempPath.back() != '/' && tempPath.back() != '\\')
tempPath.pop_back();
TextureTGA tempTex(std::string(tempPath + vModels.front()->texture).c_str());
tempData->alpha = tempTex.hasAlpha();
tempData->width = tempTex.getWidth();
tempData->height = tempTex.getHeight();
tempData->data = tempTex.getData().data();
vTextures.push_back(tempData);
glTexImage2D(GL_TEXTURE_2D,
0,
vTextures.front()->alpha ? GL_RGBA : GL_RGB,
vTextures.front()->width,
vTextures.front()->height,
0,
vTextures.front()->alpha ? GL_BGRA : GL_BGR,
GL_UNSIGNED_BYTE,
tempData->data = tempTex.getData().data()
);
}
But this does not
try
{
if (it->texture == "")
throw std::invalid_argument("no texture name");
std::string tempPath = path;
while (tempPath.back() != '/' && tempPath.back() != '\\')
tempPath.pop_back();
TextureTGA tempTex(std::string(tempPath + vModels.front()->texture).c_str());
tempData->alpha = tempTex.hasAlpha();
tempData->width = tempTex.getWidth();
tempData->height = tempTex.getHeight();
tempData->data = tempTex.getData().data();
vTextures.push_back(tempData);
glTexImage2D(GL_TEXTURE_2D,
0,
vTextures.front()->alpha ? GL_RGBA : GL_RGB,
vTextures.front()->width,
vTextures.front()->height,
0,
vTextures.front()->alpha ? GL_BGRA : GL_BGR,
GL_UNSIGNED_BYTE,
vTextures.front()->data
);
}
===SOLVED===
Found the problem. The data wasn’t valid outside the try block
Any ideas why?? (in that last case the cube is solid grey) and if i do that after the try/catch block it crashes.