Sign in to follow this  
programering

[Solved] SDL_WM_SetIcon crashes

Recommended Posts

I can't set the window icon, not even with SDL_LoadBMP:
#include <SDL/SDL.h>
#include "SDL/video.h"
#include "SDL/events.h"
#include "filesrc.h"
#include "log.h"


void MainGameLoop();


Log outLog("OutLog.txt");
Log errLog("ErrLog.txt");


Screen screen("Icon.bmp","",640,480,0,SDL_RESIZABLE,0xffffff00,"Klingis","");
Event event(screen,KEY_OPTION_DOWN);


Image *test;


int SDL_main(int argc, char *argv[])
{
	SDL_Init(SDL_INIT_VIDEO);

	InitFileDirs();

	InitKeys();

	SetFileDir(FILE_DIR_DATA);

	test = new Image("test.bmp");
	test->setColor(0,0,0,0);
	test->setMask(0,0,0,255);
	test->drawHorzLine(15,0,100);
//	screen.setMask(0xff,0xff,0);
	screen.setColor(0xff,0x00,0x00);

	MainGameLoop();

	SetFileDir(FILE_DIR_APP);

	screen.saveBMP("ScreenShot.bmp");
	test->saveBMP("test.bmp");

	delete test;

	return 0;
}



void MainGameLoop()
{
	bool running = true;

	while (running)
	{
		screen.fillBG();
	//	screen.drawRect(10,10,100,100);

		test->centerBlit();

		if (event.update())
		{
			switch (event.type())
			{
			case SDL_QUIT:
				running = false;
				break;
			default:
				break;
			}
		}

		screen.update();

	}
}



void Screen::setIcon(const std::string &iconFile, const std::string &maskFile)
{
	SDL_Surface *icon;
	std::ifstream maskIfs;
	Uint8 *mask;

	SetFileDir(GetDataDir());

	if (iconFile.empty())
		icon = NULL;
	else
		icon = SDL_LoadBMP(FilePath(iconFile).c_str());

	if (maskFile.empty())
		mask = NULL;
	else
	{
		maskIfs.open(FilePath(maskFile).c_str());

		if (maskIfs.good())
		{
			int size = 32 * 32;
			mask = new Uint8[size];

			maskIfs.read((char *)mask,size);

			maskIfs.close();
		}
		else
			mask = NULL;
	}

	if (icon || mask)
		setIcon(icon,mask);
}



Screen::Screen(const std::string &iconFile, const std::string &iconMaskFile, int width, int height, int bitpp, Uint32 flags, Uint32 bgColor, const std::string &title, const std::string &iconName)
{
//	setIcon(iconFile,iconMaskFile);
	SetFileDir(GetDataDir());

	SDL_WM_SetIcon(SDL_LoadBMP(FilePath(iconFile).c_str()),0);

	this->width = width;
	this->height = height;
	this->bitpp = bitpp;
	this->flags = flags;
	this->bgColor = bgColor;

	success = create();

	setCaption(title,iconName);
}



