diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp index 0f24640..fbb1d81 100644 --- a/binding-mri/binding-mri.cpp +++ b/binding-mri/binding-mri.cpp @@ -594,3 +594,4 @@ static void mriBindingTerminate(){ static void mriBindingReset(){ rb_raise(getRbData()->exc[Reset], " "); } + diff --git a/binding-mri/filesystem-binding.cpp b/binding-mri/filesystem-binding.cpp index 6dcc7a2..41d6d93 100644 --- a/binding-mri/filesystem-binding.cpp +++ b/binding-mri/filesystem-binding.cpp @@ -30,10 +30,11 @@ #include static void fileIntFreeInstance(void *inst){ - SDL_IOStream *ops = static_cast(inst); - SDL_CloseIO(ops); + SDL_IOStream *ops = static_cast(inst); + if (ops) { + SDL_CloseIO(ops); + } } - DEF_TYPE_CUSTOMFREE(FileInt, fileIntFreeInstance); static VALUE fileIntForPath(const char *path, bool rubyExc){ @@ -91,14 +92,15 @@ RB_METHOD(fileIntRead){ } RB_METHOD(fileIntClose){ - RB_UNUSED_PARAM; - SDL_IOStream *ops = getPrivateData(self); + RB_UNUSED_PARAM; + SDL_IOStream *ops = getPrivateData(self); if (!ops){ printf("NULL guard! fileIntClose broken!"); return Qnil; } - SDL_CloseIO(ops); - return Qnil; + SDL_CloseIO(ops); + setPrivateData(self, nullptr); + return Qnil; } RB_METHOD(fileIntGetByte){