[Fixed] Fix assertion fault on VS2008 debug build

This is for people involved in the developement of Snes9x, or SNES emulators in general.
BUG REPORTS BELONG IN TECH SUPPORT/BUG TRACKING!
Post Reply
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

[Fixed] Fix assertion fault on VS2008 debug build

Post by gocha »

Prevented refering erased iterator.

Code: Select all

diff --git a/conffile.cpp b/conffile.cpp
index 94983e7..5f437ab 100644
--- a/conffile.cpp
+++ b/conffile.cpp
@@ -459,19 +459,21 @@ char *ConfigFile::GetStringDup(const char *key, const char *def){
 bool ConfigFile::SetString(const char *key, string val, const char *comment){
     set<ConfigEntry, ConfigEntry::key_less>::iterator i;
     bool ret=false;
+    bool found;
 
     ConfigEntry e(key, val);
 	if(comment && *comment) e.comment = comment;
 	e.used=true;
 
     i=data.find(e);
-    if(i!=data.end()){
+    found=(i==data.end());
+    if(!found){
         e.line=i->line;
         data.erase(e);
 		sectionSizes.DecreaseSectionSize(e.section);
         ret=true;
     }
-	if((i==data.end() && (!alphaSort || timeSort)) || (!alphaSort && timeSort))
+	if((found && (!alphaSort || timeSort)) || (!alphaSort && timeSort))
 		e.line = linectr++;
 
     data.insert(e);
Last edited by gocha on Mon Jan 10, 2011 1:46 pm, edited 2 times in total.
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Post by gocha »

Also, current snes9xgit master might cause another assertion error, when opening a movie from movie open dialog, if it's not my fault. (I guess it's because both fd and stream points the same file description. I don't know how it should be fixed.)
User avatar
BearOso
Official GTK/Linux Porter/Dev
Posts: 460
Joined: Tue Oct 02, 2007 12:50 am

Post by BearOso »

Ok, committed.
gocha wrote:Also, current snes9xgit master might cause another assertion error, when opening a movie from movie open dialog, if it's not my fault. (I guess it's because both fd and stream points the same file description. I don't know how it should be fixed.)
This is visual studio being too pedantic. It's perfectly OK to have two different references to the same file descriptor.
User avatar
OV2
Official Win32 Porter/Dev
Posts: 679
Joined: Thu Aug 30, 2007 10:15 pm

Post by OV2 »

It's not only an assertion, it's a crash on every movie playback. I think the problem was caused during the dup and access call removal. Removing the fclose call after CLOSE_STREAM in S9xMovieOpen stops the crash. IIRC closing a stream also closes the associated file descriptor - that might be the problem here.
User avatar
BearOso
Official GTK/Linux Porter/Dev
Posts: 460
Joined: Tue Oct 02, 2007 12:50 am

Post by BearOso »

Doh. In spec, double-closing a file descriptor definitely shouldn't crash. We also can't leave the FILE type stream there because it's a leak.

Ok, so the problem here is that we need an integer file number to pass to REOPEN_STREAM. We can't just OPEN_STREAM because, when using zlib, seeking is proportional to the compressed size, and the header is uncompressed. We can't use "dup" because it's not standard C, and we can't use "open" because it's also not standard C. And ideas?
User avatar
BearOso
Official GTK/Linux Porter/Dev
Posts: 460
Joined: Tue Oct 02, 2007 12:50 am

Post by BearOso »

Ok, a little research shows that the FILE objects might be managed by the C library, so fclose won't leave it intact. I've checked it in valgrind, any no leak comes from there, so it should be fine.
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Post by gocha »

BearOso wrote:Ok, a little research shows that the FILE objects might be managed by the C library, so fclose won't leave it intact. I've checked it in valgrind, any no leak comes from there, so it should be fine.
I checked your update and it worked fine. Thanks.
User avatar
Camo_Yoshi
Snes9x Purple belt
Posts: 922
Joined: Thu Nov 08, 2007 7:59 pm

Post by Camo_Yoshi »

I look at this topic in a tab and see...

Image

And go: O_o'
Snes9x FAQs | Forum Rules
What operating system are you using? 32 or 64bit? Version of Snes9x? Is the text at the bottom of the window white when you load the game?
These suggestions are usually the solution to your issue!
the_randomizer
Snes9x Orange Belt
Posts: 222
Joined: Sat Oct 17, 2009 4:18 am

Post by the_randomizer »

Camo_Yoshi wrote:I look at this topic in a tab and see...

Image

And go: O_o'
Wow. Simply amazing. :shock: Just like the poorly abbreviated words for Assistant Manager.
Lisa: "I hope you all know you're sponsoring a murderous pirate!"
Sponsor: "A pirate!!? Well, that's hardly the image we need for Long John Silvers!"
Post Reply