Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / PGM (Pokemon Game Maker Project) - Error when using rect
- - By Fulgurance Date 2023-09-14 16:51
Hi, I am using ruby with Gosu to make a remake of the first version of Pokemon.
I have a class called Sprite inherite directly from Gosu::Image, but I don't know why, when my script load the third sprite, I have a very unusual error.

Sprite class:

class Sprite < Gosu::Image

    attr_accessor :x
    attr_accessor :y
    attr_accessor :z
    attr_accessor :zoomX
    attr_accessor :zoomY
    attr_accessor :color
    attr_accessor :mode

    def initialize(source, options = {})
        super(source,options)
        @x = 0
        @y = 0
        @z = 0
        @zoomX = 1.0
        @zoomY = 1.0
        @color = 0xff_ffffff
        @mode = :default
    end

    def draw
        super(@x,@y,@z,@zoomX,@zoomY,@color,@mode)
    end

end


The code who generate the bug:

class GameMessageScene < GameScene

    def initialize(text,skinNumber)
        super()

        #GLOBAL SETTINGS
        @color = Color.new(180,255,255,255)
        @path = "Graphics/Messages/#{skinNumber}.png"
        @space = 5

        #CORNERS
        @backgroundTopLeft = Sprite.new(@path,{rect: [0,0,16,16]})
        @backgroundTopLeft.color = @color
        @backgroundTopLeft.x = @space
        @backgroundTopLeft.y = $gameWindow.height - 64 / 2 - @space

        @backgroundTopRight = Sprite.new(@path,{rect: [32,0,16,16]})
        @backgroundTopRight.color = @color
        @backgroundTopRight.x = $gameWindow.width - 16 - @space
        @backgroundTopRight.y = @backgroundTopLeft.y

        #THE NEXT LINE WILL BUG
        @backgroundBottomLeft = Sprite.new(@path,{rect: [0,32,16,16]})
        @backgroundBottomLeft.color = @color
        @backgroundBottomLeft.x = @space
        @backgroundBottomLeft.y = $gameWindow.height - 16 - @space


The error (the game freeze few second and then crash, with this error then):

zohran@alienware-m17-r3 ~/Documents/Programmation/PGM $ ruby Game.rb
/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_vector.h:1144: std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = Gosu::Color; _Alloc = std::allocator<Gosu::Color>; const_reference = const Gosu::Color&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.
Aborted
Parent - By jlnr (dev) Date 2024-07-12 13:57
Oops, looks like I had unsubscribed from this board by accident. Welp, I can only assume that the image does not contain the rect that you've tried to load from it.
Up Topic Gosu / Gosu Exchange / PGM (Pokemon Game Maker Project) - Error when using rect

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill