I am trying to retrieve a stack trace in my program, and store it for later use (debugging purposes). But the call to boost::stacktrace::frame::name() never returns, and I have no clue why. When I use this exact code in a simple project, it runs nicely. Any ideas?
boost::stacktrace::stacktrace stacktrace;
stringstream stacktraceText;
for (const auto& entry : stacktrace)
{
if (entry.empty() == false)
{
auto name = entry.name();
stacktraceText << name << "\n";
}
else
{
stacktraceText += L"<missing symbol info>\n";
}
}
Related
I wanna get all the local variables in a function.
void getLocalVariables(Function &F) {
ValueSymbolTable *vst = F.getValueSymbolTable();
for (auto vs : vst) { // here it says: This scope-based "for" statement required the appropriate "begin" function, but was not found
auto s = vs.getKey();
auto v = vs.getValue();
}
}
The error is that: This scope-based "for" statement required the appropriate "begin" function, but was not found. So how can I correct my code? Tks.
I check the documentation for ValueSymbolTable, and finally find how to use it. But actually, as arnt said, they are not local variables in source code. They are temporary variables generated by IR.
void getLocalVariables(Function &F) {
// not test yet
ValueSymbolTable *vst = F.getValueSymbolTable();
errs() << (*vst).size() << "\n.";
for (ValueSymbolTable::iterator VI = vst->begin(), VE = vst->end(); VI != VE; ++VI) {
Value *V = VI->getValue();
if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasLocalLinkage()) {
if (!V->getName().startswith("llvm.dbg"))
// Set name to "", removing from symbol table!
V->setName("");
}
}
}
I have the following code, and can be compiled, but when I run it, it fails with error of missing resource.
I have checked the cascade installer and everything is clicked and installed. How could I fix this?
#include <TDocStd_Application.hxx>
#include <TDataStd_Integer.hxx>
int main()
{
Handle(TDocStd_Application) app = new TDocStd_Application;
Handle(TDocStd_Document) doc;
app->NewDocument("BinOcaf", doc);
if (doc.IsNull())
{
std::cout << "Error: cannot create an OCAF document." << std::endl;
return 1;
}
// to access the main label, the transient data framework
TDF_Label mainLab = doc->Main();
// attach some integer value to this label
TDataStd_Integer::Set(mainLab, 1002);
// save document to file
PCDM_StoreStatus sstatus = app->SaveAs(doc, "C:/Users/Administrator/Desktop/test.cbf");
if (sstatus != PCDM_SS_OK)
{
app->Close(doc);
std::cout << "cannot write OCAF document." << std::endl;
return 1;
}
// release the data of doc
app->Close(doc);
return 0;
}
Ok, so after some head scratching I realized one thing. Forgot to define format.
just add the line of code to the main function would fix the problem.
BinDrivers::DefineFormate(app);
I'm writing a party system for a game, and I'm getting some very strange behavior out of a std::set std::wstring that contains IP addresses for the party. The error I'm getting is in xtree, usually in clear, but I've also hit it in insert. It's a read access violation at _Head->_Parent, usually says something like "_Head->_Parent was [memory address]."
This problem is very rare, and I've been trying to reproduce it for 2 months with no success. The game is up 24/7, and thousands of parties are created and destroyed each day, and I only get this error 2-3 times a week. Everything that inserts into, erases from, iterates over, or clears this set has a global mutex around it, that's only used for this set. Here's the relevant code:
Party.h
```
private:
std::set<std::wstring> ipList;
public:
std::set<std::wstring> getIPList() { return ipList; }
```
Party.cpp
```
PartyManager::DisbandParty(Party* party){
SAFE_DELETE(party);
}
Party::~Party(){
ipList.clear();
}
Party::AddPartyMember(){
getUniquePlayerLock.lock();
ipList.insert(s2ws(player->GetClientSession()->GetRemoteIP()));
getUniquePlayerLock.unlock();
}
Party::LeaveParty(){
getUniquePlayerLock.lock();
ipList.erase(s2ws(player->GetClientSession()->GetRemoteIP()));
getUniquePlayerLock.unlock();
}
Party::KickMember(){
getUniquePlayerLock.lock();
ipList.erase(s2ws(kickedplayer->GetClientSession()->GetRemoteIP()));
getUniquePlayerLock.unlock();
}
Party::GetUniquePlayers(){
std::set<std::wstring>::iterator it;
std::wstring curIP;
std::list<CPlayer*> uniquePlayers;
if (!ipList.empty()) {
for (it = ipList.begin(); it != ipList.end(); it++)
{
curIP = *it;
//std::wcout << "\nChecking IP " << curIP;
for (int i = 0; i < m_byMemberInfoCount; i++)
{
//std::cout << "\n" << i;
CPlayer* player = GetPlayer(i);
if (player) {
if (curIP == s2ws(player->GetClientSession()->GetRemoteIP())) {
uniquePlayers.push_back(player);
//std::wcout << "\n" << curIP;
break;
}
}
}
}
}
return uniquePlayers;
}
```
I'm all out of ideas here. It has to be some sort of undefined behavior, memory corruption, or something very obvious that I'm missing. Maybe in certain circumstances ipList is being destroyed before the party destructor is called? I'm still fuzzy on when variables declared in header files are considered "out of scope" and thus destroyed. Any help is appreciated.
Edit: With this logic, would the value of player->GetClientSession()->GetRemoteIP() be destroyed until it is repopulated?
Edit2: I've made some changes to check for nulls in the client session and IP as requested. This time, I'm getting an access violation error on accessing the lower bound of the set.
```
template <class _Keyty>
_Tree_find_result<_Nodeptr> _Find_lower_bound(const _Keyty& _Keyval) const {
const auto _Scary = _Get_scary();
_Tree_find_result<_Nodeptr> _Result{{_Scary->_Myhead->_Parent, _Tree_child::_Right}, _Scary->_Myhead}; **ACCESS VIOLATION ERROR IS HERE**
_Nodeptr _Trynode = _Result._Location._Parent;
while (!_Trynode->_Isnil) {`enter code here`
_Result._Location._Parent = _Trynode;
if (_DEBUG_LT_PRED(_Getcomp(), _Traits::_Kfn(_Trynode->_Myval), _Keyval)) {
_Result._Location._Child = _Tree_child::_Right;
_Trynode = _Trynode->_Right;
} else {
_Result._Location._Child = _Tree_child::_Left;
_Result._Bound = _Trynode;
_Trynode = _Trynode->_Left;
}
}
return _Result;
}
```
What could I possibly be doing to this set to cause this memory access error? It's a member variable being accessed in a class function, with no out of band destructors being called on it anywhere. I'm totally lost here.
Edit 3: Adding ifdefs for the global mutex below:
globalVariables.h:
#pragma once
#ifndef playerLockDefined
#include <mutex>
#define playerLockDefined
extern std::mutex getUniquePlayerLock;
#endif // !1
globalVariables.cpp:
#include "stdafx.h"
#include "globalVariables.h"
std::mutex getUniquePlayerLock;
I am working on a small game and came across a big problem with lists.
Here's my code:
void cCollisionManager::checkCollision(cPlayer * pPlayer, std::list<cAsteroid*> *asteroidList, std::list<cShot*> *ShotList)
{
sf::FloatRect PlayerBox = pPlayer->getSprite()->getGlobalBounds();
for (auto it : *asteroidList) {
for (auto es : *ShotList) {
sf::FloatRect asteroidboundingBox = it->getSprite()->getGlobalBounds();
sf::FloatRect ShotBox = es->getSprite().getGlobalBounds();
if (asteroidboundingBox.intersects(ShotBox)) {
it = asteroidList->erase(it);
*pPlayer->pPunkte += 1;
std::cout << *pPlayer->pPunkte << std::endl;
}
if (asteroidboundingBox.intersects(PlayerBox)) {
if (*pPlayer->phealth >= 0.f)
*pPlayer->phealth -= 0.5f;
}
}
}
}
I used SFML and basically everything works. But if I want to delete the colliding asteroid and the shot, the programs exits with an error. In the if loop I tried to erase the object, but the compiler also gives an error saying that the argument type is not the same as the object type I am giving to it.
EDIT
I had another look at the other question, you recommended to me, but still I haven't found out how to solve that problem. So if I changed my code to a while loop, the game couldn't handle it, because the Collision Manager is actually called in every single Call of the SFML main loop. So it would just get stuck in my collision loop. So I changed my code a bit, but still, things are not working.
Don't modify sequences that are being enumerated with range-for. Use
iterators and the appropriate result of an erase. – WhozCraig
This is actually the answer to it. I did the mistake - using a for loop and not a while loop and so I had some big issues and bad construction ideas for my code - luckily everything now works!
Here is my final code:
auto it = asteroidList->begin();
auto es = ShotList->begin();
while (it != asteroidList->end()) {
sf::FloatRect PlayerBox = pPlayer->getSprite()->getGlobalBounds();
sf::FloatRect asteroidboundingBox = (*it)->getSprite()->getGlobalBounds();
while (es != ShotList->end())
{
sf::FloatRect ShotBox = (*es)->getSprite().getGlobalBounds();
if (asteroidboundingBox.intersects(ShotBox)) {
it = asteroidList->erase(it);
es = ShotList->erase(es);
std::cout << "Asteroid destroyed" << std::endl;
*pPlayer->pPunkte += 1;
std::cout << *pPlayer->pPunkte << std::endl;
}
if (es != ShotList->end())
es++;
}
if (asteroidboundingBox.intersects(PlayerBox))
{
if (*pPlayer->phealth > 3.f) {
*pPlayer->phealth -= 5.f;
it = asteroidList->erase(it);
}
else
*pPlayer->pBStateAlive = false;
}
if (it != asteroidList->end()) {
it++;
es = ShotList->begin();
}
}
}
so I'm used to coding in C# and have just started using C++ again after a pretty substantial break. Essentially what I'm trying to do is to create a program that has lists of students with IDs, in courses.
I have this code that essentially prints out all available students in courses.
auto allCourses = WSUCourse::getAllCourses();
std::for_each(
allCourses.begin(),
allCourses.end(),
GetCoursePrinter());
The GetCoursePrinter() is called in this code in the constructor
struct GetCoursePrinter
{
void operator () (
MyCourse *coursePtr
)
{
std::cout << coursePtr->getIdentifier() <<
": " <<
coursePtr->getTitle() <<
std::endl;
}
};
My problem is after I delete an enrollment like so
MyEnrollment *enrollmentPtr = MyEnrollment::findEnrollment(
MyStudent::getStudentWithUniqueID(1000002),
MyCourse::getCourseWithIdentifier("CS 2800")
);
delete enrollmentPtr;
And then try to print it with GetCoursePrinter it crashes. I believe this is because it's trying to access something that doesn't exist. What I'm wondering is if there is a way to call something like this
if (allCourses.current() != null)
{
GetCoursePrinter();
}
else
{
//do nothing
}
when you call:
delete enrollmentPtr;
you need to remove this item in environment.