Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

Techie

Alter Hase

  • »Techie« ist der Autor dieses Themas

Beiträge: 717

Wohnort: Bayreuth

Beruf: Student | Hilfswissenschaftler in der Robotik

  • Private Nachricht senden

1

23.07.2013, 14:56

WinAPI wRap des Todes....

Hallo,
ich schreib mal wieder an meinem WinAPI wrapper herum.
Den Code habe ich, im vergleich zum letzten mal etwas umgestaltet.
Leider bekomme ich ständig Expections um die Ohren geworfen...

RoE.cpp :

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#pragma once
#pragma comment( lib, "ClockGear.lib ")
#define CGUSE

#include "Engine\ClockGear.h"

int main()
{
    AppDX9* pApp = new AppDX9(L"Rise of Empires");
    pApp->Create( L"Rise of Empires", 600, 400, 32, false );
    while( !(pApp->Exec()) )
    {
    };
    return 0;
}


ClockGear.h

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#pragma once

#ifdef _MSC_VER
#   ifndef CGUSE
#       define CGAPI __declspec( dllexport )
#   else
#       define CGAPI __declspec( dllimport )
#       pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#   endif

#   ifdef _DEBUG
#       define D3D_DEBUG_INFO
#   endif 

#   include <Windows.h>
#   include <d3d9.h>

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

#endif


// Engine includes
#include "AppDX9.h"


AppDX9:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#pragma once

class CGAPI AppDX9
{
private:

    HWND m_hWnd; // Handle of the Window
    static LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );

public:
    // Construktor
    AppDX9( const wchar_t* pnCaption );

    // Methods
    HWND Create(    const wchar_t* pcTitle,
            const int nWidth,
            const int nHeight,
            const int nCBit,
            bool bFullscreen );

    void Destroy();

    int Exec();
    

};


AppDX9.cpp :

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include "ClockGear.h"
/*
    The order of the definition is the same as  declared in AppDX9.h
*/

LRESULT AppDX9::WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    AppDX9* pApp = NULL;

    if( msg == WM_NCCREATE )
        SetWindowLongPtr( hWnd, GWL_USERDATA, (long)(LPCREATESTRUCT(lParam)->lpCreateParams ) );

    pApp = ( AppDX9* ) GetWindowLongPtr( hWnd, GWL_USERDATA );

    switch( msg )
    {
    case WM_DESTROY:
        // pApp->Destroy();
        PostQuitMessage(0);
        return 0;
        break;
    }


    return DefWindowProc( hWnd, msg, wParam, lParam );
}

AppDX9::AppDX9(  const wchar_t* pcCaption )
{
    WNDCLASSEX wc;
    ZeroMemory( &wc, sizeof( WNDCLASSEX ));
    wc.cbSize       = sizeof( WNDCLASSEX );
    wc.style        = CS_VREDRAW | CS_HREDRAW;
    wc.lpfnWndProc  = WndProc;
    wc.hInstance    = GetModuleHandle( NULL );
    wc.lpszClassName= (LPCUWSTR) pcCaption;

    if( !RegisterClassEx( &wc ))
    {
        MessageBox( NULL, L" Failed to register Class! ", L"Error! ClockGear-Engine ", MB_OK );
        return;
    }

}

HWND AppDX9::Create(    const wchar_t* pcTitle,
                        const int nWidth,
                        const int nHeight,
                        const int nCBit,
                        bool bFullscreen )
{
    this->m_hWnd = CreateWindowEx(  NULL,
                                    (LPCWSTR) pcTitle,
                                    (LPCWSTR) pcTitle,
                                    WS_OVERLAPPEDWINDOW,
                                    0,
                                    0,
                                    nWidth,
                                    nHeight,
                                    NULL,
                                    NULL,
                                    GetModuleHandle( NULL ),
                                    this );

    ShowWindow( this->m_hWnd, SW_SHOWDEFAULT );
    return this->m_hWnd;

}

