Я пытаюсь внедрить систему сетки для обнаружения столкновений между танками в игре. Танк должен находиться в правой ячейке сетки, сохраненной и обновляемой всякий раз, когда он переходит к другому. vec2 position{ start_blue_x + ((i % max_rows) * spacing), start_blue_y + ((i / max_rows) * spacing) };
Cell* tank_cell = Cell::find_cell_for_tank(position.x, position.y, cells);
Tank tank = Tank(position.x, position.y, BLUE, tank_cell, &tank_blue, &smoke, 1100.f, position.y + 16, tank_radius, tank_max_health, tank_max_speed);
tank_cell->tanks.push_back(&tank);
< /code>
cell.h:
Cell(int column, int row, vector tanks);
< /code>
It seems to happen at the last line where I push the tank in the cell.
Exception thrown: Access violation reading
Cell::find_cell_for_tank()
Cell* Cell::find_cell_for_tank(int pos_x, int pos_y, vector& cells)
{
int tank_col = pos_x / CELL_WIDTH;
int tank_row = pos_y / CELL_HEIGHT;
for (int i = 0; i < cells.size(); i++) {
if ((*cells.at(i)).column == tank_col && (*cells.at(i)).row == tank_row)
{
return cells.at(i);
}
}
Cell* new_cell = &Cell(tank_col, tank_row, {});
cells.push_back(new_cell);
return new_cell;
}
Подробнее здесь: https://stackoverflow.com/questions/756 ... ector-in-c
Не в состоянии добавить указатель на вектор в C ++ ⇐ C++
Программы на C++. Форум разработчиков
-
Anonymous
1755842989
Anonymous
Я пытаюсь внедрить систему сетки для обнаружения столкновений между танками в игре. Танк должен находиться в правой ячейке сетки, сохраненной и обновляемой всякий раз, когда он переходит к другому. vec2 position{ start_blue_x + ((i % max_rows) * spacing), start_blue_y + ((i / max_rows) * spacing) };
Cell* tank_cell = Cell::find_cell_for_tank(position.x, position.y, cells);
Tank tank = Tank(position.x, position.y, BLUE, tank_cell, &tank_blue, &smoke, 1100.f, position.y + 16, tank_radius, tank_max_health, tank_max_speed);
tank_cell->tanks.push_back(&tank);
< /code>
cell.h:
Cell(int column, int row, vector tanks);
< /code>
It seems to happen at the last line where I push the tank in the cell.
Exception thrown: Access violation reading
Cell::find_cell_for_tank()
Cell* Cell::find_cell_for_tank(int pos_x, int pos_y, vector& cells)
{
int tank_col = pos_x / CELL_WIDTH;
int tank_row = pos_y / CELL_HEIGHT;
for (int i = 0; i < cells.size(); i++) {
if ((*cells.at(i)).column == tank_col && (*cells.at(i)).row == tank_row)
{
return cells.at(i);
}
}
Cell* new_cell = &Cell(tank_col, tank_row, {});
cells.push_back(new_cell);
return new_cell;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/75642986/not-able-to-add-pointer-to-a-vector-in-c[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия