The Partridge Family were neither partridges nor a family. Discuss.
-
Lauris321
- Posts: 16
- Joined: January 3rd, 2013, 9:30 pm
- Location: Lithuania
Post
by Lauris321 » July 18th, 2014, 4:56 pm
Hello forum!
I'am having a strange problem with loading files. When I load a tilemap in PLAY section, all the tiles within a tilemap works, but after that all other loaded surfaces get corrupted. Therefore, when you press left mouse button on a grass tile instead of a building surface you get a mess. The problem doesn't seem to corrupt surfaces only in TileMap.cpp.
The whole problem is in this part of code:
Code: Select all
if( GetOpenFileName(&ofn) )
{
tileMapFile = fopen( szFileName, "r" );
assert( tileMapFile );
}
else
{
tileMapFile = fopen( "TileMaps\\New_Tilemap.txt", "r" );
assert( tileMapFile );
}
If I cancel the file selection when the dialog pops up or don't use GetOpenFileName(&ofn) at all and use a predetermined path, the program works just fine.
I got the algorithm for the file selection popup from here:
http://www.winprog.org/tutorial/app_two.html
Another guy having similar problem, but unsolved:
http://www.graphicsgroups.com/15-direct ... 2d207b.htm
-
Attachments
-
- Project Tycoon.rar
- (38.27 KiB) Downloaded 150 times
-
LuisR14
- Posts: 1248
- Joined: May 23rd, 2013, 3:52 pm
- Location: USA
-
Contact:
Post
by LuisR14 » July 19th, 2014, 2:34 am
make sure to use GetOpenFileNameA (if you're building with unicode enabled then GetOpenFileName would resolve to GetOpenFileNameW
, tho the compiler should've probably error'd)
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]
irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]
alt[/url] -- join up if ever want real-time help or to just
chat --
-
Lauris321
- Posts: 16
- Joined: January 3rd, 2013, 9:30 pm
- Location: Lithuania
Post
by Lauris321 » July 19th, 2014, 8:33 am
Thanks for the response, but using GetOpenFileNameA still doesn't work for me.
Code: Select all
OPENFILENAMEA ofn;
char szFileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = *hWnd;
ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "txt";
FILE* tileMapFile;
if( GetOpenFileNameA(&ofn) )
{
tileMapFile = fopen( szFileName, "r" );
assert( tileMapFile );
}
else
{
tileMapFile = fopen( "TileMaps\\New_Tilemap.txt", "r" );
assert( tileMapFile );
}
Can you show me how exactly this part should be written?
-
chili
- Site Admin
- Posts: 3948
- Joined: December 31st, 2011, 4:53 pm
- Location: Japan
-
Contact:
Post
by chili » July 19th, 2014, 1:58 pm
I don't see the problem. Gonna need more detailed instructions on how to replicate the bug.
Chili
-
Lauris321
- Posts: 16
- Joined: January 3rd, 2013, 9:30 pm
- Location: Lithuania
Post
by Lauris321 » July 19th, 2014, 2:40 pm
When you launch the game select the PLAY option, then go to the Tilemaps folder and select New_Tilemap.txt. When you will be in the game you will be able to build buildings by pressing left mouse button on GRASS tiles. The problem is that the buildings in question will not be drawn properly because of memory corruption caused by GetOpenFileName() function in Tilemap.cpp file.
How it is supposed to look:
How it looks with the bug:
-
LuisR14
- Posts: 1248
- Joined: May 23rd, 2013, 3:52 pm
- Location: USA
-
Contact:
Post
by LuisR14 » July 22nd, 2014, 10:08 am
ok i found out the problem
GetOpenFileName changes the current working directory to the directory of the file you choose, so the fix was to also include the OFN_NOCHANGEDIR flag
(the documentation for OFN_NOCHANGEDIR tho says that it doesn't affect GetOpenFileName, so which means the documentation is wrong
)
edit: hehe, hadn't really taken the time to check this till now
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]
irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]
alt[/url] -- join up if ever want real-time help or to just
chat --
-
Lauris321
- Posts: 16
- Joined: January 3rd, 2013, 9:30 pm
- Location: Lithuania
Post
by Lauris321 » July 22nd, 2014, 4:34 pm
Thank you so much Luis, this problem was pestering for like a week now.
-
LuisR14
- Posts: 1248
- Joined: May 23rd, 2013, 3:52 pm
- Location: USA
-
Contact:
Post
by LuisR14 » July 22nd, 2014, 5:53 pm
hehe, no probs, glad to help
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]
irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]
alt[/url] -- join up if ever want real-time help or to just
chat --
-
chili
- Site Admin
- Posts: 3948
- Joined: December 31st, 2011, 4:53 pm
- Location: Japan
-
Contact:
Post
by chili » July 23rd, 2014, 1:26 am
Good stuff Luis. I've been meaning to take a look at this one for a few days but was procrastinating. :s
Chili
-
LuisR14
- Posts: 1248
- Joined: May 23rd, 2013, 3:52 pm
- Location: USA
-
Contact:
Post
by LuisR14 » July 23rd, 2014, 4:19 pm
haha, yea, i was procrastinating as well, but looks like i decided b4 you did xP
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]
irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]
alt[/url] -- join up if ever want real-time help or to just
chat --