-3
간단한 프로그램으로 시스템에로드 된 그림을 표시하려고합니다. 디렉토리에없는 이미지 이름을 입력하면 반환되지만 오류가 발견되지 않았다고 말하면 오류가 발생하지만 이후에 어떤 이유로 0을 반환하면 오류가 발생합니다. 메인 내부에서 충돌이 발생합니다.SDL 프로그램이 닫힐 때 - c0000005?
해결 방법을 찾을 수 없습니다. 내가 뭘 잘못하고 있는지에 대한 도움이 필요 하신가요?
#include "SDL_Wrapper.h"
#include <iostream>
#include <string>
using namespace std;
class Image {
public:
Image();
~Image();
int loadImage();
int saveImage();
int outputImage();
protected:
int height, width;
string imageName;
SDL_Surface* displayWindow;
SDL_Surface* imageSurface;
SDL_Surface* tempSurface;
};
Image::Image() {
displayWindow = NULL;
imageSurface = NULL;
tempSurface = NULL;
}
Image::~Image() {
}
int Image::saveImage() {
return 0;
}
int Image::outputImage() {
return 0;
}
int Image::loadImage() {
if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {
cout << "Error: Did not initialise correctly" << endl;
}
cout << "Enter the image name (and extension) you wish to use - ";
cin >> imageName;
imageSurface = LoadImage(imageName.c_str());
// Check if the image has been loaded correctly
if (imageSurface == NULL) {
imageSurface = NULL;
SDL_Quit();
cout << "Error: Picture not loaded/found" << endl;
return 1;
}
displayWindow = SDL_SetVideoMode(imageSurface->w, imageSurface->h, 32, SDL_SWSURFACE);
if (displayWindow == NULL) {
cout << "Error: displayWindow is blank, halting";
return 1;
}
SDL_WM_SetCaption("Image Preview", NULL);
SDL_BlitSurface(imageSurface, NULL, displayWindow, NULL);
if (SDL_Flip(displayWindow) == -1) {
cout << "Error: displayWindow did not flip correctly";
return 1;
}
SDL_Event event;
bool quit = false;
while (quit == false) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
quit = true;
}
}
}
SDL_FreeSurface(imageSurface);
SDL_Quit();
return 0;
}
void test()
{
Image img;
img.loadImage();
}
int main(int argc, char * argv[]) {
test();
return 0;
}
편집 : 컴파일러는 나에게이 이야기 -이 라인에
- > SDL_Display.exe!std::_DebugHeapDelete<std::locale::facet>(std::locale::facet * _Ptr) Line 62 + 0xc bytes C++
편집 2 인 '콜 스택'에서
Unhandled exception at 0x776015de in SDL_Display.exe: 0xC0000005: Access violation reading location 0x61d47bce.
을 : -
LoadImage() 함수// Load Image
SDL_Surface* LoadImage(const char* ImageLocation)
{
// Initialize Variables
SDL_Surface *SDL_S_Return = NULL;
// Load Image
SDL_S_Return = IMG_Load(ImageLocation);
// If it hasn't been loaded...
if(SDL_S_Return == NULL)
{
// Send out an Error Message
fprintf(stderr, "Error: %s\n", IMG_GetError());
}
// Return the Surface (Will be NULL if file isn't loaded)
return SDL_S_Return;
}
return 문 다음에 즉시 오류가 발생합니까? 디버거를 사용하여 충돌하는 정확한 줄을 가져옵니다. – Aaron
디버거에서 코드에서 액세스 위반이 트리거되는 위치는 무엇입니까? –
자네가 가면 나는 너희들에게 올바른 정보를 주었다고 생각한다. – Silenced