summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ext/ruby2d/ruby2d.c30
-rw-r--r--lib/ruby2d/image.rb4
-rw-r--r--lib/ruby2d/music.rb4
-rw-r--r--lib/ruby2d/sound.rb4
-rw-r--r--lib/ruby2d/sprite.rb4
-rw-r--r--lib/ruby2d/text.rb4
6 files changed, 27 insertions, 23 deletions
diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c
index 7970c56..b6388ac 100644
--- a/ext/ruby2d/ruby2d.c
+++ b/ext/ruby2d/ruby2d.c
@@ -333,8 +333,8 @@ static R_VAL ruby2d_image_ext_init(mrb_state* mrb, R_VAL self) {
#else
static R_VAL ruby2d_image_ext_init(R_VAL self, R_VAL path) {
#endif
- S2D_Log(S2D_INFO, "Init image: %s", RSTRING_PTR(path));
S2D_Image *img = S2D_CreateImage(RSTRING_PTR(path));
+ if (!img) return R_FALSE;
// Get width and height from Ruby class. If set, use it, else choose the
// native dimensions of the image.
@@ -342,9 +342,9 @@ static R_VAL ruby2d_image_ext_init(R_VAL self, R_VAL path) {
R_VAL h = r_iv_get(self, "@height");
r_iv_set(self, "@width" , r_test(w) ? w : INT2NUM(img->width));
r_iv_set(self, "@height", r_test(h) ? h : INT2NUM(img->height));
-
r_iv_set(self, "@data", r_data_wrap_struct(image, img));
- return R_NIL;
+
+ return R_TRUE;
}
@@ -390,7 +390,6 @@ static void free_image(mrb_state *mrb, void *p_) {
#else
static void free_image(S2D_Image *img) {
#endif
- S2D_Log(S2D_INFO, "Free image `%s` at %i, %i", img->path, img->x, img->y);
S2D_FreeImage(img);
}
@@ -406,14 +405,14 @@ static R_VAL ruby2d_sprite_ext_init(mrb_state* mrb, R_VAL self) {
#else
static R_VAL ruby2d_sprite_ext_init(R_VAL self, R_VAL path) {
#endif
- S2D_Log(S2D_INFO, "Init sprite: %s", RSTRING_PTR(path));
S2D_Sprite *spr = S2D_CreateSprite(RSTRING_PTR(path));
+ if (!spr) return R_FALSE;
r_iv_set(self, "@img_width" , INT2NUM(spr->width));
r_iv_set(self, "@img_height", INT2NUM(spr->height));
r_iv_set(self, "@data", r_data_wrap_struct(sprite, spr));
- return R_NIL;
+ return R_TRUE;
}
@@ -470,7 +469,6 @@ static void free_sprite(mrb_state *mrb, void *p_) {
#else
static void free_sprite(S2D_Sprite *spr) {
#endif
- S2D_Log(S2D_INFO, "Free sprite `%s` at %i, %i", spr->path, spr->x, spr->y);
S2D_FreeSprite(spr);
}
@@ -484,8 +482,6 @@ static R_VAL ruby2d_text_ext_init(mrb_state* mrb, R_VAL self) {
#else
static R_VAL ruby2d_text_ext_init(R_VAL self) {
#endif
- S2D_Log(S2D_INFO, "Init text: %s", RSTRING_PTR(r_iv_get(self, "@text")));
-
// Trim the font file string to its actual length on MRuby
#if MRUBY
mrb_value s = r_iv_get(self, "@font");
@@ -497,12 +493,13 @@ static R_VAL ruby2d_text_ext_init(R_VAL self) {
RSTRING_PTR(r_iv_get(self, "@text")),
NUM2DBL(r_iv_get(self, "@size"))
);
+ if (!txt) return R_FALSE;
r_iv_set(self, "@width", INT2NUM(txt->width));
r_iv_set(self, "@height", INT2NUM(txt->height));
-
r_iv_set(self, "@data", r_data_wrap_struct(text, txt));
- return R_NIL;
+
+ return R_TRUE;
}
@@ -565,7 +562,6 @@ static void free_text(mrb_state *mrb, void *p_) {
#else
static void free_text(S2D_Text *txt) {
#endif
- S2D_Log(S2D_INFO, "Free text \"%s\" with font `%s`", txt->msg, txt->font);
S2D_FreeText(txt);
}
@@ -581,10 +577,10 @@ static R_VAL ruby2d_sound_ext_init(mrb_state* mrb, R_VAL self) {
#else
static R_VAL ruby2d_sound_ext_init(R_VAL self, R_VAL path) {
#endif
- S2D_Log(S2D_INFO, "Init sound: %s", RSTRING_PTR(path));
S2D_Sound *snd = S2D_CreateSound(RSTRING_PTR(path));
+ if (!snd) return R_FALSE;
r_iv_set(self, "@data", r_data_wrap_struct(sound, snd));
- return R_NIL;
+ return R_TRUE;
}
@@ -612,7 +608,6 @@ static void free_sound(mrb_state *mrb, void *p_) {
#else
static void free_sound(S2D_Sound *snd) {
#endif
- S2D_Log(S2D_INFO, "Free sound `%s`", snd->path);
S2D_FreeSound(snd);
}
@@ -628,10 +623,10 @@ static R_VAL ruby2d_music_ext_init(mrb_state* mrb, R_VAL self) {
#else
static R_VAL ruby2d_music_ext_init(R_VAL self, R_VAL path) {
#endif
- S2D_Log(S2D_INFO, "Init music: %s", RSTRING_PTR(path));
S2D_Music *mus = S2D_CreateMusic(RSTRING_PTR(path));
+ if (!mus) return R_FALSE;
r_iv_set(self, "@data", r_data_wrap_struct(music, mus));
- return R_NIL;
+ return R_TRUE;
}
@@ -740,7 +735,6 @@ static void free_music(mrb_state *mrb, void *p_) {
#else
static void free_music(S2D_Music *mus) {
#endif
- S2D_Log(S2D_INFO, "Free music `%s`", mus->path);
S2D_FreeMusic(mus);
}
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