summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-03-13 12:29:18 -0500
committersanine <sanine.not@pm.me>2023-03-13 12:29:18 -0500
commit184a9517a619c0052aabd8ad6ab00ed0d2607e97 (patch)
treeae0bbc82be387255215e5f1cdc85fe5a2ca1fdff /src
parentcc7dfef17ffaa41a675364fb5f0561a13d6b0dba (diff)
fix null pointer errors
Diffstat (limited to 'src')
-rw-r--r--src/glfw/setup.h4
-rw-r--r--src/glfw/window.c8
-rw-r--r--src/import/import.c4
3 files changed, 15 insertions, 1 deletions
diff --git a/src/glfw/setup.h b/src/glfw/setup.h
index b867627..3e5b482 100644
--- a/src/glfw/setup.h
+++ b/src/glfw/setup.h
@@ -416,6 +416,10 @@ H_GLFW_FUNCTIONS
X("PLATFORM_ERROR", GLFW_PLATFORM_ERROR) \
X("FORMAT_UNAVAILABLE", GLFW_FORMAT_UNAVAILABLE) \
X("NO_WINDOW_CONTEXT", GLFW_NO_WINDOW_CONTEXT) \
+ X("PRESS", GLFW_PRESS) \
+ X("RELEASE", GLFW_RELEASE) \
+ X("REPEAT", GLFW_REPEAT) \
+
#endif
diff --git a/src/glfw/window.c b/src/glfw/window.c
index 0199fb0..5922dde 100644
--- a/src/glfw/window.c
+++ b/src/glfw/window.c
@@ -88,6 +88,12 @@ int glfwCreateWindow_bind(lua_State *L)
GLFWwindow ** window = create_window(L);
*window = glfwCreateWindow(width, height, title, *monitor, *share);
+ if (*window == NULL) {
+ int code;
+ const char *err;
+ code = glfwGetError(&err);
+ return luaL_error(L, "failed to create window: %s [code %d]", err, code);
+ }
configure_window(window);
return 1;
}
@@ -113,7 +119,7 @@ int glfwWindowShouldClose_bind(lua_State *L)
int glfwSetWindowShouldClose_bind(lua_State *L)
{
GLFWwindow ** window = luaL_checkudata(L, 1, glfw_window_tname);
- int value = luaL_checkinteger(L, 2);
+ int value = lua_toboolean(L, 2);
glfwSetWindowShouldClose(*window, value);
return 0;
}
diff --git a/src/import/import.c b/src/import/import.c
index e2fc250..66bd541 100644
--- a/src/import/import.c
+++ b/src/import/import.c
@@ -9,7 +9,11 @@
void read_file(void *ctx, const char *filename, int is_mtl, const char *obj_filename, char **buf, size_t *len)
{
+ lua_State *L = ctx;
FILE *f = fopen(filename, "rb");
+ if (f == NULL) {
+ luaL_error(L, "failed to open file \"%s\"", filename);
+ }
fseek(f, 0, SEEK_END);
*len = ftell(f);
fseek(f, 0, SEEK_SET);