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

  • Home
  • SEARCH
  • 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 623373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:05:10+00:00 2026-05-13T19:05:10+00:00

[Edit] Note: These projects are projects that I have copied and renamed. Not sure

  • 0

[Edit]
Note: These projects are projects that I have copied and renamed. Not sure if that would have anything to do with it.

I am using the directx sdk and just playing around with it. I was trying to blit a image on to the screen by loading a external file. For some reason it does not work when I build it and run in debug. But If I go to the debug folder and open the exe file. It works. I am not sure why. Here is my code

#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <time.h>
#include <iostream>
using namespace std;

#pragma comment(lib,"d3d9.lib")
#pragma comment(lib, "d3dx9.lib")

const string APPTITLE = "Game Loop";
const int SCREENW = 1024;
const int SCREENH = 768;

bool gameover = false;

LPDIRECT3D9 d3d             = NULL;
LPDIRECT3DDEVICE9 d3ddev    = NULL;
LPDIRECT3DSURFACE9 surface  = NULL;
LPDIRECT3DSURFACE9 backbuffer = NULL;

#define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

bool Game_Init(HWND window)
{
    MessageBox(window, "Game_Init", "BREAKPOINT",0);
    //Initialize

    d3d = Direct3DCreate9(D3D_SDK_VERSION);
    if(d3d == NULL)
    {
        MessageBox(window, "Error Initializing", "ERROR",MB_OK);
        return 0;
    }

    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferCount = 1;
    d3dpp.BackBufferWidth = SCREENW;
    d3dpp.BackBufferHeight = SCREENH;
    d3dpp.hDeviceWindow = window;
    d3dpp.Windowed = TRUE;

    d3d->CreateDevice(
        D3DADAPTER_DEFAULT,
        D3DDEVTYPE_HAL,
        window,
        D3DCREATE_SOFTWARE_VERTEXPROCESSING,
        &d3dpp,
        &d3ddev
        );

    if(d3ddev == NULL)
    {
        MessageBox(window, "Error Creating Device", "ERROR",MB_OK);
        return 0;
    }

    srand(time(NULL));

    d3ddev->Clear(0,NULL,D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,255,0), 1.0f,0);

    d3ddev->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);
    HRESULT result = d3ddev->CreateOffscreenPlainSurface(
        SCREENW,SCREENH,
        D3DFMT_X8R8G8B8,
        D3DPOOL_DEFAULT,
        &surface,
        NULL);
    if(!SUCCEEDED(result)) return false;

    result = D3DXLoadSurfaceFromFile(
        surface,
        NULL,NULL,
        "legotron.bmp",
        NULL,
        D3DX_DEFAULT,
        0,
        NULL);

    if(!SUCCEEDED(result))
    {
        MessageBox(window, "Error Loading Image", "ERROR",MB_OK);
        return false;
    }

    return true;
}

void Game_Run(HWND hwnd)
{
    if(!d3ddev) return;

    d3ddev->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);

    if(d3ddev->BeginScene())
    {

        d3ddev->StretchRect(surface, NULL, backbuffer, NULL, D3DTEXF_NONE);

        d3ddev->EndScene();
        d3ddev->Present(NULL,NULL,NULL,NULL);
    }

    if(KEY_DOWN(VK_ESCAPE))
        PostMessage(hwnd, WM_DESTROY,0,0);
}

void Game_End(HWND hwnd)
{
    if(surface) surface->Release();
    if(d3ddev)d3ddev->Release();
    if(d3d)d3d->Release();
}

LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM WParam, LPARAM lparam)
{
    switch(message)
    {
        case WM_DESTROY:
            gameover = true;
            PostQuitMessage(0);
            return 0;
        break;
    }

    return DefWindowProc(hWnd, message, WParam, lparam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                  LPSTR lpCmdLine, int nCmdShow)
{
        //set the new windows properties

    WNDCLASSEX wc;

    wc.cbSize       = sizeof(WNDCLASSEX);
    wc.style        = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc  = (WNDPROC) WinProc;
    wc.cbClsExtra   = 0;
    wc.cbWndExtra   = 0;
    wc.hInstance    = hInstance;
    wc.hIcon        = NULL;
    wc.hCursor      = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName= APPTITLE.c_str();
    wc.hIconSm      = NULL;

    RegisterClassEx(&wc);

    HWND window = CreateWindow(
        APPTITLE.c_str(),
        APPTITLE.c_str(),
        WS_OVERLAPPED,
        CW_USEDEFAULT, CW_USEDEFAULT,
        SCREENW,SCREENH,
        NULL,
        NULL,
        hInstance,
        NULL);

    if(window == 0) return 0;

    //display the window 
    ShowWindow(window, nCmdShow);
    UpdateWindow(window);

    //initialize the game
    if(!Game_Init(window)) return 0;

    MSG message;

    //main message loop
    while(!gameover)
    {
        if(PeekMessage(&message,NULL, 0, 0,PM_REMOVE))
        {
            TranslateMessage(&message);
            DispatchMessage(&message);
        }
        Game_Run(window);
    }

    Game_End(window);

    return message.wParam;
}

I have it where it closes the application if the image fails to load.

result = D3DXLoadSurfaceFromFile(
            surface,
            NULL,NULL,
            "legotron.bmp",
            NULL,
            D3DX_DEFAULT,
            0,
            NULL);

        if(!SUCCEEDED(result))
        {
            MessageBox(window, "Error Loading Image", "ERROR",MB_OK);
            return false;
        }

the window stays open (but no image) if I remove the return false line. so apparently it fails there. The image is located in the same folder as the .exe file (within the debug folder) as it should. cause i havnt done anything to tell it to go anywhere else otherwise. Again it works when I personally open the .exe file within the debug folder. but does not work in the ide when I build it and try to run it.

[EDIT]

I Built the application from scratch and ran it. Still doesnt work.

  • 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-13T19:05:10+00:00Added an answer on May 13, 2026 at 7:05 pm

    The current folder isn’t necessarily the folder where your .exe file is. Check the Debugging page of the project options and make sure the working folder is what you expect.

    When you run the program in debug, you’re running the same .exe file from that debug folder, but visual studio sets up the environment it runs in – working folder included. You know the program runs, therefore most likely the environment is at fault.

    Programs that work as a release build but not debug happen occasionally, usually meaning there’s a memory corruption. Programs where the same build works when called one way but not another are rarer, but can happen. These things are a nightmare to debug.

    I doubt that’s the problem here though.

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

Sidebar

Related Questions

I need to solve the following question which i can't get to work by
I want to get the header of a selected tab-item of a tab-control and

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.