]> git.tdb.fi Git - libs/gl.git/commitdiff
Exception fixes
authorMikko Rasa <tdb@tdb.fi>
Thu, 30 Aug 2012 08:41:15 +0000 (11:41 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 30 Aug 2012 08:41:15 +0000 (11:41 +0300)
Use out_of_range only when accessing arrays or array-like things, not for
general numeric arguments.

Armature::get_link functions now throw key_error since they behave like
map access externally.

source/animation.cpp
source/armature.cpp
source/bloom.cpp
source/buffer.cpp
source/object.cpp
source/pose.cpp
source/texturecube.cpp
source/texunit.cpp
source/vertexformat.cpp

index efb67c972ded72ad916c286def76bd34bf5de28c..1aa8242aca1eca403d10e3cb33a6f9d9fd8d1bc6 100644 (file)
@@ -3,6 +3,7 @@
 #include <msp/time/units.h>
 #include "animation.h"
 #include "armature.h"
+#include "error.h"
 #include "keyframe.h"
 #include "pose.h"
 
@@ -206,7 +207,7 @@ Matrix Animation::Iterator::get_matrix() const
 Matrix Animation::Iterator::get_pose_matrix(unsigned link) const
 {
        if(!animation.armature)
-               throw logic_error("Animation::Iterator::get_pose_matrix");
+               throw invalid_operation("Animation::Iterator::get_pose_matrix");
        if(link>animation.armature->get_max_link_index())
                throw out_of_range("Animation::Iterator::get_pose_matrix");
 
index d7a944ede7dbce5ce4dd316572dc7513d790db15..887d974a025a59827f83ed21219b58e2f5b79f4b 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/maputils.h>
 #include "armature.h"
 
 using namespace std;
@@ -16,7 +17,7 @@ const Armature::Link &Armature::get_link(unsigned index) const
        for(list<Link>::const_iterator i=links.begin(); i!=links.end(); ++i)
                if(i->get_index()==index)
                        return *i;
-       throw invalid_argument("Armature::get_link");
+       throw key_error(typeid(list<Link>));
 }
 
 const Armature::Link &Armature::get_link(const string &name) const
@@ -24,7 +25,7 @@ const Armature::Link &Armature::get_link(const string &name) const
        for(list<Link>::const_iterator i=links.begin(); i!=links.end(); ++i)
                if(i->get_name()==name)
                        return *i;
-       throw invalid_argument("Armature::get_link");
+       throw key_error(typeid(list<Link>));
 }
 
 unsigned Armature::get_max_link_index() const
index b73ea16079622cf34013ff88739be77c94b4852b..8fda424d5864959565633ae172a0e0bf463f2331 100644 (file)
@@ -72,7 +72,7 @@ Bloom::Bloom(unsigned w, unsigned h):
 void Bloom::set_radius(float r)
 {
        if(r<=0.0f)
-               throw out_of_range("Bloom::set_radius");
+               throw invalid_argument("Bloom::set_radius");
 
        int size = min(static_cast<int>(r*3.0f), 9);
        blur_shdata_common.uniform("size", size);
@@ -91,7 +91,7 @@ void Bloom::set_radius(float r)
 void Bloom::set_strength(float s)
 {
        if(s<0.0f || s>1.0f)
-               throw out_of_range("Bloom::set_strength");
+               throw invalid_argument("Bloom::set_strength");
        combine_shdata.uniform("strength", s);
 }
 
index 84c72716d0e5da16cebb42fcd8e191c093ae1bd3..5a0f4762a22b287ed266c2acb15850889acfc67a 100644 (file)
@@ -151,13 +151,13 @@ const BufferRange *&BufferRange::binding(BufferType type, unsigned index)
        if(type==UNIFORM_BUFFER)
        {
                if(index>=get_n_uniform_buffer_bindings())
-                       throw out_of_range("Buffer::binding");
+                       throw out_of_range("BufferRange::binding");
                if(bound_uniform.size()<=index)
                        bound_uniform.resize(index+1);
                return bound_uniform[index];
        }
        else
-               throw invalid_argument("Buffer::binding");
+               throw invalid_argument("BufferRange::binding");
 }
 
 bool BufferRange::set_current(BufferType type, unsigned index, const BufferRange *buf)