void AppDX9::Destroy()
{
    DestroyWindow( this->m_hWnd );
    return;
}

int AppDX9::Exec()
{
    MSG* pMsg = new MSG;
    while( PeekMessage( pMsg, this->m_hWnd, 0, 0, PM_REMOVE ))
    {
        TranslateMessage( pMsg );
        DispatchMessage( pMsg );
    }
    if( pMsg->message == WM_DESTROY ) 
        return -1;
    return 0;
}


Bei mir heißt es immer "badd_alloc".
Ich bin mir nicht sicher was dieß hei0en soll.
Entweder mache ich da etwas mit dem "new"-Operator falsch oder es liegt and WndProc-prozedur.

Könnt ihr mir helfen?

Gruß Techie
P.S.: Hoffentlich nerve ich nicht mit meinen ganzen Threads...
I write my own game engines because if I'm going to live in buggy crappy filth, I want it to me my own - Ron Gilbert

BlueCobold

Community-Fossil

Beiträge: 10 738

Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer

  • Private Nachricht senden

2

23.07.2013, 15:05

Ich kann zu Deinem Problem nicht viel sagen, aber Zeile 79 in AppDX9.cpp ist großer Mist und erzeugt haufenweise Speicherlöcher.
Teamleiter von Rickety Racquet (ehemals das "Foren-Projekt") und von Marble Theory

Willkommen auf SPPRO, auch dir wird man zu Unity oder zur Unreal-Engine raten, ganz bestimmt.[/Sarkasmus]

patrick246

Treue Seele

Beiträge: 328

Wohnort: nahe Heilbronn/BW

Beruf: TG Profil Informatik-Schüler

  • Private Nachricht senden

3

23.07.2013, 15:16

Du reservierst immer wieder Speicher mit new, gibt ihn aber nie wieder frei. Entweder du nimmst den Stack dafür oder du benutzt Smart-Pointer.

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
    MSG pMsg;
    while( PeekMessage( &pMsg, this->m_hWnd, 0, 0, PM_REMOVE ))
    {
        TranslateMessage( &pMsg );
        DispatchMessage( &pMsg );
    }
    if( pMsg.message == WM_DESTROY ) 
        return -1;
    return 0;

Techie

Alter Hase

  • »Techie« ist der Autor dieses Themas

Beiträge: 717

Wohnort: Bayreuth

Beruf: Student | Hilfswissenschaftler in der Robotik

  • Private Nachricht senden

4

23.07.2013, 15:33

Fail, ist mir gar nicht aufgefallen das ich MSG ständig neu alloziere ( wird das so geschrieben ? ).
Beim main is' es mir aufgefallen aufgefallen.

Ich habe jetzt "delete" eingefügt, jetzt bleibt nur noch ein Problem:
VSC++ 2012 scheint den Debugmodus bei Beendigung des Programms nicht verlassen zu wollen.

Aufhedenfall vielen Dank an BlueCobold und patrick.

Gruß Techie
I write my own game engines because if I'm going to live in buggy crappy filth, I want it to me my own - Ron Gilbert

Tobiking

1x Rätselkönig

  • Private Nachricht senden

5

23.07.2013, 16:03

Deine Anwendung läuft halt weiter, auch wenn alle Fenster geschlossen wurden. Als Tipp: WM_DESTROY ist nicht die letzte Nachricht, die gesendet wird.

Techie

Alter Hase

  • »Techie« ist der Autor dieses Themas

Beiträge: 717

Wohnort: Bayreuth

Beruf: Student | Hilfswissenschaftler in der Robotik

  • Private Nachricht senden

6

23.07.2013, 16:15

Oh Gott, das wird mir langsam peinlich, dass ich selbst solch einfach aufgaben nicht gebacken kriege.....

Nun, soll ich dann den Code:
if( msg->message == WM_DESTROY )

In die PeekMessage-Schleife integrieren?
I write my own game engines because if I'm going to live in buggy crappy filth, I want it to me my own - Ron Gilbert

Werbeanzeige