Hallo,
ich habe ein Problem mit dem ContactListener in Box2d.
Sobald ich eine Kollision herbeirufe kriege ich einen Zugriffsverletzungsfehler.
Ich wundere mich da ich eigentlich nicht viel am Contactlistener bearbeitet habe.
die HPP:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#pragma once
#include "Box2D\Box2D.h"
class CContactListener : public b2ContactListener
{
public:
CContactListener() {};
~CContactListener() {};
void BeginContact(b2Contact* contact) ;
void EndContact(b2Contact* contact);
};
|
Die CPP:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
|
#include "ContactListener.hpp"
void CContactListener::BeginContact(b2Contact * contact)
{
printf("Kollision");
}
void CContactListener::EndContact(b2Contact * contact)
{
}
|
EDIT:
So übergebe ich den Contactlistener an Box2d:
|
C-/C++-Quelltext
|
1
2
3
|
World = new b2World(b2Vec2(0.f, 0.f));
CContactListener ContactListener;
World->SetContactListener(&ContactListener);
|
Der Fehler:
Ausgelöste Ausnahme: Lesezugriffsverletzung
'listener->' war '0xCCCCCCCC'.
Falls ein Handler für diese Ausnahme vorhanden ist, kann das Programm möglicherweise weiterhin sicher ausgeführt werden.
in der b2Contact.cpp:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
// Update the contact manifold and touching status.
// Note: do not assume the fixture AABBs are overlapping or are valid.
void b2Contact::Update(b2ContactListener* listener)
{
//...
if (wasTouching == false && touching == true && listener)
{
listener->BeginContact(this); // Hier soll der Fehler sein!
}
//...
}
|
Der Listener ist ja mein übergebenes Objekt... ich versteh nicht gnaz was ich falsch mache...
mit freundlichen Grüßen
Urprimat