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 6117279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:18:09+00:00 2026-05-23T15:18:09+00:00

I did a poor job of explaining my original question, so here’s a second

  • 0

I did a poor job of explaining my original question, so here’s a second stab. From a top down perspective, here’s the goal:

I have a map class that is using DDXML to parse and load in an XML map file. This map file has several strings for a character to display to the player, which I am parsing and storing in the map class (as NSMutableString*). When an event triggers to load one of those messages to the player, the game loop grabs that NSMutableString*, copies it into a temporary middle-man object, which then when updates passes it finally into its rendering object. It seems crazy, but it makes a lot of sense if you see the full set of code (hah, I hope!).

I’m experiencing what SEEMS to be a memory overwrite situation… when I try to access the NSMutableString in the second or third pass (either to the temp middle-man or to the rendering object), the texture coordinates get goofy. It seems like the strings themselves are intact, but nearby memory looks hosed. I will occasionally get crashes (EXC_BAD_ADDR, or similar) in the same game loop iteration that these reads are done right before rendering.

I think this is almost certainly due to my (still) poor grasp of NSMutableStrings. By the by, I am using the mutable version as I need to edit the strings (add \n characters, for example) after they have been loaded. Here’s some relevant code snippets that may help better explain what I’m doing:

I have a TextSnippet structure used for rendering that looks similar to the following (some data omitted for brevity):

struct TextSnippet
{
    NSMutableString* string;
}

I read the map (DDXML) and store the text messages into the map object with: (message->text is defined as NSMutableString* text[MAX_TEXT_PER_MESSAGE];

message->text[i] = [NSMutableString stringWithCapacity:50];
        [message->text[i] setString:[[text attributeForName:@"text"] stringValue]];
        [message->text[i] retain];

I then do the following (note: this could be really stupid and wrong, and I’m positive I’m leaking memory like nobody’s business, but I’m just trying rapidly worse ideas, and this is the latest of the worst):

This is the middle-man tier:

// Properly copy the NSMutableString into the local message
for (int i = 0; i < m_message->count; i++)
{
    m_message->text[i] = [message->text[i] mutableCopy];
    [message->text[i] retain];
}

Finally, later in the loop I actually write to the TextSnippet structure (m_msgText in this case), so the text can be rendered:

m_msgText->string = [m_message->text[m_currentText] mutableCopy];
[m_msgText->string retain];

Like I said, I know it’s kind of nasty doing the extra copies… I’m looking into other, much more extensive rewrites to get around this, but in the interim… how SHOULD you go about doing this, if you did need to pass a NSMutableString* around so much? I suppose the problem still COULD be something else, but whenever I change the NSMutableString* data to hard-coded @”” string constants at the middle-man tier, the memory problem is not present. Doesn’t it just about have to be a problem with how I’m handling my strings here?

Thanks again to the original posters who tried to offer some help – I hope this is more informative.

  • 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-23T15:18:10+00:00Added an answer on May 23, 2026 at 3:18 pm

    I don’t know why you are getting this error (I’ve never had one), but there is some bits in your sample code that look odd (may be just my lack of C/C++ knowledge 🙂

    message->text[i++] = [[NSMutableString alloc] 
                            initWithString:[[text attributeForName:@"text"] stringValue]];
    

    I can’t find any reference to a stringValue method in the SDK. But aside from that, why not just store a reference to the NSMutableString being created? I’m also not sure what text is, but presuming that `[text attributeForName:@”text”]’ returns a NSString, I don’t think you need to get the stringValue anyway.

    m_msgText->string = [[NSMutableString alloc] 
                            initWithString:[m_message->text[m_currentText] mutableCopy]];
    

    I’m not sure why you are doing the [m_message->text[m_currentText] mutableCopy] bit. Why not just do

     m_msgText->string = [[NSMutableString alloc] 
                            initWithString:[m_message->text[m_currentText]]];
    

    becuase it will create a new NSMutableString by copying the text from [m_message->text[m_currentText]].

    Feel free to tell me I’m talking rubbish because you probably know more about mixing C/C++ and Objective C than I do 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure if this question makes for some poor performance down the track, but
Did some searches here & on the 'net and haven't found a good answer
I saw this quote in this question : MS support is poor, except when
Did you used Dynamic websites before? you see its a good way for making
Did you ever have the following situation: you need to store information, but a
Did anyone tried to customize the window in which the quicktime is playing video?
Did about 30 minutes worth of searching, found lots of relevant info, but none
Did I not get enough sleep or what? This following code var frame=document.getElementById(viewer); frame.width=100;
Did not have luck with these examples: Javascript File remove Javascript FSO DeleteFile Method
Did actually someone make already a tutorial that shows how to customize an UITableView?

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.