If you've been trying to import older extensions into GameMaker Studio 2.3.1 or newer, you might encounter these error messages time to time:
wrong number of arguments for function buffer_get_surface wrong number of arguments for function buffer_set_surface
This is a small post on how to get rid of that:
The problem
Prior to GMS2.3.1, signatures for the two functions were as following:
buffer_get_surface(buffer, surface, mode, offset, modulo) buffer_set_surface(buffer, surface, mode, offset, modulo)
and starting with GMS2.3.1 they are:
buffer_get_surface(buffer, surface, offset) buffer_set_surface(buffer, surface, offset)
so, the third and fifth arguments are gone, and that's why you are getting the error.
This small yet breaking changes owes to fact that GM had only ever supported one "mode" and "modulo" was approximately never used as it is uncommon to work with raw data that would have a non-standard row-to-row "stride" in GML.
Manually fixing
As per above, if you had
buffer_get_surface(a, b, c, d, e);
it should now be changed to
buffer_get_surface(a, b, d);
Quick fix
You can use macros to create proxy functions that will accept either of argument counts!
#macro buffer_get_surface_base buffer_get_surface #macro buffer_get_surface buffer_get_surface_hook /// @param buffer /// @param surface /// @param offset|mode;offset;modulo function buffer_get_surface_hook() { switch (argument_count) { case 5: buffer_get_surface_base(argument[0], argument[1], argument[3]); break; case 3: buffer_get_surface_base(argument[0], argument[1], argument[2]); break; default: show_error("Wrong argument count for buffer_get_surface", 1); } } #macro buffer_set_surface_base buffer_set_surface #macro buffer_set_surface buffer_set_surface_hook /// @param buffer /// @param surface /// @param offset|mode;offset;modulo function buffer_set_surface_hook() { switch (argument_count) { case 5: buffer_set_surface_base(argument[0], argument[1], argument[3]); break; case 3: buffer_set_surface_base(argument[0], argument[1], argument[2]); break; default: show_error("Wrong argument count for buffer_set_surface", 1); } }
This way you don't have to change any code, which can be convenient if the offending code sits inside a GML extension.
That's all!
I just stumbled upon this post as a google answer. My project is showing this same problem but I am not using/calling that function anywhere. I didn’t even know it existed in the first place. I just imported my new project and bam, got hit with this same issue as a compiler error.
You might not be using it yourself, but one of the extensions you are using might be. If you cannot locate where the function is being called, GMEdit has a “search in extensions” checkbox in Global Search (Ctrl+Shift+F)
“Quick fix” from this post would work even if you do not change the code.
Useful use for macros, although I feel like it would be best for all involved to just run through the code and update all offending function calls, lol. The buffer-surface functions aren’t overly common things to use, and surely it won’t likely take more than a few minutes to search and fix each instance of them.
Unfortunately the buffer_get_surface is broken on HTML5, it gives a “offset not defined” error. I recently submitted a bug report about this and they said they’ll add to the bug list! Hoping they solve it in 2.3.2 (doubt, tho)
It might be still expecting 5 arguments, which can be mitigated with a macro like this as well.