From 9e7d07e0c13db303978d8dd09129081be74b0ec0 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sat, 8 Nov 2014 13:56:32 +0100 Subject: [PATCH] Add fbo source protection against not allocating in derived classes --- src/Sources/FboSource.cpp | 9 ++++++++- src/Sources/FboSource.h | 13 +++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Sources/FboSource.cpp b/src/Sources/FboSource.cpp index f64236b..a866366 100644 --- a/src/Sources/FboSource.cpp +++ b/src/Sources/FboSource.cpp @@ -3,7 +3,7 @@ namespace ofx { namespace piMapper { FboSource::FboSource() : fbo(NULL) { - name = PIMAPPER_DEF_FBO_SOURCE_NAME; + name = PIMAPPER_FBO_SOURCE_DEF_NAME; loadable = false; loaded = false; type = SourceType::SOURCE_TYPE_FBO; @@ -32,6 +32,13 @@ namespace ofx { void FboSource::onAppSetup(ofEventArgs &args) { ofRemoveListener(ofEvents().setup, this, &FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP); setup(); + + // Check if FBO was allocated in user defined setup + // If not, show warning and alocate to avoid panic + if (!fbo->isAllocated()) { + ofLogWarning("FboSource::onAppSetup") << "FBO not allocated, allocating with default values"; + allocate(PIMAPPER_FBO_SOURCE_DEF_WIDTH, PIMAPPER_FBO_SOURCE_DEF_HEIGHT); + } } void FboSource::onAppUpdate(ofEventArgs &args) { diff --git a/src/Sources/FboSource.h b/src/Sources/FboSource.h index 2a27ded..3e3a3a5 100644 --- a/src/Sources/FboSource.h +++ b/src/Sources/FboSource.h @@ -10,7 +10,9 @@ class YourGenerativeSource : public FboSource { #include "ofMain.h" #include "BaseSource.h" -#define PIMAPPER_DEF_FBO_SOURCE_NAME "FBO Source" +#define PIMAPPER_FBO_SOURCE_DEF_NAME "FBO Source" +#define PIMAPPER_FBO_SOURCE_DEF_WIDTH 500 +#define PIMAPPER_FBO_SOURCE_DEF_HEIGHT 500 namespace ofx { namespace piMapper { @@ -38,12 +40,15 @@ namespace ofx { virtual void draw() {}; // But this is the only place where you shoud do drawing virtual void exit() {}; - // Use these to set up FBo itself - void allocate(int width, int height); - void clear(); // The only method from BaseSource to be overriden + // The only method from BaseSource to be overriden + void clear(); protected: ofFbo* fbo; + + // Use this instead fbo->allocate as it sets other source related settings + // It is protected to force the user to create derived FBO sources from this + void allocate(int width, int height); }; } // namespace piMapper } // namespace ofx \ No newline at end of file