diff options
| -rw-r--r-- | ext/ruby2d/ruby2d.c | 9 | ||||
| -rw-r--r-- | test/window_spec.rb | 4 |
2 files changed, 11 insertions, 2 deletions
diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c index 300c8e0..7c17bac 100644 --- a/ext/ruby2d/ruby2d.c +++ b/ext/ruby2d/ruby2d.c @@ -176,8 +176,13 @@ static R_VAL ruby2d_ext_screenshot(mrb_state* mrb, R_VAL self) { #else static R_VAL ruby2d_ext_screenshot(R_VAL self, R_VAL path) { #endif - S2D_Screenshot(window, RSTRING_PTR(path)); - return R_NIL; + if (window) { + S2D_Screenshot(window, RSTRING_PTR(path)); + return path; + } else { + S2D_Log(S2D_WARN, "Cannot take screenshot before window is shown"); + return R_FALSE; + } } diff --git a/test/window_spec.rb b/test/window_spec.rb index 7be4e2b..7aac7aa 100644 --- a/test/window_spec.rb +++ b/test/window_spec.rb @@ -9,4 +9,8 @@ RSpec.describe Ruby2D::Window do expect(Window.width).to eq(200) end + it "does not allow screenshots until shown" do + expect(Window.screenshot).to be false + end + end |