Do you know why? [Edited by - programering on May 30, 2009 12:24:13 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by programering
I can't set the window icon, not even with SDL_LoadBMP:

*** Source Snippet Removed ***


Do you know why?
Nope.


But if you give us some sort of information we might. For a start, where does the crash occur, and what's the message? Have you used your Debugger to see that everything is as it should be (E.g. that the pointers are valid, and you managed to load the BMP and so on)?

Share this post


Link to post
Share on other sites
Yes the SDL_Surface loads, and I know it's SDL_WM_SetIcon(SDL_LoadBMP(FilePath(iconFile).c_str()),0); causing the crash.

Call Stack

SDL! 0039c2ac()
$E36() line 15 + 223 bytes
$E39() + 29 bytes
MSVCRT! 77c29d7a()
KLINGIS! WinMainCRTStartup + 202 bytes
KERNEL32! 7c816fe7()




SDL! 0039c2ac() - Code Segment:

0039C290 push ecx
0039C291 mov edx,dword ptr ds:[3B19DCh]
0039C297 push ebx
0039C298 mov ebx,dword ptr [esp+0Ch]
0039C29C mov eax,edx
0039C29E push ebp
0039C29F push esi
0039C2A0 test ebx,ebx
0039C2A2 mov dword ptr [esp+0Ch],eax
0039C2A6 je 0039C353
0039C2AC mov eax,dword ptr [eax+104h] // <-- Here.
0039C2B2 test eax,eax
0039C2B4 je 0039C353
0039C2BA mov ecx,dword ptr [esp+18h]
0039C2BE test ecx,ecx
0039C2C0 jne 0039C34B
0039C2C6 mov eax,dword ptr [ebx+8]
0039C2C9 mov dword ptr [esp+14h],ecx
0039C2CD add eax,7
0039C2D0 imul eax,dword ptr [ebx+0Ch]
0039C2D4 cdq
0039C2D5 and edx,7
0039C2D8 add eax,edx
0039C2DA mov esi,eax
0039C2DC sar esi,3
0039C2DF push esi
0039C2E0 call dword ptr ds:[3A110Ch]
0039C2E6 mov ebp,eax
0039C2E8 add esp,4
0039C2EB test ebp,ebp
0039C2ED je 0039C353
0039C2EF mov ecx,esi
0039C2F1 push edi
0039C2F2 mov edx,ecx
0039C2F4 or eax,0FFh
0039C2F7 mov edi,ebp
0039C2F9 shr ecx,2
0039C2FC rep stos dword ptr [edi]
0039C2FE mov ecx,edx
0039C300 and ecx,3
0039C303 rep stos byte ptr [edi]
0039C305 mov eax,dword ptr [ebx]
0039C307 pop edi
0039C308 test ah,10h
0039C30B mov ecx,1
0039C310 jne 0039C316
0039C312 mov ecx,dword ptr [esp+14h]
0039C316 test eax,10000h
0039C31B je 0039C320
0039C31D or ecx,2
0039C320 test ecx,ecx
0039C322 je 0039C32F
0039C324 push ecx
0039C325 push ebp
0039C326 push ebx
0039C327 call 0039C360
0039C32C add esp,0Ch
0039C32F mov eax,dword ptr [esp+0Ch]
0039C333 push ebp
0039C334 push ebx
0039C335 push eax
0039C336 call dword ptr [eax+104h]
0039C33C push ebp
0039C33D call dword ptr ds:[3A1104h]
0039C343 add esp,10h
0039C346 pop esi
0039C347 pop ebp
0039C348 pop ebx
0039C349 pop ecx
0039C34A ret
0039C34B push ecx
0039C34C push ebx
0039C34D push edx
0039C34E call eax
0039C350 add esp,0Ch
0039C353 pop esi
0039C354 pop ebp
0039C355 pop ebx
0039C356 pop ecx
0039C357 ret





$E36() line 15 + 223 bytes

#include <SDL/SDL.h>
#include "SDL/video.h"
#include "SDL/events.h"
#include "filesrc.h"
#include "log.h"


void MainGameLoop();


Log outLog("OutLog.txt");
Log errLog("ErrLog.txt");


/* The green arrow --> */ Screen screen("Icon.bmp","",640,480,0,SDL_RESIZABLE,0xffffff00,"Klingis","");
Event event(screen,KEY_OPTION_DOWN);


Image *test;


int SDL_main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);

InitFileDirs();

InitKeys();

SetFileDir(FILE_DIR_DATA);

test = new Image("test.bmp");
test->setColor(0,0,0,0);
test->setMask(0,0,0,255);
test->drawHorzLine(15,0,100);
// screen.setMask(0xff,0xff,0);
screen.setColor(0xff,0x00,0x00);

MainGameLoop();

SetFileDir(FILE_DIR_APP);

screen.saveBMP("ScreenShot.bmp");
test->saveBMP("test.bmp");

delete test;

return 0;
}



void MainGameLoop()
{
bool running = true;

while (running)
{
screen.fillBG();
// screen.drawRect(10,10,100,100);

test->centerBlit();

if (event.update())
{
switch (event.type())
{
case SDL_QUIT:
running = false;
break;
default:
break;
}
}

screen.update();

}
}





$E39() + 29 bytes

$E39:
00404890 push ebp
00404891 mov ebp,esp
00404893 sub esp,40h
00404896 push ebx
00404897 push esi
00404898 push edi
00404899 lea edi,[ebp-40h]
0040489C mov ecx,10h
004048A1 mov eax,0CCCCCCCCh
004048A6 rep stos dword ptr [edi]
004048A8 call $E36 (004048d0)
004048AD call $E38 (00404a80)
004048B2 pop edi
004048B3 pop esi
004048B4 pop ebx
004048B5 add esp,40h
004048B8 cmp ebp,esp
004048BA call _chkesp (0040869c)
004048BF mov esp,ebp
004048C1 pop ebp
004048C2 ret





