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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:55:31+00:00 2026-06-03T17:55:31+00:00

Ok, I think I know what is wrong, but I don’t know how to

  • 0

Ok, I think I know what is wrong, but I don’t know how to fix this.

LoadResource is returning text from multiple resources.

(These are resources compiled into my EXE by MINGW’s ‘winres’ utility.)
(This is NOT an OpenGL question.)

I am trying to load the text of a shader into memory from a resource stored in the EXE.

Here are the relivant pieces of code:

Where I am calling my function from:

void SetupDisplay() {
    UINT vShader = LoadShaderResource (VERTEX1, GL_VERTEX_SHADER);
    UINT fShader = LoadShaderResource (FRAGMENT1, GL_FRAGMENT_SHADER);

….

The top half where it’s starting the process of loading the shader….
(I put a bunch of stuff in here trying to locate the problem, I walked back until I found this:

UINT LoadShaderResource (int index, int type) {
    std::vector<std::string> Lines;
    std::string tShader = LoadTextFileResource(index);
    std::cerr << "-------BEGIN " << index << "\n";
    std::cerr <<  tShader;
    std::cerr << "-------END\n";
    std::istringstream iss(tShader);

… the rest isn’t relivant, the shader complie crashes, at the bottom is the diagnostics this produces as to why. I use istringstream because I get all the text back in one big glob, but that’s not the issue, (I have code that follows this that splits it.) the issue is both files get included at the same time when they are not supposed to be, at least for one of them, my guess is how they are stored, but I don’t know how to fix this.

Ok, Maybe something needs to be done here?

std::string LoadTextFileResource(int name) {
    HMODULE handle = GetModuleHandleA(NULL);
    HRSRC rc = FindResourceA(handle, MAKEINTRESOURCE(name),  RT_RCDATA);
    HGLOBAL rcData = LoadResource(handle, rc);
    std::string result = (const char*) LockResource(rcData);
    return result;
 }

Ok, that’s all the C++ code, now for the resouce stuff:

resource.rc

// Generated by ResEdit 1.5.11
// Copyright (C) 2006-2012
// http://www.resedit.net

#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"


LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
VERTEX1        RCDATA         "..\\Data\\shader.vert"


LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
FRAGMENT1      RCDATA         "..\\Data\\shader.frag"


//
// Icon resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDI_ICON1          ICON           "..\\Data\\Generic.ico"

…. I show the icon only so you can see what is following, the rest is version info and such.

My resource.h file to link my code to the resource.rc file:

#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif

#define IDI_ICON1                               100
#define VERTEX1                                 110
#define FRAGMENT1                               120

Now, the text of the shaders. (remember, this is not an OpenGL question.)

shader.frag

#version 330
#pragma optimize(off)
#pragma debug(on)

smooth in vec3 theColor;
out vec4 outputColor;

void main()
{
    outputColor = vec4(theColor, 1.0);
}

shader.vert

#version 330
#pragma optimize(off)
#pragma debug(on)

layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec3 inColor;

smooth out vec3 theColor;

void main()
{
    gl_Position = vec4(inPosition, 1.0);
    theColor = inColor;
}

Ok, with all that out of the way, here is what it produces. (including the double spacing.)

-------BEGIN 110
#version 330

#pragma optimize(off)

#pragma debug(on)



layout (location = 0) in vec3 inPosition;

layout (location = 1) in vec3 inColor;



smooth out vec3 theColor;



void main()

{

    gl_Position = vec4(inPosition, 1.0);

    theColor = inColor;

}

#version 330

#pragma optimize(off)

#pragma debug(on)



smooth in vec3 theColor;

out vec4 outputColor;



void main()

{

    outputColor = vec4(theColor, 1.0);

}

-------END
-------BEGIN 120
#version 330

#pragma optimize(off)

#pragma debug(on)



smooth in vec3 theColor;

out vec4 outputColor;



void main()

{

    outputColor = vec4(theColor, 1.0);

}

-------END

Ok, now if you notice, BEGIN 110 contains both shaders, where BEGIN 120 does not.
Of course, both shaders in the 110 is what is blowing things up. What I can not understand is where is
it getting both shaders from in 110?

There is something going on here I do not understand, but I am lost as what to look at next.

  • 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-03T17:55:36+00:00Added an answer on June 3, 2026 at 5:55 pm

    In LoadTextFileResource() you copy the resource data into a std::string using std::string::operator=(const char*). This operator assumes that your string is null-terminated. But the pointer you give it is not necessarily pointing to a null-terminated string. To fix this, you need to call SizeofResource() to determine the actual lenght of the string:

    std::string LoadTextFileResource(int name) {
        HMODULE handle = GetModuleHandleA(NULL);
        HRSRC rc = FindResourceA(handle, MAKEINTRESOURCE(name),  RT_RCDATA);
        HGLOBAL rcData = LoadResource(handle, rc);
        DWORD data_size = ::SizeofResource(handle, rc);
    
        std::string result;
    
        if (data_size != 0) {
            const char* data = (const char*)::LockResource(rcData);
            result.assign(data, data_size);
        }
    
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this has been asked before , but I don't think these solutions
I know I do many, many things wrong in this, but I don't have
I think know how to do this in C# but I'm having syntax trouble
Well I think I know the answer to this, but I would appreciate anybody
I think I already know the answer to this but thought I would ask
I think i already know the answer to this, but i cannot find anything
Perhaps I'm doing it wrong but I don't think WPF or GDI+ classes are
Honestly, I don't know a lot about PHP but I think what I need
I don't know what is wrong with this code. I have the following, very
I think the mistake i'm doing it's so stupid but i don't know what

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.