我对SDL 2完全不熟悉,我希望找到一些帮助,让我的第一个正确的程序在其中。我们已经提供了一些已经在这个项目中使用的代码,这就是为什么我不是简单地使用BlitSurface函数来制作这个解决方案。如果这确实是更好的解决方案,我将切换到那个。这是程序运行时使用的状态的一部分,显示标题图像。
由于以下代码中的指针问题,我收到了中断错误:
void MenuState::Enter()
{
//Is to load the title image used for the State
Sprite* extBackgroundSprite = met_extSystem.met_pointextSpriteManager- >CreateSprite("../assets/Testimage1.bmp" , 0 , 0 , 768 , 1024);
}
这是指由SpriteManager类和CreateSprite函数创建的Sprite,如下所示:
Sprite * SpriteManager::CreateSprite(const std::string & point_stringFilePath, int point_intX, int point_intY, int point_intWidth, int point_intHeight)
{
auto iter = met_arraypointextTextures.find(point_stringFilePath); //breaks here
if (iter == met_arraypointextTextures.end())
//If the iterator cannot locate the sprite we need in our already loaded memory,
//it needs to be loaded into our map to create pointers
{
SDL_Surface* extSurface = SDL_LoadBMP(point_stringFilePath.c_str());
SDL_Texture* extTexture = SDL_CreateTextureFromSurface(met_pointextRenderer, extSurface);
SDL_FreeSurface(extSurface);
met_arraypointextTextures.insert(std::pair<std::string, SDL_Texture*>(point_stringFilePath, extTexture));
iter = met_arraypointextTextures.find(point_stringFilePath);
}
//Creates the sprite, adds a new index point via pushback
Sprite* extSprite = new Sprite(iter->second, point_intX, point_intY, point_intWidth, point_intHeight);
met_arraypointextSprites.push_back(extSprite);
return extSprite;
}
我希望这是足够的信息和代码来表达我的问题。如果没有,请告诉我!并提前感谢你。
答案 0 :(得分:1)
事实证明,我提供的信息无法解决问题。确实需要初始化指针,但是在构造函数中找到了参数,我在这里没有提供。