MSVCRT! 77c29d7a()

77C29D0E int 3
77C29D0F int 3
77C29D10 int 3
77C29D11 int 3
77C29D12 int 3
77C29D13 mov edi,edi
77C29D15 push ebp
77C29D16 mov ebp,esp
77C29D18 push 77C040A4h
77C29D1D call dword ptr ds:[77C010E8h]
77C29D23 test eax,eax
77C29D25 je 77C29D3C
77C29D27 push 77C04094h
77C29D2C push eax
77C29D2D call dword ptr ds:[77C010D0h]
77C29D33 test eax,eax
77C29D35 je 77C29D3C
77C29D37 push dword ptr [ebp+8]
77C29D3A call eax
77C29D3C push dword ptr [ebp+8]
77C29D3F call dword ptr ds:[77C0121Ch]
77C29D45 int 3
77C29D46 int 3
77C29D47 int 3
77C29D48 int 3
77C29D49 int 3
77C29D4A int 3
77C29D4B push 8
77C29D4D call 77C2A5BB
77C29D52 pop ecx
77C29D53 ret
77C29D54 int 3
77C29D55 int 3
77C29D56 int 3
77C29D57 int 3
77C29D58 int 3
77C29D59 push 8
77C29D5B call 77C2A519
77C29D60 pop ecx
77C29D61 ret
77C29D62 int 3
77C29D63 int 3
77C29D64 int 3
77C29D65 int 3
77C29D66 int 3
77C29D67 mov edi,edi
77C29D69 push ebp
77C29D6A mov ebp,esp
77C29D6C push esi
77C29D6D mov esi,dword ptr [ebp+8]
77C29D70 jmp 77C29D7D
77C29D72 mov eax,dword ptr [esi]
77C29D74 test eax,eax
77C29D76 je 77C29D7A
77C29D78 call eax
77C29D7A add esi,4 // <-- Green arrow here.
77C29D7D cmp esi,dword ptr [ebp+0Ch]
77C29D80 jb 77C29D72
77C29D82 pop esi
77C29D83 pop ebp
77C29D84 ret
77C29D85 int 3
77C29D86 int 3
77C29D87 int 3
77C29D88 int 3
77C29D89 int 3
77C29D8A mov eax,[77C500F8]
77C29D8F test eax,eax
77C29D91 je 77C29D95
77C29D93 call eax
77C29D95 push esi
77C29D96 mov ecx,77C01284h
77C29D9B mov esi,77C0129Ch
77C29DA0 xor eax,eax
77C29DA2 cmp ecx,esi
77C29DA4 push edi
77C29DA5 mov edi,ecx
77C29DA7 jae 77C29DC0
77C29DA9 test eax,eax
77C29DAB jne 77C29DD3
77C29DAD mov ecx,dword ptr [edi]
77C29DAF test ecx,ecx
77C29DB1 je 77C29DB5
77C29DB3 call ecx
77C29DB5 add edi,4
77C29DB8 cmp edi,esi
77C29DBA jb 77C29DA9
77C29DBC test eax,eax
77C29DBE jne 77C29DD3
77C29DC0 push 77C01280h
77C29DC5 push 77C01278h
77C29DCA call 77C29D67
77C29DCF pop ecx
77C29DD0 pop ecx
77C29DD1 xor eax,eax
77C29DD3 pop edi
77C29DD4 pop esi
77C29DD5 ret




Output

Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system\SDL_image.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system\SDL.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\winmm.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\secur32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found.
Loaded symbols for 'C:\WINDOWS\system32\MSVCP60D.DLL'
Loaded symbols for 'C:\WINDOWS\system32\MSVCRTD.DLL'
Loaded 'C:\WINDOWS\system32\imm32.dll', no matching symbolic information found.
First-chance exception in Klingis.exe (SDL.DLL): 0xC0000005: Access Violation.
The program 'C:\Save\Projects\Programming\Klingis Entertainment\Klingis\Cpp\Debug\Klingis.exe' has exited with code 0 (0x0).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this