diff options
| author | Tom Black <[email protected]> | 2019-01-06 02:05:39 -0800 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2019-01-06 02:05:39 -0800 |
| commit | 742bb574dc506fbb7a8d1774c44736ad0e228c54 (patch) | |
| tree | 89b4575810ad09695dfb8aeba8319ddadcb2eb08 /lib | |
| parent | 19fe64de6fec783e32a2257ff04862b2d0a41572 (diff) | |
| download | ruby2d-742bb574dc506fbb7a8d1774c44736ad0e228c54.tar.gz ruby2d-742bb574dc506fbb7a8d1774c44736ad0e228c54.zip | |
Raise errors if media can't be read
Check if NULL pointers are returned by native functions loading media for images, sprites, audio, etc. If NULL, raise Ruby 2D error.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ruby2d/image.rb | 4 | ||||
| -rw-r--r-- | lib/ruby2d/music.rb | 4 | ||||
| -rw-r--r-- | lib/ruby2d/sound.rb | 4 | ||||
| -rw-r--r-- | lib/ruby2d/sprite.rb | 4 | ||||
| -rw-r--r-- | lib/ruby2d/text.rb | 4 |
5 files changed, 15 insertions, 5 deletions
diff --git a/lib/ruby2d/image.rb b/lib/ruby2d/image.rb index 1341f89..67ce1b1 100644 --- a/lib/ruby2d/image.rb +++ b/lib/ruby2d/image.rb @@ -20,7 +20,9 @@ module Ruby2D @rotate = opts[:rotate] || 0 self.color = opts[:color] || 'white' self.opacity = opts[:opacity] if opts[:opacity] - ext_init(@path) + unless ext_init(@path) + raise Error, "Image `#{@path}` cannot be created" + end add end diff --git a/lib/ruby2d/music.rb b/lib/ruby2d/music.rb index ef8deb5..46aab0a 100644 --- a/lib/ruby2d/music.rb +++ b/lib/ruby2d/music.rb @@ -12,7 +12,9 @@ module Ruby2D end @path = path @loop = false - ext_init(path) + unless ext_init(@path) + raise Error, "Music `#{@path}` cannot be created" + end end # Play the music diff --git a/lib/ruby2d/sound.rb b/lib/ruby2d/sound.rb index 2c78525..2dae996 100644 --- a/lib/ruby2d/sound.rb +++ b/lib/ruby2d/sound.rb @@ -11,7 +11,9 @@ module Ruby2D raise Error, "Cannot find audio file `#{path}`" end @path = path - ext_init(path) + unless ext_init(@path) + raise Error, "Sound `#{@path}` cannot be created" + end end # Play the sound diff --git a/lib/ruby2d/sprite.rb b/lib/ruby2d/sprite.rb index 94a6ea2..8405e5f 100644 --- a/lib/ruby2d/sprite.rb +++ b/lib/ruby2d/sprite.rb @@ -45,7 +45,9 @@ module Ruby2D @img_width = nil; @img_height = nil # Initialize the sprite - ext_init(@path) + unless ext_init(@path) + raise Error, "Sprite image `#{@path}` cannot be created" + end # The clipping rectangle @clip_x = opts[:clip_x] || 0 diff --git a/lib/ruby2d/text.rb b/lib/ruby2d/text.rb index a526672..d62bc0b 100644 --- a/lib/ruby2d/text.rb +++ b/lib/ruby2d/text.rb @@ -20,7 +20,9 @@ module Ruby2D unless File.exist? @font raise Error, "Cannot find font file `#{@font}`" end - ext_init + unless ext_init + raise Error, "Text `#{@text}` cannot be created" + end add end |
