Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#ifndef FONT_HPP #define FONT_HPP #include "framework.hpp" #include <SDL_ttf.h> class CFont { public: CFont(); ~CFont(); void LoadFont(const string sFontname, int iFontsize); private: SDL_Surface *m_pScreen; SDL_Surface *m_pText; TTF_Font *m_pFont; }; #endif |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include "font.hpp" #include "Logfile.hpp" #include <SDL_ttf.h> //Konstruktor CFont::CFont() { m_pScreen = g_pFramework->GetScreen(); m_pFont = NULL; } //Destruktor CFont::~CFont() { SDL_FreeSurface(m_pText); } //LoadFont void CFont::LoadFont(const string sFilename, int iFontsize) { m_pFont = TTF_OpenFont(sFilename.c_str(),iFontsize); if(m_pFont == NULL) { cout << "Fehler beim Laden von: " << sFilename.c_str(); cout << endl; cout << "Fehlermeldung: " << SDL_GetError() << endl; g_pFramework->Quit(); exit(1); } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
//LoadFont void CFont::LoadFont(const string sFilename, int iFontsize) { TTF_Font *m_pFont = TTF_OpenFont(sFilename.c_str(),iFontsize); if(m_pFont == NULL) { cout << "Fehler beim Laden von: " << sFilename.c_str(); cout << endl; cout << "Fehlermeldung: " << SDL_GetError() << endl; g_pFramework->Quit(); exit(1); } } |
C-/C++-Quelltext |
|
1 |
m_pFont = new TTF_Font; |
C-/C++-Quelltext |
|
1 2 3 4 |
CFont pFont = 0; pFont->LoadFont ("arial.ttf", 12); /* oder noch brutaler */ reinterpret_cast<CFont*> (0)->LoadFont ("arial.ttf", 12); |
Zitat
Zugriffsverletzung beim Schreiben an Position 0x00000008.
Zitat von »"Chase"«
Und wenn er den Pointer einfach in die cpp in den Namespace der Klasse schreibt wird er statisch oder ?
Zitat
Abgesehen davon will er hier ganz sicher auch gar keine Statics benutzen, weil er dann ja auch nur noch einen Font haben könnte.
Zitat von »"spacegaier"«
Das mit dem Gedankenbeispiel kapier ich aber net . Könnsch mir das noch bitte erklären?
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 |
void CFont::foo () { if (reinterpret_cast<void**> (this + 8) == &m_pFont) std::cerr << "Huch, gleiche Adresse...;)" << std::endl; else std::cerr << "Rainer redet Unsinn... ;)" << std::endl; } |
Sicaine
unregistriert
Anonymous
unregistriert
Zitat von »"Sicaine"«
"Bekomme beim Laden einer Schrift mit der SDL eine unbehandelte Ausnahme"
Was is daran so schwer?
Werbeanzeige