Problems with scope

Hi, I'm working on an SDL program and believe I am having some troubles with scope. Heres my original code, which worked fine and dandy. I've excluded the functions which blatantly are not part of the problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
bool appMain::execute(){
    SDL_Event Event;
    while(running) {
        applySurface(0,0,background,display);
        while(SDL_PollEvent(&Event)) {
            OnEvent(&Event);
            textLine.updateObjectFields();
        }
        SDL_Flip(display);
    }
    OnCleanup();
    return 0;
}

void appMain::OnEvent(SDL_Event* event) {
    if( event->type == SDL_KEYDOWN ){
            textLine.setText("u", textIndex)    
    }
}

int createTextObject::updateObjectFields(){ //didn't do anything in original code

return 1;}

void createTextObject::setText(char* newText, int fieldIndex){
    textSurface[fieldIndex] = TTF_RenderText_Solid(fonts[fieldIndex],"newText", textColor );
    SDL_Rect offset;
    offset.x = coords[fieldIndex][0];
    offset.y = coords[fieldIndex][1];
    SDL_BlitSurface( textSurface[fieldIndex], NULL, surfaceDest, &offset );
}


So what I wanted to do was change it so SDL_Blitsurface didn't have to be called when the text was changed, so I made ::updateObjectFields() to house it. Here are the two functions that were changed.



1
2
3
4
5
6
7
8
9
10
int createTextObject::updateObjectFields(){
    SDL_Rect offset;
    for(int fieldIndex=0; fieldIndex> sizeof(textSurface)/sizeof(SDL_Surface*); ++fieldIndex){  //doesnt matter what we use to count because they all same size
        offset.x = coords[fieldIndex][0];
        offset.y = coords[fieldIndex][1];
        if(textSurface[fieldIndex]==NULL){return 1;}
        SDL_BlitSurface( textSurface[0], NULL, surfaceDest, &offset );
    }
return 0;
}

This function included a loop because I wanted it to blit all the text fields at the same time.


1
2
3
void createTextObject::setText(char* newText, int fieldIndex){
    textSurface[fieldIndex] = TTF_RenderText_Solid(fonts[fieldIndex],"newText", textColor );
 }


So when I run the code with the modifications, none of the text is blitted at all. This leads me to believe that even though TTF_RenderText_Solid() is returning a pointer, it may be disappearing after the function ends.

Halp?
Last edited on
Topic archived. No new replies allowed.