-
ReturnFloat() crashes
I'm trying to use ReturnFloat() but for some reason, it crashes. Are there any specific reasons it would crash? Probably something common that I don't know about.
If you want some of the code I got plenty here. I get no warnings or errors on compile.
-
Re: ReturnFloat() crashes
You need to set the flag first. I'm using this:
// Set the "Float" flag
rdPtr->rHo.hoFlags |= HOF_FLOAT;
// Return the float
float fResult = 0.2123;
return *((long*)&fResult);
-
Re: ReturnFloat() crashes
rSDK ReturnFloat() sets the float flag.
-
Re: ReturnFloat() crashes
Yes, I am using the rSDK, sorry I forgot to mention that.
-
Re: ReturnFloat() crashes
I'm using the rSDK as well.
-
Re: ReturnFloat() crashes
So you mean I should avoid ReturnFloat() and instead do it the way you posted?
-
Re: ReturnFloat() crashes
Mokhtar, I did it the way you suggested, but it did not make any difference. It still crashes, same way, same spot.
I made a test expression that was just a ReturnFloat(0.123456789); and it did not crash; it worked fine. (It returned 0.123457)
So why else would it crash?
-
Re: ReturnFloat() crashes
Maybe it's not the return that's causing this. Perhaps you're accessing an array index out of bounds?
-
Re: ReturnFloat() crashes
I think it must be corruption. I put debug messages and it doesn't crash until the ReturnFloat() line, so I must be giving it some bad data. I haven't changed the code much since the pastebin I linked above..
-
Re: ReturnFloat() crashes
Quote:
Originally Posted by LB
I think it must be corruption.
Is this the PC of yours with the bad ram? Because bad ram can cause some really fun errors...
-
Re: ReturnFloat() crashes
Instead of doing debug messages, have your tried actually debugging your extension? It is described in the extension SDK help file how you do it. It really helps finding errors.
-
Re: ReturnFloat() crashes
He has, but he doesn't get it to work for whatever reason...
-
Re: ReturnFloat() crashes
Hi,
looks like a index out of bounds or casting
try float RetVal = (float)((*rdPtr->Points)[At].X);
just in case you are using VS2010 debug the previous line to check if a float value is present
Regards
-
Re: ReturnFloat() crashes
@Dynasoft: No it got so bad I couldn't use MMF2 anymore. I am on the other computer in our house (It's an annoying vista laptop, but it works and it's fast)
@Andos: I did read the instructions and followed everything to a tee, but any breakpoints I set give me a message saying they won't be met and then they indeed never get met. I tried every file, both CPP and headers. Not a single line would let me set a working breakpoint. So, I had the application running from the debugger mode but that was it.
@FVivolo: Why do I need to cast it to a float if it is already a float? I'll try anyway, just in case.
-
Re: ReturnFloat() crashes
If you are using VS2010, it did nasty behavior to me so i cast all the variable i need and it works, if you ask me why i donīt have a straight answer but it works for me, hope solve you situation too
Regards
-
Re: ReturnFloat() crashes
Quote:
Originally Posted by LB
@Andos: I did read the instructions and followed everything to a tee, but any breakpoints I set give me a message saying they won't be met and then they indeed never get met. I tried every file, both CPP and headers. Not a single line would let me set a working breakpoint. So, I had the application running from the debugger mode but that was it.
Were you building in release mode?
-
Re: ReturnFloat() crashes
No, I was building with debug. I made sure of it! ;)
-
Re: ReturnFloat() crashes
Is the debug configuration set to build to the right place?
-
Re: ReturnFloat() crashes
LB,
below some code you may add to help you to get some info during execution
in Common.h
extern void Msgx(char *szFormat, ...);
in General.cpp or Main.cpp
void Msgx(char *szFormat, ...)
{
char szBuffer[512];
va_list pArgs;
va_start(pArgs, szFormat);
vsprintf(szBuffer, szFormat, pArgs);
va_end(pArgs);
MessageBox(NULL, szBuffer, "Testing", MB_OK);
}
and finally use like this in your code
Msgx("My Result: %10d "%s %4.2f hex=0x%x", decimal, string, float1, hexa);
so you may track the index and the corresponding value
hope its help
-
Re: ReturnFloat() crashes
Quote:
Originally Posted by LB
@Andos: I did read the instructions and followed everything to a tee, but any breakpoints I set give me a message saying they won't be met and then they indeed never get met. I tried every file, both CPP and headers. Not a single line would let me set a working breakpoint. So, I had the application running from the debugger mode but that was it.
This message appears if you are not building in debug mode.
If you are, you might not have set up debugging correctly
-
Re: ReturnFloat() crashes
It will also appear if you try debugging before the MFX is loaded. I find it easiest to debug by attaching to edrt on a dummy frame and then advancing.
-
Re: ReturnFloat() crashes
Quote:
Originally Posted by Retriever2
It will also appear if you try debugging before the MFX is loaded. I find it easiest to debug by attaching to edrt on a dummy frame and then advancing.
Just use CopyRun.bat and the /f command line parameter to edrt.exe..
-
Re: ReturnFloat() crashes
I fixed the crash by doing this another way, but now I have a new problem.
I switched to using a map instead of a vector, and I used a struct (ActionpointID) for the key, and a struct (Actionpoint) for the value. This works great and ReturnFloat() no longer crashes (nothing is crashing).
But, when I try to get the X position, it returns the Y position; and when I try to get the Y position, it returns 0. I can't figure out why it's doing this, so here's what I have:
Actionpoints.h
http://paste.pocoo.org/show/255700/
This file is included in Common.h
In Common.h I included <map> and am no longer including <vector>
In Data.h, I changed the declaration of Points to:
Code:
map<ActionpointID, Actionpoint>* Points;
In Runtime.cpp, I changed the creation of Points to:
Code:
rdPtr->Points = new map<ActionpointID, Actionpoint>;
Deleting it is the same.
And in Main.cpp I have:
http://paste.pocoo.org/show/255703/
(for reference, here is ParamHelp.h which is included in Main.cpp)
-
Re: ReturnFloat() crashes
You are retrieving the coordinates wrong. When you retrieve a rotated coordinate the resulting X position will depend on both the original X and the original Y coordinate. Try using this instead:
Code:
// X
float RetVal = (*rdPtr->Points)[ID].X * cos(Angle);
RetVal += (*rdPtr->Points)[ID].Y * -sin(Angle);
RetVal *= Scale;
RetVal += HotSpot;
// Y
float RetVal = (*rdPtr->Points)[ID].X * sin(Angle);
RetVal += (*rdPtr->Points)[ID].Y * cos(Angle);
RetVal *= Scale;
RetVal += HotSpot;
You might have to change some signs though, I'm not 100% sure I got it right.
-
Re: ReturnFloat() crashes
I was just using angle 0 and scale 1.0 and hotspot 0.0 for testing. But your explanation would explain why sin() and cos() were taking radians and returning degrees...
-
Re: ReturnFloat() crashes
Upon more testing, I found that it's not just the X and Y that are messed up, it's everything! It's all in reverse order!
For some reason, they are still being set and accessed as the correct types, but the order is reversed! I can't figure it out. Why would it flip the variables around like that?
So, I have made an expression to get all the actionpoints as string. Then,I added two actionpoints.
The expression SHOULD return this:
1\2\3\4\5\6.7,8.9|10\11\12\13\14\15.16,17.18
BUT! Instead, it returns this:
5\4\3\2\1\8.9,6.7|14\13\12\11\10\17.18,15.16
As you can see, it seems the be flipping around the content of the structs I made (ActionpointID and Actionpoint)
Why is it doing this?
-
Re: ReturnFloat() crashes
OK, really weird thing. when I use the following code:
Code:
ActionpointID ID ((unsigned long)xlParam(), (unsigned long)xlParam(), (unsigned char)xlParam(), (unsigned long)xlParam(), (unsigned long)xlParam());
The parameters get reversed in order.
So, I have to make temporary values to hold the parameters like this:
Code:
unsigned long Object = (unsigned long)xlParam();
unsigned long Animation = (unsigned long)xlParam();
unsigned char Direction = (unsigned char)xlParam();
unsigned long Frame = (unsigned long)xlParam();
unsigned long Id = (unsigned long)xlParam();
ActionpointID ID (Object, Animation, Direction, Frame, Id);
And it works fine.
I'll let you guys know if I have any more problems, but thanks for being so helpful!
-
Re: ReturnFloat() crashes
Is xlParam() ultimately reading off of MMF's parameter queue? You are assuming that the parameters are going to be evaluated left-to-right, but I believe, as you have just observed, that the parameters are evaluated right-to-left. However I don't believe there is any hard gaurentee provided by the language about the order in which parameters are evaluated and may be different in some circumstances, so to be safe you should _never_ write code that depends on assumptions about the order of parameter evaluation in C/C++ functions.
-
Re: ReturnFloat() crashes
The order of parameters to functions getting evaluated is dependent on the calling convention. The standard one is right-to-left, but there are others.