2012-04-04 12 views
2

Ich überprüfe meinen Code auf Speicherlecks. Alles ist in Ordnung, bis ich den Code bekam:Valgrind Lecksuche mit segfault

mSystem = new LightSystem(); 
sf::View *view = th::DisplayManager::Get()->GetCamera(); 
mSystem->SetView(*view); 

SetView tut wirklich winzig Job (Auszüge einige Mitglieder der bestandenen view Zeiger Wenn letzte Codezeile wird kommentiert alles ist in Ordnung, aber uncommenting alles funktioniert im Standardmodus und schlägt fehl. in Speicherleckerkennung mit valgrind (valgrind --tool=memcheck ./Binary)

==23703== Use of uninitialised value of size 8 
==23703== at 0x6B8472: ltbl::LightSystem::SetView(sf::View const&) (LightSystem.cpp:55) 
==23703== by 0x6A7A7D: th::LightManager::Initialize() (LightManager.cpp:46) 
==23703== by 0x6A75EA: th::Root::Initialize() (Root.cpp:101) 
==23703== by 0x6A7113: th::Root::Root() (Root.cpp:66) 
==23703== by 0x6A7553: th::Root::Get() (Root.cpp:88) 
==23703== by 0x6291A8: th::Game::Initialize() (Game.cpp:36) 
==23703== by 0x61DC1C: main (main.cpp:82) 
==23703== 
==23703== Invalid read of size 8 
==23703== at 0x6B8472: ltbl::LightSystem::SetView(sf::View const&) (LightSystem.cpp:55) 
==23703== by 0x6A7A7D: th::LightManager::Initialize() (LightManager.cpp:46) 
==23703== by 0x6A75EA: th::Root::Initialize() (Root.cpp:101) 
==23703== by 0x6A7113: th::Root::Root() (Root.cpp:66) 
==23703== by 0x6A7553: th::Root::Get() (Root.cpp:88) 
==23703== by 0x6291A8: th::Game::Initialize() (Game.cpp:36) 
==23703== by 0x61DC1C: main (main.cpp:82) 
==23703== Address 0x8 is not stack'd, malloc'd or (recently) free'd 
==23703== 
==23703== 
==23703== Process terminating with default action of signal 11 (SIGSEGV) 
==23703== Access not within mapped region at address 0x8 
==23703== at 0x6B8472: ltbl::LightSystem::SetView(sf::View const&) (LightSystem.cpp:55) 
==23703== by 0x6A7A7D: th::LightManager::Initialize() (LightManager.cpp:46) 
==23703== by 0x6A75EA: th::Root::Initialize() (Root.cpp:101) 
==23703== by 0x6A7113: th::Root::Root() (Root.cpp:66) 
==23703== by 0x6A7553: th::Root::Get() (Root.cpp:88) 
==23703== by 0x6291A8: th::Game::Initialize() (Game.cpp:36) 
==23703== by 0x61DC1C: main (main.cpp:82) 
==23703== If you believe this happened as a result of a stack 
==23703== overflow in your program's main thread (unlikely but 
==23703== possible), you can try to increase the size of the 
==23703== main thread stack using the --main-stacksize= flag. 
==23703== The main thread stack size used in this run was 8388608. 

Die Fragen sind:. warum tut es funktioniert erfolgreich ohne valgrind und bricht damit ich auch --main-stacksize= einen großen Wert haben versucht zu setzen, aber es hat nicht geholfen. ich.

+3

Es funktioniert wahrscheinlich nicht ohne Valgrind. Es wird undefiniertes Verhalten, weil Sie einen ungültigen Zeiger verwenden, was bedeutet, dass alles passieren kann. –

+0

Vergessen Sie nicht, dass das Problem nicht mit der Zeile 'mSystem-> SetView (* view);' in Zusammenhang stehen muss. Sie könnten jederzeit irgendwo im Speicher beschädigt haben. Valgrind könnte sich gerade ändern, wo die Dinge sind ... – enobayram

Antwort

4
==23703== Process terminating with default action of signal 11 (SIGSEGV) 
==23703== Access not within mapped region at address 0x8 

An einem gewissen Punkt (wahrscheinlich LightSystem.cpp:55) Sie dereferencing ein Zeiger auf die Sie 8 zugeordnet, die nichts über eine gültige Adresse aussieht.

+0

So seltsam, ich habe alle Zeiger überprüft ('view' vorher und nachher) und alles scheint in Ordnung zu sein – Ockonal