[C++][SFML] 0xC0000005 w std::ostream::flush
Ostatnio zmodyfikowano 2018-05-13 14:03
sppmacd Temat założony przez niniejszego użytkownika |
[C++][SFML] 0xC0000005 w std::ostream::flush » 2018-05-05 13:42:37 Witam, mam problem przy pisaniu programu używającego SFML'a. Przy zamykaniu okna pojawia się błąd 0xC0000005. Debugger pokazuje, że błąd występuje w funkcji std::ofstream::flush(): #0 0x547488 std::ostream::flush() () (??:??) #1 0x587e4a std::ios_base::Init::~Init() () (??:??) #2 0x7ffdb574a0fb msvcrt!_initterm_e() (C:\WINDOWS\System32\msvcrt.dll:??) #3 0x4014d5 __tmainCRTStartup () (??:??) #4 0x40152b mainCRTStartup () (??:??)
Kod: #include <SFML/Graphics.hpp>
#include "World/World.hpp" #include "Util/Random.hpp" #include "Game.hpp"
#include <iostream> #include "Render/RenderWorld.hpp" #include "Render/RenderPlayer.hpp" #include "Game.hpp"
using namespace sf;
int main() { sf::RenderWindow wnd( sf::VideoMode( 15 * 50, 15 * 50, 32 ), "Laser Miner v1.0", Style::Close | Style::Titlebar ); wnd.setFramerateLimit( 60 ); sf::Event event; Random random( time( NULL ) ); Game game; game.loadTextures(); game.generateWorld(); game.createPlayer(); int moveCooldown = 0; while( wnd.isOpen() ) { while( wnd.pollEvent( event ) ) { if( event.type == sf::Event::Closed ) { wnd.close(); } if( event.type == sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Left ) { int x = event.mouseButton.x; int y = event.mouseButton.y; game.destroyBlock(( x / 50 ) +( int ) game.getWorld()->player.getPosition().x - 7,( y / 50 ) +( int ) game.getWorld()->player.getPosition().y - 7 ); } } if( Keyboard::isKeyPressed( Keyboard::W ) && moveCooldown == 0 ) { game.getWorld()->player.move( Vector2i( 0, - 1 ), game.getWorld() ); moveCooldown = 10; } if( Keyboard::isKeyPressed( Keyboard::S ) && moveCooldown == 0 ) { game.getWorld()->player.move( Vector2i( 0, 1 ), game.getWorld() ); moveCooldown = 10; } if( Keyboard::isKeyPressed( Keyboard::D ) && moveCooldown == 0 ) { game.getWorld()->player.move( Vector2i( 1, 0 ), game.getWorld() ); moveCooldown = 10; } if( Keyboard::isKeyPressed( Keyboard::A ) && moveCooldown == 0 ) { game.getWorld()->player.move( Vector2i( - 1, 0 ), game.getWorld() ); moveCooldown = 10; } if( moveCooldown > 0 ) moveCooldown--; game.getWorld()->update(); game.render( wnd ); } return 0; }
To nie jest pełny kod, ponieważ jest zbyt długi aby go tu umieścić. Tutaj można zobaczyć pełny kod, włącznie z teksturami i skompilowanymi plikami: https://drive.google.com/open?id=1-3mP6LG_R2wW-HPRzLTTbL_gIJ3LSh25 |
|
pekfos |
» 2018-05-05 13:59:10 Game::~Game() { delete this->getWorld(); } |
To nie zostało dynamicznie zaalokowane, więc nie możesz tego tak usunąć. |
|
sppmacd Temat założony przez niniejszego użytkownika |
» 2018-05-05 14:00:53 To już naprawiłem, ale cały czas pojawia się błąd tam gdzie mówiłem. |
|
pekfos |
» 2018-05-05 14:03:37 Jakbym dostawał złotówkę za każdym razem, gdy ktoś coś 'naprawił'.. Player::Player( const Player & player ) { for( int i = 0; i < Blocks::Count; i++ ) this->blocks[ i ] = player.blocks[ i ]; this->pos = player.pos; std::cout << "Copying player..." << std::endl; } |
Ten konstruktor nie alokuje blocks. |
|
sppmacd Temat założony przez niniejszego użytkownika |
COUT » 2018-05-12 16:31:35 Na trybie Debug zadziałało po usunięciu wszystkich wywołań cout . #0 0x7ffaa421875b ntdll!RtlIsNonEmptyDirectoryReparsePointAllowed() (C:\WINDOWS\SYSTEM32\ntdll.dll:??) #1 0x7ffaa421fcda ntdll!RtlpNtMakeTemporaryKey() (C:\WINDOWS\SYSTEM32\ntdll.dll:??) #2 0x7ffaa41bfe42 ntdll!RtlSetProxiedProcessId() (C:\WINDOWS\SYSTEM32\ntdll.dll:??) #3 0x7ffaa421fc03 ntdll!RtlpNtMakeTemporaryKey() (C:\WINDOWS\SYSTEM32\ntdll.dll:??) #4 0x7ffaa414ee11 ntdll!RtlAcquireSRWLockExclusive() (C:\WINDOWS\SYSTEM32\ntdll.dll:??) #5 0x7ffaa4146b39 ntdll!RtlFreeHeap() (C:\WINDOWS\SYSTEM32\ntdll.dll:??) #6 0x7ffaa1f0984c msvcrt!free() (C:\WINDOWS\System32\msvcrt.dll:??) #7 0x7ffaa1f2a0fb msvcrt!_initterm_e() (C:\WINDOWS\System32\msvcrt.dll:??) #8 0x4014d5 __tmainCRTStartup () (??:??) #9 0x40152b mainCRTStartup () (??:??)
Po Rebuild błąd pojawia się tam gdzie wcześniej (tylko na Release, na Debug działa). EDIT: Dodałem alokację blocks . Po dodaniu dealokacji pojawiają się przypadkowe wartości blocks . Player::Player( const Player & player ) { this->blocks = new unsigned int[ Blocks::Count ]; for( int i = 0; i < Blocks::Count; i++ ) this->blocks[ i ] = player.blocks[ i ]; this->pos = player.pos; }
Player::~Player() { }
|
|
pekfos |
» 2018-05-12 16:48:42 Player::Player( Vector2i p ) { this->pos = p; } |
Znowu to samo co wcześniej. |
|
sppmacd Temat założony przez niniejszego użytkownika |
» 2018-05-13 14:03:13 Na trybie Debug: działa Na trybie Release: działa Zrobiłem coś takiego: Player::Player( Vector2i p ) { this->pos = p; this->blocks = new unsigned int[ Blocks::Count ]; for( int i = 0; i < Blocks::Count; i++ ) this->blocks[ i ] = 0; }
Dziękuję za pomoc. Zamykam temat. |
|
« 1 » |