Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game sometimes hangs forever after loading audio when loading a case #31

Closed
GabuEx opened this issue Sep 30, 2014 · 6 comments
Closed
Labels

Comments

@GabuEx
Copy link
Owner

GabuEx commented Sep 30, 2014

I've had difficulty reproducing this or getting meaningful information as it seems to happen only sporadically, but after the implementation of the MRU cache for character display, I've noticed the game sometimes crash inside TTF_RenderUTF8Blended after "Loading audio..." completes when loading a case.

@GabuEx GabuEx added the bug label Sep 30, 2014
@GabuEx
Copy link
Owner Author

GabuEx commented Sep 30, 2014

A more complete callstack is as follows:

#0 0xffffffff gray_raster_render ()
#1 0xffffffff ft_smooth_render_generic ()
#2 0xffffffff FT_Render_Glyph_Internal ()
#3 0xffffffff TTF_GlyphMetrics ()
#4 0xffffffff TTF_RenderUTF8_Blended ()
#5 0xffffffff MLIFont::RenderGlyph(this=0x10243df10, c=114)
#6 0xffffffff MLIFont::CacheItemHandler::newItem(this=0x10243dbe0, key=@0x7fff5fbfef3c)
#7 0xffffffff MRUCache<unsigned int, Image*>::operator[](this=0x10243df30, key=@0x7fff5fbfef3c)
#8 0xffffffff MLIFont::GetWidth(this=0x10243df10, s=@0x7fff5fbff0d0)
#9 0xffffffff GameScreen::Draw(this=0x1023b77a0)
#10 0xffffffff Game::Draw(this=0x10243dec0)
#11 0xffffffff main(argc=1, argv=0x7fff5fbff6f8)

It seems as though it gets stuck for some in TTF_RenderUTF8_Blended trying to render a new glyph.

@GabuEx GabuEx changed the title Game sometimes crashes after loading audio when loading a case Game sometimes hangs forever after loading audio when loading a case Sep 30, 2014
@mad-mix
Copy link
Contributor

mad-mix commented Sep 30, 2014

I'm not sure if it fix that particular bug, but try to comment out pImage->FlagFontSource(this); in MLIFont::RenderGlyph(). Problem is that MLIFont now own many Image instances in cache instead of one, as it was before.

@GabuEx
Copy link
Owner Author

GabuEx commented Oct 1, 2014

Hmm, possible, I suppose (I'll try it and see), but that seems unlikely; the only time that that has any effect is when we're reloading sprites, which I don't think we actually even do anymore (we previously needed to do that in response to a fullscreen change). The callstack here seems pretty unrelated to that.

@mad-mix
Copy link
Contributor

mad-mix commented Oct 11, 2014

I've spent some time with debugger and finally got some results.

First, I got a corrupted text few times, similar to described in this message, Here is screenshots: screenshot 1, screenshot 2.
Second, I got crashes while loading case, but in some random places, not only in TTF_RenderUTF8_Blended call.

I had not been able to fully reproduce these bugs, but after code revision I found that one MLIFont ptr can be used from different threads, and MLIFont and MRUCache classes is not thread safe.

Аfter I wrap necessary functions in MLIFont in SDL_SemWait/SDL_SemPost, it looks like crashes and text corruptions are gone. Or I'm just unlucky enough.

@mad-mix
Copy link
Contributor

mad-mix commented Nov 10, 2014

Seems like here is several different bugs.

  1. Random SEGFAULT crashes while case loading. After I add thread safety to MLIFont it's gone, but I couldn't trace where exactly was the problem - semaphore value is never down to 0 before SDL_SemWait, and this is disturbing.

  2. Crash with SEGFAULT in TTF_RenderUTF8_Blended. I couldn't figure where is problem, but i got more detailed call stacks: one, two. There is some strange thing: "text" paramater in TTF_RenderUTF8_Blended (font=0x5101ab8, text=0x108594f5 "", fg=...) is empty, while utf8string = "p" in MLIFont::RenderGlyph.

  3. Text corruption in some cases.

UPD: sorry, didn't see fresh commits when writing this message. There is no crashes for the latest sources, at least on my computer.

@GabuEx
Copy link
Owner Author

GabuEx commented Nov 11, 2014

Yeah, sorry, I should've posted here when I checked in but neglected to do so. I think the root cause of all this business was the fact that MLIFont was being accessed off of the UI thread, which basically always induces unpredictable behavior if you don't know exactly how something works or that it's only being accessed on that one thread (and given that TTF_Font is a black box, one can't exactly know that in that case). Adding semaphores seemed to help a little, but never fixed the problem completely. I just moved everything that needed MLIFont onto the UI thread, and that seemed to fix all of these issues. Glad to hear that seems to be the case on your end, too. Let me know if you do see anything else, though.

@GabuEx GabuEx closed this as completed Nov 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants