TinyEngine
TinyEngine copied to clipboard
Keep getting segmentation error
Hey, I'm trying to use TinyEngine for a project because it looks really cool and useful, but I keep getting segmentation errors in when running the examples. Am I doing something wrong? Reading through the code it all seems like it should work.
I'm on MacOS.
For example, with the Heightmap example, I get a EXC_BAD_ACCESS (code=1, address=0x0) error due to this line:
mesh.bind<glm::vec3>("in_Position", &positions); //Bind Buffer to Property
Another example, when initiating a cube, I get pointed to the same error in the model helper. There seems to be something wrong in this line in void bind:
glBindVertexBuffer(bindings[binding], buf->index, 0, sizeof(T));
Do you know why this could be? Am I doing something wrong?
Just to clarify: The example has not been modified in any way? And: Simply declaring a cube leads to the segmentation fault?
Are there any compiler warnings? Are you using the provided makefile or have you altered the build?
I'm just asking for troubleshooting reasons.
Very interesting because it compiles fine on ubuntu... it'll have to be something platform specific. I'm afraid I currently don't have access to a MacOS computer, otherwise I would try and replicate this. If you want to try and resolve the issue you can confirm / try a few things:
- In the function
constructthe buffer is actually filled! i.e buffer.SIZE is larger zero and index is not zero. - Try removing the template arguments from
buffer.fill<T>, at the very end of theconstructfunction (maybe an alignment issue??). The template arguments are not strictly necessary since the vector is packed memory.
If making a cube crashes too, then perhaps the buffers indices are not defined for some reason, i.e. glGenBuffers fails.
The other alternative is that there is a driver issue and OpenGL fails to make a valid context for some reason, or does some other weird stuff... have you tried compiling with compatibility mode perhaps?
Very weird issue, thanks for bringing it up.
Also: when you launch the program, does TinyEngine output a small message to the console describing your OpenGL context profile? Something like 4.6 (Core Profile) Mesa 20.2.6?
Thanks for your quick reply!
It took a while to setup everything (linking was a bit of a pain, especially with SDL2, my system kept not finding it, very weird). I did that with CMake (I'm more familiar with that than with Make). But this was working fine, the white window example works fine etc., so I was pretty confident that everything was setup fine. CMake at least did not output any errors anymore.
But when just running the example with make, I also get a seg error..
I didn't change the source files or the shaders, only running it from my CMake setup in stead of from the Makefile, but I checked that everything would be the same (compiler and c++ standard and such)
Yep, when just declaring a cube I get a seg fault. Super weird!
I'll try changing the construct function in the example.
When I launch the program I get this 4.1 ATI-4.7.101. Maybe I should try with Mesa? Every time the error does lead somewhere to OpenGL related things so that might be the thing. I'll try to set Mesa up and see how that goes!
Thanks again for replying so fast!!
No problem.
I see, CMake shouldn't make a difference. It must be a driver issue, this is more difficult to debug.
Try the following: This is dumb on my part, and I will fix it, but go into the file view.cpp and check if gContext is NULL like so:
gContext = SDL_GL_CreateContext(gWindow);
if( gContext == NULL ){
printf( "Context could not be created! SDL_Error: %s\n", SDL_GetError() );
return false;
}
If this throws it should give us some more information. If it doesn't, we have not identified the issue. Then I would try using other drivers perhaps.
I changed it and rebuilt it but it didn't throw it...
The error keeps coming back in this block.. and then specifically the glBindVertexBuffer(...) line. Super weird.
void bind(std::string binding, Buffer* buf, bool owned = false){ //Bind a specific buffer to a binding point
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, buf->index);
glBindVertexBuffer(bindings[binding], buf->index, 0, sizeof(T));
glVertexAttribFormat(bindings[binding], sizeof(T)/sizeof(GL_FLOAT), GL_FLOAT, GL_FALSE, 0);
if(owned) buffers[binding] = buf;
}
I'll see if I can change my drivers but I'm not sure because MacOS and changing things is sometimes a pain... can't even link the project to Mesa atm..
Thanks for your help!
@weigert wen du eine osx maschiene zum debugen benötigst lass es mich wissen, ich stell dir gerne meinen test mac mini (per teamviewer) zum debugen zur verfügung.
Hi, I am also getting segfaults on all examples except 0 and 01. Also on macOS. Not sure how to try to begin working around it but very interested in any potential fix and happy to help if you can tell me what to do.
#36