From 50b36b6a8aaf9512a4699734c160fcd82c0c2ea6 Mon Sep 17 00:00:00 2001 From: Andrew Havens Date: Fri, 29 Dec 2017 09:26:26 -0800 Subject: Check for valid file path to prevent segfault when file does not exist. --- lib/ruby2d/sprite.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/ruby2d/sprite.rb b/lib/ruby2d/sprite.rb index e6a6efa..7c66f97 100644 --- a/lib/ruby2d/sprite.rb +++ b/lib/ruby2d/sprite.rb @@ -8,9 +8,11 @@ module Ruby2D def initialize(x, y, path, z=0) - # unless File.exists? path - # raise Error, "Cannot find image file `#{path}`" - # end + unless RUBY_ENGINE == 'opal' + unless File.exists? path + raise Error, "Cannot find sprite image file `#{path}`" + end + end @x, @y, @path = x, y, path @clip_x, @clip_y, @clip_w, @clip_h = 0, 0, 0, 0 -- cgit v1.2.3