Access violation with SDL_RenderText

clayasaurus clayasaurus at gmail.com
Fri Oct 27 18:02:23 PDT 2006


Johan Granberg wrote:
> mike wrote:
> 
>> Hi!
>>
>> I'm doing some GUI stuff with SDL and I got those constantly changing
>> values that I need to draw on the screen. The idea (if you don't know SDL)
>> is that you create a new surface (a bitmap) every time the value changes,
>> draw it to the screen and then delete the bitmap after drawing.
>>
>> In pseudo code:
>>
>> ' surface = RenderText(value); // <- This function returns a pointer to a
>> new surface (a struct)
>> ' DrawSurface(surface);
>> ' UpdateScreen();
>> ' FreeSurface(surface);
>>
>> Now that works so far. The problem is that my program crashes after some
>> time - about two minutes when I'm constantly moving the mouse, forcing the
>> GUI to redraw (access violation in the RenderText() line). Memory usage
>> goes up a little, about 4k every 10-15 seconds, which makes me a bit
>> suspicious, since I'm not newing anything at all, besides the surface I
>> get returned from RenderText() which I delete anyway, using the
>> FreeSurface() function.
>>
>> So my question: Has anybody of you had this problem? Or any ideas? Could
>> that be a GC issue? Maybe the GC wants to free something that doesn't
>> exist anymore? I have no idea what's going wrong, so if someone could give
>> me a hint I'd be very glad.
>>
>> -Mike
>>
> 
> I don't know what is wrong but i had a similar problem myself also using
> SDL. I think it can bee related to string handling but is not sure, try
> calling gcfullcolect every frame and see if it helps, I got my memory leaks
> down to a tickle that way.

If you pass d char[] into SDL's char* functions, like...

RenderText(char* text);

char[] w;
RenderText(w);

It might work sometimes but it is prone to crashing. Always use the 
std.toStringz() to turn D strings into C strings in this case.

I do not know if this is a problem though, just a guess. SDL has been 
stable otherwise.







More information about the Digitalmars-d-learn mailing list