libretro / Craft

A simple Minecraft clone written in C using modern OpenGL (shaders).
http://www.michaelfogleman.com/craft/
MIT License
45 stars 19 forks source link

Fix divide by zero errors [$20] #13

Open inactive123 opened 7 years ago

inactive123 commented 7 years ago

These manifest themselves primarily on ARM-based systems but they can also manifest on other systems, and they are what is currently preventing the core from working at all on iOS and Android.

Related to issues like this -

https://github.com/libretro/Craft/issues/7

A working proof of concept for this would be if by fixing these issues, the core would then work on either iOS or Android. Either one of the two would be good enough to start with.

--- There is a **[$20 open bounty](https://www.bountysource.com/issues/43654252-fix-divide-by-zero-errors?utm_campaign=plugin&utm_content=tracker%2F32425093&utm_medium=issues&utm_source=github)** on this issue. Add to the bounty at [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F32425093&utm_medium=issues&utm_source=github).
inactive123 commented 7 years ago

@bparker06 Did your PR here (https://github.com/libretro/Craft/pull/14) also take care of these issues? There is still a bounty open for this, would be nice to see this finally resolved so it could work on Android/iOS.

ghost commented 6 years ago

I just tried the AArch64 build of RA Android and it still crashes there, but probably because of the memcpy referenced in #14 and not a divide by zero.

jet082 commented 5 years ago

I have dug into this with a debugger. The issue appears to be with the skybox loading in renderer_load_shader. It seems to be passed bad data for the shader that does not compile properly.

The error appears to be coming from these lines:

static void renderer_load_shader(craft_info_t *info, size_t len, size_t len2,
      const char **string, const char **string2)
{
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
   GLuint vert, frag;

   info->program               = glCreateProgram();
   vert                 = glCreateShader(GL_VERTEX_SHADER);
   frag                 = glCreateShader(GL_FRAGMENT_SHADER);

   glShaderSource(vert, (GLsizei)len,  (const GLchar**)string, 0);
   glShaderSource(frag, (GLsizei)len2, (const GLchar**)string2, 0);
   glCompileShader(vert);
   glCompileShader(frag);

   glAttachShader(info->program, vert);
   glAttachShader(info->program, frag);
   glLinkProgram(info->program);
   glDeleteShader(vert);
   glDeleteShader(frag);
#endif
}