在项目中已调用abort()

时间:2019-12-30 16:30:58

标签: c++

我正在尝试将数据从一个对象分配给另一个对象,并让我看到此错误并选择一个例外: C ++项目中0x00007FFDCD79A839的未处理异常。 exe:Microsoft C ++异常:内存位置0x000000DDD04FA560中的std :: length_error。 Field.cpp

PDF::Reader

Board.h

RectangleShape Field::getField() {
    return field;
}

Board.cpp

#pragma once
#include "DEFINIONS.h"
#include "Field.h"

class Board
{
private:
    int length{ 3 };
    int width{ 3 };
    int lengthBoard{ 0 };
    int widthBoard{ 0 };
    int a{ 0 };
    int b{ 0 };
    bool check{ true };
    RectangleShape ramka;
    Field** board;
public:
    Board(int length = 3, int width = 3, int margin_X = 0, int margin_Y = 0);
    void drawMap(RenderWindow& window);
};

GameState.h

 Board::Board(int length, int width, int margin_X, int margin_Y) {
    this->length = length;
    this->width = width;
    ramka.setSize(Vector2f(800, 800));
    ramka.setFillColor(Color::Green);
    ramka.setOrigin(700, 700);
    ramka.setPosition(730, 730);

    board = new Field * [length];
    for (int i = 0; i < length; i++) {
        board[i] = new Field[width];
    }

    for (int i = 0; i < length; i++) {
        *this->board[i] = Field();
        for (int j = 0; j < width; j++) {
            *this->board[j] = Field();
            lengthBoard = length * board[0][0].getSize() + (length - 1) * board[0][0].getOdleglosc();
        }
    }

    while (check) {
        for (int i = 0; i < length; i++) {
            for (int j = 0; j < width; j++) {
                if (lengthBoard > ramka.getSize().x&& lengthBoard > ramka.getSize().y) {
                    a = 0.95 * board[i][j].getSize();
                    b = board[i][j].getOdleglosc();
                    board[i][j].setSize(a);
                    board[i][j].setOdleglosc(b);
                    lengthBoard = length * board[0][j].getSize() + (length - 1) * board[0][j].getOdleglosc();
                }
                else
                {
                    for (int i = 0; i < length; i++) {
                        for (int j = 0; j < width; j++) {
                            if (lengthBoard < ramka.getSize().x && lengthBoard < ramka.getSize().y) {
                                a = 1.05 * board[i][j].getSize();
                                b = board[i][j].getOdleglosc();
                                board[i][j].setSize(a);
                                board[i][j].setOdleglosc(b);
                                lengthBoard = length * board[0][j].getSize() + (length - 1) * board[0][j].getOdleglosc();
                            }
                            else {
                                check = false;
                                break;
                            }
                        }
                    }
                    if (!check)
                        break;
                }
            }
            if (!check)
                break;
        }
    }

    for (int i = 0; i < length; i++)
        for (int j = 0; j < width; j++)
            board[i][j] = Field(i, j, margin_X, margin_Y, a, b);
}

void Board::drawMap(RenderWindow& window) {

//  window.draw(ramka);
    scaleBoard(window);
    for (int i = 0; i < length; i++)
        for (int j = 0; j < width; j++) {
            window.draw(board[i][j].getField());
            std::cout << board[i][j].getSize() << "---" << board[i][j].getOdleglosc() << std::endl;
            std::cout << a << "----------------" << b << std::endl;
        }
}

GameState.cpp

    Board tablica;
    void doIt(RenderWindow& window,int numer);      //metoda pozwalajaca zainicjowac całą tablice
    int game(RenderWindow& window, Event& event, Vector2f mouse, int numer);
};

0 个答案:

没有答案