0

我无法在 draw(...) 方法中访问 c​​urWaitTime 变量,它会因 EXC_BAD_ACCESS 错误而崩溃。它甚至不是动态分配的!

#include <string>
#include "ofMain.h"
#include "Colour.h"
#include "ColourScheme.h"

#define NOTIFICATION_TEXT_SIZE          60
#define NOTIFICATION_FADE_OUT_TIME      2

class Notification {
private:
    char *text;
    float curWaitTime;

    void setGlColour( Colour *colourScheme, int colourType, float alphaPercentage ) {
        glColor4f( colourScheme[colourType].r,
                  colourScheme[colourType].g,
                  colourScheme[colourType].b,
                  colourScheme[colourType].a * alphaPercentage );
    }

public:
    float screenWidth, screenHeight;

    Notification( const char *_text, float width, float height  ) {
        text = new char[255];
        strcpy(text, _text);
        screenWidth = width;
        screenHeight = height;
        curWaitTime = NOTIFICATION_FADE_OUT_TIME;
        NSLog(@"Notification created!");
    }

    ~Notification() {
        delete text;
    }

    bool draw( Colour *colourScheme, ofTrueTypeFont *font, float deltaTime ) {
        // update timer
        curWaitTime -= deltaTime;
        if( curWaitTime <= 0.f ) {
            return false;
        }

        //draw
        setGlColour( colourScheme, COLOUR_BACKGROUND_COL3, curWaitTime / NOTIFICATION_FADE_OUT_TIME );
        font->drawString(text, screenWidth/2 - (font->stringWidth(text)/2), screenHeight/2);

        return true;
    }
};

这真的让我感到困惑,这通常有效。有任何想法吗?我正在使用 XCode 和带有 OpenFrameworks 的 iOS 编码

4

0 回答 0