Varyemez
Hectopat
Daha fazla
- Cinsiyet
- Erkek
- Meslek
- Lise Öğrencisi
C++ ile yazdığım uygulamayı açtığım zaman belirli işlemlerden sonra " *** stack smashing detected ***: <unknown> terminated Aborted (core dumped) " hatasını alıyorum. İnternette -fno-protector flag'ını eklemem gerektiği yazıyordu. Bunu yazınca stack smashing hatası gitti, ancak "segmentation fault (core dumped)" hatası almaya başladım. Bu stack smashing hatası neden oluşur? Nasıl düzeltirim?
İnşallah konuma cevap gelir, çünkü bu hata gerçekten başımı ağrıtmaya başladı.
İnşallah konuma cevap gelir, çünkü bu hata gerçekten başımı ağrıtmaya başladı.
C++:
COLLADA (dae) yukleyicisi
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <SDL2/SDL.h>
class ObjectData {
public:
std::vector<float> Position;
std::vector<float> Indices;
std::vector<float> TexCoord;
std::vector<float> Normal;
inline float* PositionPointer() { return &Position[0]; }
inline float* IndicesPointer() { return &Indices[0]; }
inline float* TexCoordPointer() { return &TexCoord[0]; }
inline float* NormalPointer() { return &Normal[0]; }
void LoadFileCOLLADA(const char* FilePath, unsigned int Returns);
bool FAILURE;
char* INFO;
private:
void ReadFLOATCOLLADA ();
std::ifstream File;
int CursorPos;
};
/*
Function loads "float-array"
Cursor must start at ...>HERE3.1415 5.21...
*/
void ObjectData::ReadFLOATCOLLADA () {
int y = CursorPos, z;
char character, FloatLine[12];
while(character != '<') {
memset(FloatLine, '0', 12);
z = 0;
for (CursorPos; character != ' '; CursorPos++, z++) {
File.seekg(CursorPos);
File.get(character);
if (character == '<')
break;
FloatLine[z] = character;
std::cout<<"Char = "<<character<<" Cursor = "<<CursorPos<<std::endl;
std::cout<<"FLOAT_ARRAY = "<<FloatLine<<std::endl;
}
ObjectData::Position.push_back(atof(FloatLine));
File.seekg(CursorPos);
File.get(character);
}
std::cout<<"VECTOR LOADING END"<<std::endl;
for (int i=0; i < Position.size(); i++)
std::cout<<Position[i]<<std::endl;
} //End of function
void ObjectData::LoadFileCOLLADA(const char* FilePath, unsigned int Returns) {
File.open(FilePath, std::ios::in);
if (Returns == 0) {
if (true) {
char Character;
char line[64];
int x;
CursorPos = 0;
while (true) {
memset(line, ' ', 80);
for (CursorPos; Character != '<'; CursorPos++) {
File.seekg(CursorPos);
File.get(Character);
std::cout<<"Char: "<<Character<<" Cursor:"<<CursorPos<<std::endl;
}
x = 0;
for (CursorPos; Character != '>'; CursorPos++) {
File.get(Character);
line[x] = Character;
File.seekg(CursorPos);
std::cout<<"NOTFLOATARRAY "<<"Char: "<<Character<<" Cursor:"<<CursorPos<<std::endl;
x++;
}
std::cout<<line<<std::endl;
if (strstr(line, "float_array") != NULL && strstr(line, "mesh-positions-array") != NULL && strstr(line, "count=") != NULL) {
CursorPos--;
ObjectData::ReadFLOATCOLLADA();
std::cout<<"Position Vector is ready!"<<std::endl;
File.close();
std::cout<<"Position Vector is ready!"<<std::endl;
return;
}
}
}
}
}
C++:
//GameObject.cpp
...
...
ObjectData DataOfGameObject;
GameObject::Name = GameObjectName;
if (FileType == 1) {
std::cout<<"GameObject::"<<GameObject::Name<<" = Loading 3D model..."<<std::endl;
DataOfGameObject.LoadFileCOLLADA(ModelPath, 0); //HATA BURADA OLUSUYOR GIBI GOZUKUYOR, CUNKU TERMINAL ASAGIDAKI YAZIYI (COLLADA LOADED) YAZDIRMIYOR.
std::cout<<"COLLADA LOADED"<<std::endl;
if (DataOfGameObject.FAILURE) {
std::cout<<"GameObject::"<<GameObject::Name<<" = "<<DataOfGameObject.INFO<<std::endl;
GameObject::FAILURE = true;
return;
}
}
else
{
std::cout<<"GameObject::"<<GameObject::Name<<" = Only COLLADA supported."<<std::endl;
}
...
...
Son düzenleme: