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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:30:16+00:00 2026-06-13T08:30:16+00:00

I currently have a class called TextureObject. In the creation function I create the

  • 0

I currently have a class called TextureObject. In the creation function I create the texture, and assign a LPCSTR in the class to a parameter given in the function. When I return that LPCSTR later, it returns in an unexpected manner.

Some type names and functions are from DirectX 11, just ignore them.

Code:

The h File:

class TextureObject
{
public:
    ID3D11ShaderResourceView *pTexture;
    LPCSTR GetFilename() const { return *FFilename; }

    bool IsNotNull;
    void CreateTexture(ID3D11Device &dev,LPCSTR Filename);
    void ReCreate(ID3D11Device &dev);
    void Release();
    int relativeId;
private:
    LPCSTR *FFilename;
};

The cpp file:

void TextureObject::CreateTexture(ID3D11Device &dev,LPCSTR Filename)
{
    D3DX11CreateShaderResourceViewFromFile(
            &dev,        // the Direct3D device
            Filename,    // load Wood.png in the local folder
            NULL,        // no additional information
            NULL,        // no multithreading
            &pTexture,   // address of the shader-resource-view
            NULL);       // no multithreading
    FFilename = new LPCSTR(Filename);
    IsNotNull = true;
}

void TextureObject::ReCreate(ID3D11Device &dev)
{
    CreateTexture(dev, *FFilename);
}

When using vs 2012 debugger in the CreateTexture function, the Filename debugger values are:

0x0a06fed0 "C:\Users\Utilizador\Desktop\particle.png"

Which is perfect for me! When i assign the class’s FFilename:

FFilename = new LPCSTR(Filename);

It’s ok. When I check the value of FFilename within the scope of this function, it’s the same value of the Filename. But when i use GetFilename, things start getting crazy:

 = 0x0a06fed0 "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþü =I.C"

Mmm, I just met you, and this is crazy, but… Here’s my value. mKay?

Well, please help me. Thank You

  • 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-06-13T08:30:17+00:00Added an answer on June 13, 2026 at 8:30 am

    You are not copying the string. You are copying the pointer. I think you probably wanted to copy the string, because you cannot guarantee the caller’s pointer will still reference valid data at a later time.

    LPCSTR is just a const char*. There’s probably a corresponding windows call, but I would just use strdup to copy the string.

    Define FFilename as LPCSTR:

    LPCSTR FFilename;
    

    And then:

    void TextureObject::CreateTexture(ID3D11Device &dev,LPCSTR Filename)
    {
        D3DX11CreateShaderResourceViewFromFile(
                &dev,        // the Direct3D device
                Filename,    // load Wood.png in the local folder
                NULL,        // no additional information
                NULL,        // no multithreading
                &pTexture,   // address of the shader-resource-view
                NULL);       // no multithreading
        FFilename = strdup(Filename);
        IsNotNull = true;
    }
    
    void TextureObject::ReCreate(ID3D11Device &dev)
    {
        CreateTexture(dev, FFilename);
    }
    

    Since you are using C++, you are free to use std::string instead, which will be cleaned up automatically when the object is destroyed.

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

Sidebar

Related Questions

Currently I have a class called user that I want to create with different
I currently have a class called clientActivity that contains a finger paintig activity that
I have a class currently called Promise that works as follows: It holds a
I'm currently working on an OO PHP application. I have a class called validation
Currently I have a class that looks like this: public class MyClass : IMyClass
Currently I have a class that is extending the ListActivity class. I need to
We currently have a utilities class that handles a lot of string formatting, date
I currently have a helper class that I am using to obfuscate a static
I have a class called 'Constants' that I am storing a String variable in.
The goal is to have a singleton data controller class called FetchData.h/.m that pulls

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.