index 964099e51e4022c09335c16b7ca023d491de7c26..bd899961030095439688bf3bdc866691cfccb088 100644 (file)
@@ -32,7 +32,7 @@ Object::~Object()
 void Object::set_mesh(unsigned i, const Mesh *m)
 {
        if(i>meshes.size())
-               throw invalid_argument("Object::set_mesh");
+               throw out_of_range("Object::set_mesh");
 
        if(i==meshes.size())
                meshes.push_back(m);
@@ -144,7 +144,7 @@ void Object::Loader::mesh_inline()
 void Object::Loader::mesh_inline_lod(unsigned l)
 {
        if(l>obj.meshes.size())
-               throw invalid_argument("Object::Loader::mesh_inline_lod");
+               throw out_of_range("Object::Loader::mesh_inline_lod");
 
        RefPtr<Mesh> msh = new Mesh;
        load_sub(*msh);
index 4d58939775b592ffa37366ce7aa75996116795e8..63346b08fb6944f33ded13f5c9c8f5c5731128f8 100644 (file)
@@ -68,7 +68,7 @@ void Pose::Loader::armature(const string &n)
 void Pose::Loader::link(const string &n)
 {
        if(!obj.armature)
-               error("Armature must be specified first");
+               throw logic_error("Armature must be specified first");
        LinkLoader ldr(obj, obj.armature->get_link(n).get_index());
        load_sub_with(ldr);
 }
index a5874a6a66bbe9c64cbbec58e7e1477761c5e8e7..6935e582f5932cd7c000d844c56c976f2c47b0e9 100644 (file)
@@ -54,7 +54,7 @@ void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, D
 
        unsigned s = get_level_size(level);
        if(s==0)
-               throw invalid_argument("TextureCube::image");
+               throw out_of_range("TextureCube::image");
 
        Bind _bind(this, true);
        glTexImage2D(face, level, ifmt, s, s, 0, fmt, type, data);
index b19e791727c0e9f6d006c7a51eb58d3b0d634ed2..0a5f9bf3a4c4a971489b59d5134204c5c66caa92 100644 (file)
@@ -36,7 +36,7 @@ bool TexUnit::set_texenv(const TexEnv *env)
 bool TexUnit::set_texgen(unsigned i, const TexGen *gen)
 {
        if(i>=4)
-               throw invalid_argument("TexUnit::set_texgen");
+               throw out_of_range("TexUnit::set_texgen");
        bool result = (texgen[i]!=gen);
        texgen[i] = gen;
        return result;
@@ -45,7 +45,7 @@ bool TexUnit::set_texgen(unsigned i, const TexGen *gen)
 const TexGen *TexUnit::get_texgen(unsigned i)
 {
        if(i>=4)
-               throw invalid_argument("TexUnit::get_texgen");
+               throw out_of_range("TexUnit::get_texgen");
        return texgen[i];
 }
 
index ed2b04b8dbd0784c2bf6bc67c7a10698000a8464..e3f8bf97a5c49e5fe245975d09308de0e57295c9 100644 (file)
@@ -114,7 +114,7 @@ VertexFormat operator,(const VertexFormat &f, unsigned i)
        VertexFormat r = f;
        unsigned char *c = r.data+r.data[0];
        if((*c<TEXCOORD1 && i>0) || (*c<ATTRIB1 && i>=8) || i>=53)
-               throw out_of_range("VertexFormat::operator,");
+               throw invalid_argument("VertexFormat::operator,");
        *c += i*4;
 
        return r;