问题描述
在我的C ++项目中使用SDL2 mixer库时,我遇到了问题。一旦我在#includes SDL_mixer.h的类上调用函数,该项目将无法运行。尝试运行它时,出现以下消息:
和
您可能可以推断,在代码中添加断点不会提供任何其他信息,因为该项目根本不会启动。
注释掉使用包含混合器的类的行,使该项目似乎可以再次运行。我尝试过搜索错误代码,但找不到任何有关此错误含义的文档。
其他可能相关的信息:我正在使用柯南安装我的库,并将其设置为自动安装所有依赖项。
我将在此处发布该类的标题代码,尽管我不认为问题出在这里,因为该项目无论如何也无法运行到该代码。
#include <SDL.h>
#include <SDL_mixer.h>
#include <memory>
#include <string>
#include <map>
class SoundService {
public:
/*******************************************************************************
* @brief Gets the singleton instance of the SoundService class.
*
* @return A reference to the instance of the SoundService.
******************************************************************************/
static std::unique_ptr<SoundService> &getInstance() {
if (instance == nullptr) {
if(Mix_OpenAudio(44100,MIX_DEFAULT_FORMAT,2,4096) < 0){
SDL_Log("mixer Initialization Error: %s",Mix_GetError());
}
instance = std::unique_ptr<SoundService>(new SoundService());
}
return instance;
}
/**
* @brief Loads a music file and stores it with a given id string.
* @param id
* @param filePath
* @return True if the asset has been loaded successfully,otherwise false.
*/
bool loadMusic(const std::string &id,const std::string &filePath);
void playMusic(const std::string &id,int loops = -1);
void pauseMusic();
void resumeMusic();
/**
* @brief Removes a music file by id.
* @param id
* @return True if the asset has been removed successfully,otherwise false.
*/
bool removeMusic(std::string &id);
/**
* @brief Loads an sfx file and stores it with a given id string.
* @param id
* @param filePath
* @return True if the asset has been loaded successfully,otherwise false.
*/
bool loadSFX(const std::string &id,const std::string &filePath);
void playSFX(const std::string &id,int loops = 0,int channel = 0);
/**
* @brief Removes an sfx file by id.
* @param id
* @return True if the asset has been removed successfully,otherwise false.
*/
bool removeSFX(std::string &id);
/**
* @brief Removes all the music files and sfx files from the sound service
*/
void clear();
private:
SoundService() = default;
static std::unique_ptr<SoundService> instance;
std::map<std::string,Mix_Music *> musicMap;
std::map<std::string,Mix_Chunk *> sfxMap;
};
auto& soundService = SoundService::getInstance();
以下是用于声明所需库的conanfile:
from conans import ConanFile,CMake
from conans.tools import os_info
class ModularMagicConan(ConanFile):
name = "ModularMagic"
version = "0.1"
url = "edited out"
description = "A 2D game"
settings = "os","compiler","build_type","arch"
generators = "cmake"
def requirements(self):
self.requires("sdl2/2.0.12@bincrafters/stable") # SDL2,rendering and window creation library
self.requires("sdl2_image/2.0.5@bincrafters/stable") # SDL2 image,texture library
self.requires("sdl2_mixer/2.0.4@bincrafters/stable") # SDL2 mixer,sound library
self.requires("gtest/1.10.0") # Used for unit testing
self.requires("Box2d/2.4.0") # Box2D,physics library
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
cmake.test()
任何熟悉此问题或有任何想法的原因是什么以及如何解决它?
解决方法
错误class CustomSignupForm(forms.Form):
first_name = forms.CharField(max_length=30,label='First name')
last_name = forms.CharField(max_length=30,label='Last name')
email = forms.EmailField(required=True)
password = forms.CharField(widget=forms.PasswordInput)
def signup(self,request,user):
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.email = self.cleaned_data['email']
user.password = self.cleaned_data['password']
user.save()
通常与.NET Framework问题有关。当某些Windows服务无法启动时也会出现。
如果您是我,我将检查系统的事件查看器(假设您使用的是Windows OS)以获取有关这些事件的更多详细信息。您可以通过关注this tutorial
找到此类应用程序 ,好吧,我不知道它是否真的可以作为答案,但是也许可以帮助其他遇到相同问题的人。我和一个同事在某处发现了这个粗略的建议,在System32中扔了一个glib-2.0-0.dll副本(您应该可以在:C驱动器的.conan文件夹中找到该副本)。这以某种方式起作用,我现在可以运行我的项目。我不知道SDL_mixer是否有问题,因为这似乎不是解决问题的正确方法,但至少我可以再次进行我的项目。
,在 CLion 中遇到了同样的问题。通过复制 SDL2_mixer 中的所有 .dll 并将它们放在与 .exe 文件相同的目录中来修复它。see picture here