Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: 2 sf::RectangleShape memory error  (Read 3042 times)

0 Members and 3 Guests are viewing this topic.

kachan1208

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
2 sf::RectangleShape memory error
« on: July 18, 2014, 07:43:11 pm »
whe i create 2 sf::RectangleShape in class header, i have memmory error. When i create sf::RectangleShape* i can`t to draw it. How to create 2 independent rectangles?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

kachan1208

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: 2 sf::RectangleShape memory error
« Reply #2 on: July 18, 2014, 07:59:31 pm »
#ifndef BOARD_H
#define BOARD_H

#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics.hpp>

#define numOfCellsH 4
#define numOfCellsW 4
#define cellHeight 128
#define cellWidth 128
#define margin 10

class board
{
public:
    board(sf::RenderWindow* window);
    ~board();
    void drawCellsBackground();
    void drawBoard();


private:
    sf::RenderWindow* mWindow;

    sf::RectangleShape mBoardBox;
    sf::RectangleShape mCellsBg;
};

gdb output :
Code: [Select]

Error in `/home/kachan/work/build-2048-Debug/2048': malloc(): smallbin double linked list corrupted: 0x00000000007b7180 ***

then i try
#ifndef BOARD_H
#define BOARD_H

#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics.hpp>

#define numOfCellsH 4
#define numOfCellsW 4
#define cellHeight 128
#define cellWidth 128
#define margin 10

class board
{
public:
    board(sf::RenderWindow* window);
    ~board();
    void drawCellsBackground();
    void drawBoard();


private:
    sf::RenderWindow* mWindow;

    sf::RectangleShape mBoardBox;
   // sf::RectangleShape mCellsBg;
};
and it works

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: 2 sf::RectangleShape memory error
« Reply #3 on: July 18, 2014, 08:03:25 pm »
Show the code where you initialize the variables.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

kachan1208

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: 2 sf::RectangleShape memory error
« Reply #4 on: July 18, 2014, 08:04:38 pm »
program down before i init something, because
#include "board.h"

#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/RectangleShape.hpp>

board::board(sf::RenderWindow *window)
{
    mWindow = window;

//    mBoardBox = new sf::RectangleShape;
    mBoardBox.setSize(sf::Vector2f(((numOfCellsW+1) * margin) + (cellWidth * numOfCellsW),
                                   ((numOfCellsH+1) * margin) + (cellHeight * numOfCellsH)));
    mBoardBox.setPosition(19, 160);
    mBoardBox.setFillColor(sf::Color(187, 173, 160, 255));

//    mCellsBg = new sf::RectangleShape;
//    mCellsBg.setSize(sf::Vector2f(cellWidth, cellHeight));
//    mCellsBg.setFillColor(sf::Color(205, 192, 180, 255));
}

board::~board()
{
}




void board::drawCellsBackground()
{

}

void board::drawBoard()
{
    mWindow->draw(mBoardBox);
//    mWindow->draw(mCellsBg);
}
 

kachan1208

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: 2 sf::RectangleShape memory error
« Reply #6 on: July 18, 2014, 08:38:13 pm »
Please read the link posted by zsbzsb carefully... and then adjust your problem description.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

kachan1208

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: 2 sf::RectangleShape memory error
« Reply #7 on: July 18, 2014, 09:35:15 pm »
this is problem only with my knowledge of C++, thats all. i fix it.

 

anything