Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7018415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:02:53+00:00 2026-05-27T23:02:53+00:00

For some reason, my variable filename changes by the time it gets to setupView

  • 0

For some reason, my variable filename changes by the time it gets to setupView to filename from a more recent instance of the class and i cant figure out why. I just started learning obj-C, so im assuming im doing some sort of rookie mistake.

They are instantiated by:

campusMapTileZero=[[CampusMapTile alloc] initNameOfTiletoLoad:@"cm0"];
campusMapTileOne=[[CampusMapTile alloc] initNameOfTiletoLoad:@"cm1"];

and the implementation im referring to is:

#import "CampusMapTile.h"
#import "TileManager.h"
#import "GLView.h"
#import "OpenGLCommon.h"
#import "ConstantsAndMacros.h"


@implementation CampusMapTile
NSString *filename;
- (id) initNameOfTiletoLoad: (NSString *)filename 
{
    if(self = [super init]) {
        NSLog(@"initialized map tile for tile:");
        NSLog(filename);
        [self setTile:filename];
    }
    return self;
}

-(void)setTile:(NSString*) _filename {
    NSLog(@"set tile called from setTile.");
    filename=_filename;
    NSLog(@"filename in setTile is:");
    NSLog(filename);
}



- (void)drawView:(GLView*)view 
{
    glBindTexture(GL_TEXTURE_2D, texture[0]);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);


    static const Vertex3D vertices[] = {
        {0,0, 1}, //TL
        { 1024,0, 1}, //TR
        {0,-1024, 1}, //BL
        { 1024.0f, -1024.0f, 1}  //BR
    };


    static const GLfloat texCoords[] = {
        0.0, 1.0,
        1.0, 1.0,
        0.0, 0.0,
        1.0, 0.0
    };

    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);

}

- (void)setupView:(GLView*)view {   
    NSLog(@"setup view called");
    NSLog(filename);
    [self loadTextures:filename textureIdentifier:0];

}

-(void)loadTextures:(NSString*) filename textureIdentifier:(int) textureNumber {
    //enable textures.
    glEnable(GL_TEXTURE_2D);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_FASTEST);
    glEnable(GL_BLEND); 
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    // Bind the number of textures we need.
    glGenTextures(1, &texture[textureNumber]);
    glBindTexture(GL_TEXTURE_2D, texture[textureNumber]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 

    //    [tileManager setupView:view];    
    NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:@"jpg"];
    NSData *texData = [[NSData alloc] initWithContentsOfFile:path];
    UIImage *image = [[UIImage alloc] initWithData:texData];

    if (image == nil)
        NSLog(@"Do real error checking here");

    GLuint width = CGImageGetWidth(image.CGImage);
    GLuint height = CGImageGetHeight(image.CGImage);
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    void *imageData = malloc( height * width * 4 );
    CGContextRef context = CGBitmapContextCreate( imageData, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big );

    // Flip the Y-axis
    CGContextTranslateCTM (context, 0, height);
    CGContextScaleCTM (context, 1.0, -1.0);

    CGColorSpaceRelease( colorSpace );
    CGContextClearRect( context, CGRectMake( 0, 0, width, height ) );
    CGContextDrawImage( context, CGRectMake( 0, 0, width, height ), image.CGImage );

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);

    CGContextRelease(context);

    free(imageData);
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:02:53+00:00Added an answer on May 27, 2026 at 11:02 pm

    The problem is that your filename variable is a global variable, not an instance variable.

    You need to delete your existing NSString* filename declaration and instead declare filename in your class’s @interface block, like so:

    @interface CampusMapTile : UIViewController {
        NSString* filename;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a BOOL instance variable which -for some reason- some time later always
For some reason I have always assumed that most of the time a variable
For some reason when I return from the signal handler for SIGFPE, the variable
I'm assigning a variable string from an XML node and for some reason when
I'm trying to get a variable from the URL, but for some reason, I
For some unknown reason I'm running into a problem when passing a variable to
For some reason I've having problems reading this session variable within an ajax document,
I am using some python to do some variable name generation. For some reason
For some reason this isn't storing the variable correctly giving me a value of
For some reason when I call a namespace within this class, I get an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.