Access violation with SDL_RenderText

Bradley Smith digitalmars-com at baysmith.com
Sun Oct 29 01:16:49 PDT 2006



mike wrote:

> 
> I'm doing that already, and - oddly enough - this seems to be the problem.
> 
> ' SDL_RenderText("text");
> 
> works.
> 
> ' SDL_RenderText(toStringz("text"));
> 
> crashes after about two minutes, when I'm rendering text every frame. 
> Also without toStringz I have no increase in memory usage, while with 
> toStringz I have. Anyway, I'll post a solution once I find it.

Perhaps you should buffer the text passed to SDL? Something like the 
following:

// Do this once in a constructor or globally
char* renderedTextBuffer = new char[1024];

// Do this to render text
if (value.length > renderedTextBuffer.length) {
   renderedTextBuffer = new char[value.length];
}
renderedTextBuffer[0 .. value.length] = value;
renderedTextBuffer[value.length] = 0;
RenderText(renderedText);

This is effectively what toStringz() does, but it won't allocate memory 
with every render.

   Bradley



More information about the Digitalmars-d-learn mailing list